mirror of
https://github.com/overte-org/overte.git
synced 2025-04-22 04:44:08 +02:00
merge fix
This commit is contained in:
commit
99f6ce2733
11 changed files with 113 additions and 11 deletions
|
@ -1523,11 +1523,17 @@ void Application::shootParticle() {
|
|||
delete particleEditHandle;
|
||||
}
|
||||
|
||||
// Caller is responsible for managing this EditableParticle
|
||||
ParticleEditHandle* Application::newParticleEditHandle(uint32_t id) {
|
||||
ParticleEditHandle* particleEditHandle = new ParticleEditHandle(&_particleEditSender, _particles.getTree());
|
||||
return particleEditHandle;
|
||||
}
|
||||
|
||||
// Caller is responsible for managing this EditableParticle
|
||||
ParticleEditHandle* Application::makeParticle(glm::vec3 position, float radius, xColor color, glm::vec3 velocity,
|
||||
glm::vec3 gravity, float damping, QString updateScript) {
|
||||
|
||||
ParticleEditHandle* particleEditHandle = new ParticleEditHandle(&_particleEditSender, _particles.getTree());
|
||||
ParticleEditHandle* particleEditHandle = newParticleEditHandle();
|
||||
particleEditHandle->createParticle(position, radius, color, velocity, gravity, damping, updateScript);
|
||||
return particleEditHandle;
|
||||
}
|
||||
|
|
|
@ -121,6 +121,7 @@ public:
|
|||
void wheelEvent(QWheelEvent* event);
|
||||
|
||||
void shootParticle(); // shoots a particle in the direction you're looking
|
||||
ParticleEditHandle* newParticleEditHandle(uint32_t id = NEW_PARTICLE);
|
||||
ParticleEditHandle* makeParticle(glm::vec3 position, float radius, xColor color, glm::vec3 velocity,
|
||||
glm::vec3 gravity, float damping, QString updateScript);
|
||||
|
||||
|
@ -141,6 +142,7 @@ public:
|
|||
Camera* getCamera() { return &_myCamera; }
|
||||
ViewFrustum* getViewFrustum() { return &_viewFrustum; }
|
||||
VoxelSystem* getVoxels() { return &_voxels; }
|
||||
ParticleTreeRenderer* getParticles() { return &_particles; }
|
||||
VoxelSystem* getSharedVoxelSystem() { return &_sharedVoxelSystem; }
|
||||
VoxelTree* getClipboard() { return &_clipboard; }
|
||||
Environment* getEnvironment() { return &_environment; }
|
||||
|
|
|
@ -62,7 +62,20 @@ void Hand::reset() {
|
|||
}
|
||||
|
||||
void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, float deltaTime) {
|
||||
|
||||
glm::vec3 targetPosition = fingerTipPosition / (float)TREE_SCALE;
|
||||
float targetRadius = (TOY_BALL_RADIUS * 2.0f) / (float)TREE_SCALE;
|
||||
const Particle* closestParticle = Application::getInstance()->getParticles()
|
||||
->getTree()->findClosestParticle(targetPosition, targetRadius);
|
||||
|
||||
if (closestParticle) {
|
||||
printf("potentially caught... particle ID:%d\n", closestParticle->getID());
|
||||
|
||||
// you can create a ParticleEditHandle by doing this...
|
||||
ParticleEditHandle* caughtParticle = Application::getInstance()->newParticleEditHandle(closestParticle->getID());
|
||||
|
||||
// but make sure you clean it up, when you're done
|
||||
delete caughtParticle;
|
||||
}
|
||||
// Is the controller button being held down....
|
||||
if (palm.getControllerButtons() & BUTTON_FWD) {
|
||||
// If grabbing toy ball, add forces to it.
|
||||
|
@ -74,8 +87,10 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f
|
|||
|
||||
// isCaught is also used as "creating" a new ball... for now, this section is the
|
||||
// create new ball portion of the code...
|
||||
bool isCaught = true;
|
||||
if (isCaught) {
|
||||
bool isCaught = false;
|
||||
|
||||
// If we didn't catch something, then create a new ball....
|
||||
if (!isCaught) {
|
||||
_toyBallInHand = true;
|
||||
_hasToyBall = true;
|
||||
|
||||
|
|
|
@ -102,6 +102,7 @@ private:
|
|||
bool _hasToyBall;
|
||||
bool _toyBallShouldRender;
|
||||
|
||||
const Particle* _heldParticle;
|
||||
ParticleEditHandle* _ballParticleEditHandle;
|
||||
|
||||
float _pitchUpdate;
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
#include <OctreePacketData.h>
|
||||
|
||||
const uint32_t NEW_PARTICLE = 0xFFFFFFFF;
|
||||
const uint32_t UNKNOWN_TOKEN = 0xFFFFFFFF;
|
||||
|
||||
class ParticleDetail {
|
||||
public:
|
||||
uint32_t id;
|
||||
|
|
|
@ -16,15 +16,22 @@ std::map<uint32_t,ParticleEditHandle*> ParticleEditHandle::_allHandles;
|
|||
uint32_t ParticleEditHandle::_nextCreatorTokenID = 0;
|
||||
|
||||
|
||||
ParticleEditHandle::ParticleEditHandle(ParticleEditPacketSender* packetSender, ParticleTree* localTree) {
|
||||
_creatorTokenID = _nextCreatorTokenID;
|
||||
_nextCreatorTokenID++;
|
||||
_id = NEW_PARTICLE;
|
||||
_isKnownID = false;
|
||||
ParticleEditHandle::ParticleEditHandle(ParticleEditPacketSender* packetSender, ParticleTree* localTree, uint32_t id) {
|
||||
if (id == NEW_PARTICLE) {
|
||||
_creatorTokenID = _nextCreatorTokenID;
|
||||
_nextCreatorTokenID++;
|
||||
_id = NEW_PARTICLE;
|
||||
_isKnownID = false;
|
||||
_allHandles[_creatorTokenID] = this;
|
||||
} else {
|
||||
_creatorTokenID = UNKNOWN_TOKEN;
|
||||
_id = id;
|
||||
_isKnownID = true;
|
||||
// don't add to _allHandles because we already know it...
|
||||
}
|
||||
_packetSender = packetSender;
|
||||
_localTree = localTree;
|
||||
|
||||
_allHandles[_creatorTokenID] = this;
|
||||
}
|
||||
|
||||
ParticleEditHandle::~ParticleEditHandle() {
|
||||
|
|
|
@ -19,12 +19,14 @@
|
|||
#include <SharedUtil.h>
|
||||
#include <OctreePacketData.h>
|
||||
|
||||
#include "Particle.h"
|
||||
|
||||
class ParticleEditPacketSender;
|
||||
class ParticleTree;
|
||||
|
||||
class ParticleEditHandle {
|
||||
public:
|
||||
ParticleEditHandle(ParticleEditPacketSender* packetSender, ParticleTree* localTree);
|
||||
ParticleEditHandle(ParticleEditPacketSender* packetSender, ParticleTree* localTree, uint32_t id = NEW_PARTICLE);
|
||||
~ParticleEditHandle();
|
||||
|
||||
uint32_t getCreatorTokenID() const { return _creatorTokenID; }
|
||||
|
|
|
@ -64,6 +64,57 @@ void ParticleTree::storeParticle(const Particle& particle) {
|
|||
_isDirty = true;
|
||||
}
|
||||
|
||||
class FindNearPointArgs {
|
||||
public:
|
||||
glm::vec3 position;
|
||||
float targetRadius;
|
||||
bool found;
|
||||
const Particle* closestParticle;
|
||||
float closestParticleDistance;
|
||||
};
|
||||
|
||||
|
||||
bool ParticleTree::findNearPointOperation(OctreeElement* element, void* extraData) {
|
||||
FindNearPointArgs* args = static_cast<FindNearPointArgs*>(extraData);
|
||||
ParticleTreeElement* particleTreeElement = static_cast<ParticleTreeElement*>(element);
|
||||
|
||||
|
||||
// If this particleTreeElement contains the point, then search it...
|
||||
if (particleTreeElement->getAABox().contains(args->position)) {
|
||||
const Particle* thisClosestParticle = particleTreeElement->getClosestParticle(args->position);
|
||||
|
||||
// we may have gotten NULL back, meaning no particle was available
|
||||
if (thisClosestParticle) {
|
||||
glm::vec3 particlePosition = thisClosestParticle->getPosition();
|
||||
float distanceFromPointToParticle = glm::distance(particlePosition, args->position);
|
||||
|
||||
// If we're within our target radius
|
||||
if (distanceFromPointToParticle <= args->targetRadius) {
|
||||
// we are closer than anything else we've found
|
||||
if (distanceFromPointToParticle < args->closestParticleDistance) {
|
||||
args->closestParticle = thisClosestParticle;
|
||||
args->closestParticleDistance = distanceFromPointToParticle;
|
||||
args->found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// we should be able to optimize this...
|
||||
return true; // keep searching in case children have closer particles
|
||||
}
|
||||
|
||||
// if this element doesn't contain the point, then none of it's children can contain the point, so stop searching
|
||||
return false;
|
||||
}
|
||||
|
||||
const Particle* ParticleTree::findClosestParticle(glm::vec3 position, float targetRadius) {
|
||||
// First, look for the existing particle in the tree..
|
||||
FindNearPointArgs args = { position, targetRadius, false, NULL, FLT_MAX };
|
||||
recurseTreeWithOperation(findNearPointOperation, &args);
|
||||
return args.closestParticle;
|
||||
}
|
||||
|
||||
|
||||
int ParticleTree::processEditPacketData(PACKET_TYPE packetType, unsigned char* packetData, int packetLength,
|
||||
unsigned char* editData, int maxLength, Node* senderNode) {
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@ public:
|
|||
virtual void update();
|
||||
|
||||
void storeParticle(const Particle& particle);
|
||||
const Particle* findClosestParticle(glm::vec3 position, float targetRadius);
|
||||
|
||||
void addNewlyCreatedHook(NewlyCreatedParticleHook* hook);
|
||||
void removeNewlyCreatedHook(NewlyCreatedParticleHook* hook);
|
||||
|
@ -51,6 +52,7 @@ private:
|
|||
|
||||
static bool updateOperation(OctreeElement* element, void* extraData);
|
||||
static bool findAndUpdateOperation(OctreeElement* element, void* extraData);
|
||||
static bool findNearPointOperation(OctreeElement* element, void* extraData);
|
||||
|
||||
void notifyNewlyCreatedParticle(const Particle& newParticle, Node* senderNode);
|
||||
|
||||
|
|
|
@ -104,6 +104,19 @@ bool ParticleTreeElement::updateParticle(const Particle& particle) {
|
|||
return false;
|
||||
}
|
||||
|
||||
const Particle* ParticleTreeElement::getClosestParticle(glm::vec3 position) const {
|
||||
const Particle* closestParticle = NULL;
|
||||
float closestParticleDistance = FLT_MAX;
|
||||
uint16_t numberOfParticles = _particles.size();
|
||||
for (uint16_t i = 0; i < numberOfParticles; i++) {
|
||||
float distanceToParticle = glm::distance(position, _particles[i].getPosition());
|
||||
if (distanceToParticle < closestParticleDistance) {
|
||||
closestParticle = &_particles[i];
|
||||
}
|
||||
}
|
||||
return closestParticle;
|
||||
}
|
||||
|
||||
|
||||
int ParticleTreeElement::readElementDataFromBuffer(const unsigned char* data, int bytesLeftToRead,
|
||||
ReadBitstreamToTreeParams& args) {
|
||||
|
|
|
@ -80,6 +80,7 @@ public:
|
|||
|
||||
bool containsParticle(const Particle& particle) const;
|
||||
bool updateParticle(const Particle& particle);
|
||||
const Particle* getClosestParticle(glm::vec3 position) const;
|
||||
|
||||
protected:
|
||||
void storeParticle(const Particle& particle);
|
||||
|
|
Loading…
Reference in a new issue