mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 21:47:12 +02:00
Merge remote-tracking branch 'hifi/master'
This commit is contained in:
commit
94af583949
9 changed files with 51 additions and 15 deletions
|
@ -103,6 +103,9 @@ function updateButterflies(deltaTime) {
|
||||||
var CHANCE_OF_IMPULSE = 0.04;
|
var CHANCE_OF_IMPULSE = 0.04;
|
||||||
for (var i = 0; i < numButterflies; i++) {
|
for (var i = 0; i < numButterflies; i++) {
|
||||||
if (Math.random() < CHANCE_OF_IMPULSE) {
|
if (Math.random() < CHANCE_OF_IMPULSE) {
|
||||||
|
if (!butterflies[i].isKnownID) {
|
||||||
|
butterflies[i] = Entities.identifyEntity(butterflies[i]);
|
||||||
|
}
|
||||||
var properties = Entities.getEntityProperties(butterflies[i]);
|
var properties = Entities.getEntityProperties(butterflies[i]);
|
||||||
if (Vec3.length(Vec3.subtract(properties.position, flockPosition)) > range) {
|
if (Vec3.length(Vec3.subtract(properties.position, flockPosition)) > range) {
|
||||||
Entities.editEntity(butterflies[i], { position: flockPosition } );
|
Entities.editEntity(butterflies[i], { position: flockPosition } );
|
||||||
|
|
|
@ -160,7 +160,7 @@ public:
|
||||||
float getLargestDimension() const { return glm::length(_dimensions); } /// get the largest possible dimension
|
float getLargestDimension() const { return glm::length(_dimensions); } /// get the largest possible dimension
|
||||||
|
|
||||||
/// set dimensions in domain scale units (0.0 - 1.0) this will also reset radius appropriately
|
/// set dimensions in domain scale units (0.0 - 1.0) this will also reset radius appropriately
|
||||||
void setDimensions(const glm::vec3& value) { _dimensions = value; recalculateCollisionShape(); }
|
virtual void setDimensions(const glm::vec3& value) { _dimensions = value; recalculateCollisionShape(); }
|
||||||
|
|
||||||
/// set dimensions in meter units (0.0 - TREE_SCALE) this will also reset radius appropriately
|
/// set dimensions in meter units (0.0 - TREE_SCALE) this will also reset radius appropriately
|
||||||
void setDimensionsInMeters(const glm::vec3& value) { setDimensions(value / (float) TREE_SCALE); }
|
void setDimensionsInMeters(const glm::vec3& value) { setDimensions(value / (float) TREE_SCALE); }
|
||||||
|
|
|
@ -19,9 +19,13 @@
|
||||||
#include "MovingEntitiesOperator.h"
|
#include "MovingEntitiesOperator.h"
|
||||||
#include "UpdateEntityOperator.h"
|
#include "UpdateEntityOperator.h"
|
||||||
|
|
||||||
EntityTree::EntityTree(bool shouldReaverage) : Octree(shouldReaverage), _simulation(NULL) {
|
EntityTree::EntityTree(bool shouldReaverage) :
|
||||||
|
Octree(shouldReaverage),
|
||||||
|
_fbxService(NULL),
|
||||||
|
_lightsArePickable(true),
|
||||||
|
_simulation(NULL)
|
||||||
|
{
|
||||||
_rootElement = createNewElement();
|
_rootElement = createNewElement();
|
||||||
_lightsArePickable = true; // assume they are by default
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityTree::~EntityTree() {
|
EntityTree::~EntityTree() {
|
||||||
|
|
|
@ -47,6 +47,13 @@ LightEntityItem::LightEntityItem(const EntityItemID& entityItemID, const EntityI
|
||||||
_emptyShape.setRadius(0.0f);
|
_emptyShape.setRadius(0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LightEntityItem::setDimensions(const glm::vec3& value) {
|
||||||
|
float maxDimension = glm::max(value.x, value.y, value.z);
|
||||||
|
_dimensions = glm::vec3(maxDimension, maxDimension, maxDimension);
|
||||||
|
recalculateCollisionShape();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
EntityItemProperties LightEntityItem::getProperties() const {
|
EntityItemProperties LightEntityItem::getProperties() const {
|
||||||
EntityItemProperties properties = EntityItem::getProperties(); // get the properties from our base class
|
EntityItemProperties properties = EntityItem::getProperties(); // get the properties from our base class
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,9 @@ public:
|
||||||
LightEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties);
|
LightEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties);
|
||||||
|
|
||||||
ALLOW_INSTANTIATION // This class can be instantiated
|
ALLOW_INSTANTIATION // This class can be instantiated
|
||||||
|
|
||||||
|
/// set dimensions in domain scale units (0.0 - 1.0) this will also reset radius appropriately
|
||||||
|
virtual void setDimensions(const glm::vec3& value);
|
||||||
|
|
||||||
// methods for getting/setting all properties of an entity
|
// methods for getting/setting all properties of an entity
|
||||||
virtual EntityItemProperties getProperties() const;
|
virtual EntityItemProperties getProperties() const;
|
||||||
|
|
|
@ -10,9 +10,12 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
|
#include <glm/gtx/transform.hpp>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#include <ByteCountCoding.h>
|
#include <ByteCountCoding.h>
|
||||||
|
#include <GeometryUtil.h>
|
||||||
|
|
||||||
#include "EntityTree.h"
|
#include "EntityTree.h"
|
||||||
#include "EntityTreeElement.h"
|
#include "EntityTreeElement.h"
|
||||||
|
@ -97,18 +100,24 @@ void SphereEntityItem::recalculateCollisionShape() {
|
||||||
bool SphereEntityItem::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
bool SphereEntityItem::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||||
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
||||||
void** intersectedObject, bool precisionPicking) const {
|
void** intersectedObject, bool precisionPicking) const {
|
||||||
|
// determine the ray in the frame of the entity transformed from a unit sphere
|
||||||
// NOTE: origin and direction are in tree units. But our _sphereShape is in meters, so we need to
|
glm::mat4 translation = glm::translate(getPosition());
|
||||||
// do a little math to make these match each other.
|
glm::mat4 rotation = glm::mat4_cast(getRotation());
|
||||||
RayIntersectionInfo rayInfo;
|
glm::mat4 scale = glm::scale(getDimensions());
|
||||||
rayInfo._rayStart = origin * (float)TREE_SCALE;
|
glm::mat4 registration = glm::translate(glm::vec3(0.5f, 0.5f, 0.5f) - getRegistrationPoint());
|
||||||
rayInfo._rayDirection = direction;
|
glm::mat4 entityToWorldMatrix = translation * rotation * scale * registration;
|
||||||
|
glm::mat4 worldToEntityMatrix = glm::inverse(entityToWorldMatrix);
|
||||||
|
glm::vec3 entityFrameOrigin = glm::vec3(worldToEntityMatrix * glm::vec4(origin, 1.0f));
|
||||||
|
glm::vec3 entityFrameDirection = glm::normalize(glm::vec3(worldToEntityMatrix * glm::vec4(direction, 1.0f)));
|
||||||
|
|
||||||
// TODO: Note this is really doing ray intersections against a sphere, which is fine except in cases
|
float localDistance;
|
||||||
// where our dimensions actually make us an ellipsoid. But we'll live with this for now until we
|
// NOTE: unit sphere has center of 0,0,0 and radius of 0.5
|
||||||
// get a more full fledged physics library
|
if (findRaySphereIntersection(entityFrameOrigin, entityFrameDirection, glm::vec3(0.0f), 0.5f, localDistance)) {
|
||||||
if (_sphereShape.findRayIntersection(rayInfo)) {
|
// determine where on the unit sphere the hit point occured
|
||||||
distance = rayInfo._hitDistance / (float)TREE_SCALE;
|
glm::vec3 entityFrameHitAt = entityFrameOrigin + (entityFrameDirection * localDistance);
|
||||||
|
// then translate back to work coordinates
|
||||||
|
glm::vec3 hitAt = glm::vec3(entityToWorldMatrix * glm::vec4(entityFrameHitAt, 1.0f));
|
||||||
|
distance = glm::distance(origin,hitAt);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -60,7 +60,7 @@ public:
|
||||||
virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||||
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
||||||
void** intersectedObject, bool precisionPicking) const;
|
void** intersectedObject, bool precisionPicking) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void recalculateCollisionShape();
|
virtual void recalculateCollisionShape();
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,13 @@ TextEntityItem::TextEntityItem(const EntityItemID& entityItemID, const EntityIte
|
||||||
setProperties(properties, true);
|
setProperties(properties, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextEntityItem::setDimensions(const glm::vec3& value) {
|
||||||
|
// NOTE: Text Entities always have a "depth" of 1cm.
|
||||||
|
float fixedDepth = 0.01f / (float)TREE_SCALE;
|
||||||
|
_dimensions = glm::vec3(value.x, value.y, fixedDepth);
|
||||||
|
recalculateCollisionShape();
|
||||||
|
}
|
||||||
|
|
||||||
EntityItemProperties TextEntityItem::getProperties() const {
|
EntityItemProperties TextEntityItem::getProperties() const {
|
||||||
EntityItemProperties properties = EntityItem::getProperties(); // get the properties from our base class
|
EntityItemProperties properties = EntityItem::getProperties(); // get the properties from our base class
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,9 @@ public:
|
||||||
TextEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties);
|
TextEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties);
|
||||||
|
|
||||||
ALLOW_INSTANTIATION // This class can be instantiated
|
ALLOW_INSTANTIATION // This class can be instantiated
|
||||||
|
|
||||||
|
/// set dimensions in domain scale units (0.0 - 1.0) this will also reset radius appropriately
|
||||||
|
virtual void setDimensions(const glm::vec3& value);
|
||||||
|
|
||||||
// methods for getting/setting all properties of an entity
|
// methods for getting/setting all properties of an entity
|
||||||
virtual EntityItemProperties getProperties() const;
|
virtual EntityItemProperties getProperties() const;
|
||||||
|
|
Loading…
Reference in a new issue