remove usage of ParticleEditHandle from application

This commit is contained in:
Brad Hefta-Gaub 2014-01-21 14:07:46 -08:00
parent 278ca02595
commit 03a9253748
4 changed files with 1 additions and 281 deletions

View file

@ -652,8 +652,6 @@ void Application::keyPressEvent(QKeyEvent* event) {
bool isShifted = event->modifiers().testFlag(Qt::ShiftModifier);
bool isMeta = event->modifiers().testFlag(Qt::ControlModifier);
switch (event->key()) {
case Qt::Key_N:
shootParticle();
break;
case Qt::Key_Shift:
if (Menu::getInstance()->isOptionChecked(MenuOption::VoxelSelectMode)) {
@ -1503,63 +1501,6 @@ void Application::removeVoxel(glm::vec3 position,
_voxels.deleteVoxelAt(voxel.x, voxel.y, voxel.z, voxel.s);
}
void Application::shootParticle() {
glm::vec3 position = _viewFrustum.getPosition();
glm::vec3 direction = _viewFrustum.getDirection();
const float LINEAR_VELOCITY = 5.f;
glm::vec3 lookingAt = position + (direction * LINEAR_VELOCITY);
const float radius = 0.125 / TREE_SCALE;
xColor color = { 0, 255, 255};
glm::vec3 velocity = lookingAt - position;
glm::vec3 gravity = DEFAULT_GRAVITY * 0.01f;
float damping = DEFAULT_DAMPING * 0.01f;
float lifetime = 5.0f; // bullets have 5 second lifetime
QString script(
" function collisionWithVoxel(voxel) { "
" print('collisionWithVoxel(voxel)... '); "
" print('myID=' + Particle.getID()); "
" var voxelColor = voxel.getColor();"
" print('voxelColor=' + voxelColor.red + ', ' + voxelColor.green + ', ' + voxelColor.blue ); "
" var myColor = Particle.getColor();"
" print('myColor=' + myColor.red + ', ' + myColor.green + ', ' + myColor.blue ); "
" var newProps = { color: voxelColor }; "
" print('about to call Particle.setProperties()'); "
" Particle.setProperties(newProps); "
" var voxelAt = voxel.getPosition();"
" var voxelScale = voxel.getScale();"
" Voxels.eraseVoxel(voxelAt.x, voxelAt.y, voxelAt.z, voxelScale); "
" print('Voxels.eraseVoxel(' + voxelAt.x + ', ' + voxelAt.y + ', ' + voxelAt.z + ', ' + voxelScale + ')...'); "
" } "
" Particle.collisionWithVoxel.connect(collisionWithVoxel); " );
ParticleEditHandle* particleEditHandle = makeParticle(position / (float)TREE_SCALE, radius, color,
velocity / (float)TREE_SCALE, gravity, damping, lifetime, NOT_IN_HAND, script);
// If we wanted to be able to edit this particle after shooting, then we could store this value
// and use it for editing later. But we don't care about that for "shooting" and therefore we just
// clean up our memory now. deleting a ParticleEditHandle does not effect the underlying particle,
// it just removes your ability to edit that particle later.
delete particleEditHandle;
}
// Caller is responsible for managing this EditableParticle
ParticleEditHandle* Application::newParticleEditHandle(uint32_t id) {
ParticleEditHandle* particleEditHandle = new ParticleEditHandle(&_particleEditSender, _particles.getTree(), id);
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, float lifetime, bool inHand, QString updateScript) {
ParticleEditHandle* particleEditHandle = newParticleEditHandle();
particleEditHandle->createParticle(position, radius, color, velocity, gravity, damping, lifetime, inHand, updateScript);
return particleEditHandle;
}
void Application::makeVoxel(glm::vec3 position,
float scale,
@ -4178,10 +4119,6 @@ void Application::processDatagrams() {
break;
case PACKET_TYPE_PARTICLE_ADD_RESPONSE:
// This will make sure our local ParticleEditHandle are handles correctly
ParticleEditHandle::handleAddResponse(_incomingPacket, bytesReceived);
// this will keep creatorTokenIDs to IDs mapped correctly
Particle::handleAddParticleResponse(_incomingPacket, bytesReceived);
break;

View file

@ -66,7 +66,6 @@
#include "ui/LogDialog.h"
#include "FileLogger.h"
#include "ParticleTreeRenderer.h"
#include "ParticleEditHandle.h"
#include "ControllerScriptingInterface.h"
@ -123,11 +122,6 @@ 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, float lifetime, bool inHand, QString updateScript);
void makeVoxel(glm::vec3 position,
float scale,
unsigned char red,

View file

@ -21,26 +21,7 @@ using namespace std;
const float FINGERTIP_COLLISION_RADIUS = 0.01f;
const float FINGERTIP_VOXEL_SIZE = 0.05f;
const int TOY_BALL_HAND = 1;
const float TOY_BALL_RADIUS = 0.05f;
const float TOY_BALL_DAMPING = 0.1f;
const float TOY_BALL_LIFETIME = 30.0f; // toy balls live for 30 seconds
const glm::vec3 NO_VELOCITY = glm::vec3(0,0,0);
const glm::vec3 NO_GRAVITY = glm::vec3(0,0,0);
const float NO_DAMPING = 0.f;
const glm::vec3 TOY_BALL_GRAVITY = glm::vec3(0,-2.0f,0);
const QString TOY_BALL_UPDATE_SCRIPT("");
const float PALM_COLLISION_RADIUS = 0.03f;
const float CATCH_RADIUS = 0.3f;
const xColor TOY_BALL_ON_SERVER_COLOR[] =
{
{ 255, 0, 0 },
{ 0, 255, 0 },
{ 0, 0, 255 },
{ 255, 255, 0 },
{ 0, 255, 255 },
{ 255, 0, 255 },
};
Hand::Hand(Avatar* owningAvatar) :
@ -56,16 +37,8 @@ Hand::Hand(Avatar* owningAvatar) :
_grabDelta(0, 0, 0),
_grabDeltaVelocity(0, 0, 0),
_grabStartRotation(0, 0, 0, 1),
_grabCurrentRotation(0, 0, 0, 1),
_throwSound(QUrl("https://dl.dropboxusercontent.com/u/1864924/hifi-sounds/throw.raw")),
_catchSound(QUrl("https://dl.dropboxusercontent.com/u/1864924/hifi-sounds/catch.raw"))
_grabCurrentRotation(0, 0, 0, 1)
{
for (int i = 0; i < MAX_HANDS; i++) {
_toyBallInHand[i] = false;
_ballParticleEditHandles[i] = NULL;
_whichBallColor[i] = 0;
}
_lastControllerButtons = 0;
}
void Hand::init() {
@ -81,161 +54,7 @@ void Hand::init() {
void Hand::reset() {
}
void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, float deltaTime) {
Application* app = Application::getInstance();
ParticleTree* particles = app->getParticles()->getTree();
int handID = palm.getSixenseID();
const int NEW_BALL_BUTTON = BUTTON_3;
bool grabButtonPressed = ((palm.getControllerButtons() & BUTTON_FWD) ||
(palm.getControllerButtons() & BUTTON_3));
bool ballAlreadyInHand = _toyBallInHand[handID];
glm::vec3 targetPosition;
palm.getBallHoldPosition(targetPosition);
float targetRadius = CATCH_RADIUS / (float)TREE_SCALE;
// If I don't currently have a ball in my hand, then try to catch closest one
if (!ballAlreadyInHand && grabButtonPressed) {
const Particle* closestParticle = particles->findClosestParticle(targetPosition, targetRadius);
if (closestParticle) {
ParticleEditHandle* caughtParticle = app->newParticleEditHandle(closestParticle->getID());
glm::vec3 newPosition = targetPosition;
glm::vec3 newVelocity = NO_VELOCITY;
// update the particle with it's new state...
caughtParticle->updateParticle(newPosition,
closestParticle->getRadius(),
closestParticle->getXColor(),
newVelocity,
NO_GRAVITY,
NO_DAMPING,
DEFAULT_LIFETIME,
IN_HAND, // we just grabbed it!
closestParticle->getScript());
// now tell our hand about us having caught it...
_toyBallInHand[handID] = true;
//printf(">>>>>>> caught... handID:%d particle ID:%d _toyBallInHand[handID] = true\n", handID, closestParticle->getID());
_ballParticleEditHandles[handID] = caughtParticle;
caughtParticle = NULL;
// use the threadSound static method to inject the catch sound
// pass an AudioInjectorOptions struct to set position and disable loopback
AudioInjectorOptions injectorOptions;
injectorOptions.setPosition(newPosition);
injectorOptions.setLoopbackAudioInterface(app->getAudio());
AudioScriptingInterface::playSound(&_catchSound, &injectorOptions);
}
}
// If there's a ball in hand, and the user presses the skinny button, then change the color of the ball
int currentControllerButtons = palm.getControllerButtons();
if (currentControllerButtons != _lastControllerButtons && (currentControllerButtons & BUTTON_0)) {
_whichBallColor[handID]++;
if (_whichBallColor[handID] >= sizeof(TOY_BALL_ON_SERVER_COLOR)/sizeof(TOY_BALL_ON_SERVER_COLOR[0])) {
_whichBallColor[handID] = 0;
}
}
// If '3' is pressed, and not holding a ball, make a new one
if ((palm.getControllerButtons() & NEW_BALL_BUTTON) && (_toyBallInHand[handID] == false)) {
_toyBallInHand[handID] = true;
// Create a particle on the particle server
glm::vec3 ballPosition;
palm.getBallHoldPosition(ballPosition);
_ballParticleEditHandles[handID] = app->makeParticle(
ballPosition / (float)TREE_SCALE,
TOY_BALL_RADIUS / (float) TREE_SCALE,
TOY_BALL_ON_SERVER_COLOR[_whichBallColor[handID]],
NO_VELOCITY / (float)TREE_SCALE,
TOY_BALL_GRAVITY / (float) TREE_SCALE,
TOY_BALL_DAMPING,
TOY_BALL_LIFETIME,
IN_HAND,
TOY_BALL_UPDATE_SCRIPT);
// Play a new ball sound
app->getAudio()->startDrumSound(1.0f, 2000, 0.5f, 0.02f);
}
if (grabButtonPressed) {
// If we don't currently have a ball in hand, then create it...
if (_toyBallInHand[handID]) {
// Update ball that is in hand
uint32_t particleInHandID = _ballParticleEditHandles[handID]->getID();
const Particle* particleInHand = particles->findParticleByID(particleInHandID);
xColor colorForParticleInHand = particleInHand ? particleInHand->getXColor()
: TOY_BALL_ON_SERVER_COLOR[_whichBallColor[handID]];
glm::vec3 ballPosition;
palm.getBallHoldPosition(ballPosition);
_ballParticleEditHandles[handID]->updateParticle(ballPosition / (float)TREE_SCALE,
TOY_BALL_RADIUS / (float) TREE_SCALE,
colorForParticleInHand,
NO_VELOCITY / (float)TREE_SCALE,
TOY_BALL_GRAVITY / (float) TREE_SCALE,
TOY_BALL_DAMPING,
TOY_BALL_LIFETIME,
IN_HAND,
TOY_BALL_UPDATE_SCRIPT);
}
} else {
// If toy ball just released, add velocity to it!
if (_toyBallInHand[handID]) {
const float THROWN_VELOCITY_SCALING = 1.5f;
_toyBallInHand[handID] = false;
palm.updateCollisionlessPaddleExpiry();
glm::vec3 ballPosition;
palm.getBallHoldPosition(ballPosition);
glm::vec3 ballVelocity = palm.getTipVelocity();
glm::quat avatarRotation = _owningAvatar->getOrientation();
ballVelocity = avatarRotation * ballVelocity;
ballVelocity *= THROWN_VELOCITY_SCALING;
uint32_t particleInHandID = _ballParticleEditHandles[handID]->getID();
const Particle* particleInHand = particles->findParticleByID(particleInHandID);
xColor colorForParticleInHand = particleInHand ? particleInHand->getXColor()
: TOY_BALL_ON_SERVER_COLOR[_whichBallColor[handID]];
_ballParticleEditHandles[handID]->updateParticle(ballPosition / (float)TREE_SCALE,
TOY_BALL_RADIUS / (float) TREE_SCALE,
colorForParticleInHand,
ballVelocity / (float)TREE_SCALE,
TOY_BALL_GRAVITY / (float) TREE_SCALE,
TOY_BALL_DAMPING,
TOY_BALL_LIFETIME,
NOT_IN_HAND,
TOY_BALL_UPDATE_SCRIPT);
// after releasing the ball, we free our ParticleEditHandle so we can't edit it further
// note: deleting the edit handle doesn't effect the actual particle
delete _ballParticleEditHandles[handID];
_ballParticleEditHandles[handID] = NULL;
// use the threadSound static method to inject the throw sound
// pass an AudioInjectorOptions struct to set position and disable loopback
AudioInjectorOptions injectorOptions;
injectorOptions.setPosition(ballPosition);
injectorOptions.setLoopbackAudioInterface(app->getAudio());
AudioScriptingInterface::playSound(&_throwSound, &injectorOptions);
}
}
// remember the last pressed button state
if (currentControllerButtons != 0) {
_lastControllerButtons = currentControllerButtons;
}
}
glm::vec3 Hand::getAndResetGrabDelta() {
const float HAND_GRAB_SCALE_DISTANCE = 2.f;
@ -282,8 +101,6 @@ void Hand::simulate(float deltaTime, bool isMine) {
FingerData& finger = palm.getFingers()[0]; // Sixense has only one finger
glm::vec3 fingerTipPosition = finger.getTipPosition();
simulateToyBall(palm, fingerTipPosition, deltaTime);
_buckyBalls.grab(palm, fingerTipPosition, _owningAvatar->getOrientation(), deltaTime);
if (palm.getControllerButtons() & BUTTON_4) {
@ -517,7 +334,6 @@ void Hand::render(bool isMine) {
glPopMatrix();
}
}
if (Menu::getInstance()->isOptionChecked(MenuOption::DisplayLeapHands)) {
renderLeapHands(isMine);
@ -546,7 +362,6 @@ void Hand::render(bool isMine) {
void Hand::renderLeapHands(bool isMine) {
const float alpha = 1.0f;
const float TARGET_ALPHA = 0.5f;
//const glm::vec3 handColor = _ballColor;
const glm::vec3 handColor(1.0, 0.84, 0.66); // use the skin color
@ -564,19 +379,6 @@ void Hand::renderLeapHands(bool isMine) {
palm.getBallHoldPosition(targetPosition);
glPushMatrix();
ParticleTree* particles = Application::getInstance()->getParticles()->getTree();
const Particle* closestParticle = particles->findClosestParticle(targetPosition / (float)TREE_SCALE,
CATCH_RADIUS / (float)TREE_SCALE);
// If we are hitting a particle then draw the target green, otherwise yellow
if (closestParticle) {
glColor4f(0,1,0, TARGET_ALPHA);
} else {
glColor4f(1,1,0, TARGET_ALPHA);
}
glTranslatef(targetPosition.x, targetPosition.y, targetPosition.z);
glutWireSphere(CATCH_RADIUS, 10.f, 10.f);
const float collisionRadius = 0.05f;
glColor4f(0.5f,0.5f,0.5f, alpha);
glutWireSphere(collisionRadius, 10.f, 10.f);

View file

@ -19,7 +19,6 @@
#include <AvatarData.h>
#include <AudioScriptingInterface.h>
#include <HandData.h>
#include <ParticleEditHandle.h>
#include "BuckyBalls.h"
#include "InterfaceConfig.h"
@ -102,24 +101,12 @@ private:
void handleVoxelCollision(PalmData* palm, const glm::vec3& fingerTipPosition, VoxelTreeElement* voxel, float deltaTime);
void simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, float deltaTime);
#define MAX_HANDS 2
bool _toyBallInHand[MAX_HANDS];
int _whichBallColor[MAX_HANDS];
ParticleEditHandle* _ballParticleEditHandles[MAX_HANDS];
int _lastControllerButtons;
float _pitchUpdate;
glm::vec3 _grabDelta;
glm::vec3 _grabDeltaVelocity;
glm::quat _grabStartRotation;
glm::quat _grabCurrentRotation;
Sound _throwSound;
Sound _catchSound;
};
#endif