mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 15:29:32 +02:00
change toy ball to use ParicleEditHandle class
This commit is contained in:
parent
82b5c53551
commit
5d9b7c7f75
4 changed files with 64 additions and 18 deletions
|
@ -236,6 +236,11 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
|
||||||
// Tell our voxel edit sender about our known jurisdictions
|
// Tell our voxel edit sender about our known jurisdictions
|
||||||
_voxelEditSender.setVoxelServerJurisdictions(&_voxelServerJurisdictions);
|
_voxelEditSender.setVoxelServerJurisdictions(&_voxelServerJurisdictions);
|
||||||
_particleEditSender.setServerJurisdictions(&_particleServerJurisdictions);
|
_particleEditSender.setServerJurisdictions(&_particleServerJurisdictions);
|
||||||
|
|
||||||
|
// For now we're going to set the PPS for outbound packets to be super high, this is
|
||||||
|
// probably not the right long term solution. But for now, we're going to do this to
|
||||||
|
// allow you to move a particle around in your hand
|
||||||
|
_particleEditSender.setPacketsPerSecond(3000); // super high!!
|
||||||
}
|
}
|
||||||
|
|
||||||
Application::~Application() {
|
Application::~Application() {
|
||||||
|
|
|
@ -22,8 +22,9 @@ using namespace std;
|
||||||
const float FINGERTIP_VOXEL_SIZE = 0.05;
|
const float FINGERTIP_VOXEL_SIZE = 0.05;
|
||||||
const int TOY_BALL_HAND = 1;
|
const int TOY_BALL_HAND = 1;
|
||||||
const float TOY_BALL_RADIUS = 0.05f;
|
const float TOY_BALL_RADIUS = 0.05f;
|
||||||
const glm::vec3 TOYBALL_GRAVITY (0, -1, 0);
|
const float TOY_BALL_DAMPING = 0.f;
|
||||||
float TOYBALL_DAMPING = 1.f;
|
const glm::vec3 TOY_BALL_GRAVITY = glm::vec3(0,-1,0);
|
||||||
|
const QString TOY_BALL_UPDATE_SCRIPT("");
|
||||||
const float PALM_COLLISION_RADIUS = 0.03f;
|
const float PALM_COLLISION_RADIUS = 0.03f;
|
||||||
|
|
||||||
Hand::Hand(Avatar* owningAvatar) :
|
Hand::Hand(Avatar* owningAvatar) :
|
||||||
|
@ -38,8 +39,9 @@ Hand::Hand(Avatar* owningAvatar) :
|
||||||
_toyBallPosition(0),
|
_toyBallPosition(0),
|
||||||
_toyBallVelocity(0),
|
_toyBallVelocity(0),
|
||||||
_toyBallInHand(false),
|
_toyBallInHand(false),
|
||||||
|
_ballParticleEditHandle(NULL),
|
||||||
_pitchUpdate(0)
|
_pitchUpdate(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hand::init() {
|
void Hand::init() {
|
||||||
|
@ -56,54 +58,88 @@ void Hand::reset() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, float deltaTime) {
|
void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, float deltaTime) {
|
||||||
|
|
||||||
|
// Is the controller button being held down....
|
||||||
if (palm.getControllerButtons() & BUTTON_FWD) {
|
if (palm.getControllerButtons() & BUTTON_FWD) {
|
||||||
// If grabbing toy ball, add forces to it
|
// If grabbing toy ball, add forces to it.
|
||||||
|
|
||||||
|
// If we don't currently have a ball in hand, then create it...
|
||||||
if (!_toyBallInHand) {
|
if (!_toyBallInHand) {
|
||||||
// Test for whether close enough to catch and catch
|
// Test for whether close enough to catch and catch....
|
||||||
|
|
||||||
|
// 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;
|
bool isCaught = true;
|
||||||
if (isCaught) {
|
if (isCaught) {
|
||||||
_toyBallInHand = true;
|
_toyBallInHand = true;
|
||||||
|
|
||||||
|
// create the ball, call MakeParticle, and use the resulting ParticleEditHandle to
|
||||||
|
// manage the newly created particle.
|
||||||
|
// Create a particle on the particle server
|
||||||
|
xColor color = { 255, 255, 0}; // Slightly different color on server
|
||||||
|
|
||||||
|
_ballParticleEditHandle = Application::getInstance()->makeParticle(fingerTipPosition / (float)TREE_SCALE,
|
||||||
|
TOY_BALL_RADIUS / (float) TREE_SCALE,
|
||||||
|
color,
|
||||||
|
_toyBallVelocity / (float)TREE_SCALE,
|
||||||
|
TOY_BALL_GRAVITY / (float) TREE_SCALE,
|
||||||
|
TOY_BALL_DAMPING,
|
||||||
|
TOY_BALL_UPDATE_SCRIPT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_toyBallInHand) {
|
if (_toyBallInHand) {
|
||||||
// Ball is in hand
|
// Ball is in hand
|
||||||
_toyBallPosition = fingerTipPosition;
|
_toyBallPosition = fingerTipPosition;
|
||||||
_toyBallVelocity = glm::vec3(0);
|
_toyBallVelocity = glm::vec3(0);
|
||||||
|
|
||||||
|
xColor color = { 255, 255, 0}; // Slightly different color on server
|
||||||
|
|
||||||
|
_ballParticleEditHandle->updateParticle(fingerTipPosition / (float)TREE_SCALE,
|
||||||
|
TOY_BALL_RADIUS / (float) TREE_SCALE,
|
||||||
|
color,
|
||||||
|
_toyBallVelocity / (float)TREE_SCALE,
|
||||||
|
TOY_BALL_GRAVITY / (float) TREE_SCALE,
|
||||||
|
TOY_BALL_DAMPING,
|
||||||
|
TOY_BALL_UPDATE_SCRIPT);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// If toy ball just released, add velocity to it!
|
// If toy ball just released, add velocity to it!
|
||||||
if (_toyBallInHand) {
|
if (_toyBallInHand) {
|
||||||
|
|
||||||
_toyBallInHand = false;
|
_toyBallInHand = false;
|
||||||
glm::vec3 handVelocity = palm.getRawVelocity();
|
glm::vec3 handVelocity = palm.getRawVelocity();
|
||||||
glm::vec3 fingerTipVelocity = palm.getTipVelocity();
|
glm::vec3 fingerTipVelocity = palm.getTipVelocity();
|
||||||
glm::quat avatarRotation = _owningAvatar->getOrientation();
|
glm::quat avatarRotation = _owningAvatar->getOrientation();
|
||||||
//printVector(avatarRotation * handVelocity);
|
//printVector(avatarRotation * handVelocity);
|
||||||
_toyBallVelocity += avatarRotation * fingerTipVelocity;
|
_toyBallVelocity += avatarRotation * fingerTipVelocity;
|
||||||
|
|
||||||
// Create a particle on the particle server
|
|
||||||
xColor color = { 255, 255, 0}; // Slightly different color on server
|
xColor color = { 255, 255, 0}; // Slightly different color on server
|
||||||
glm::vec3 gravity = glm::vec3(0, -1, 0);
|
_ballParticleEditHandle->updateParticle(fingerTipPosition / (float)TREE_SCALE,
|
||||||
float damping = 0.99f;
|
TOY_BALL_RADIUS / (float) TREE_SCALE,
|
||||||
QString updateScript("");
|
color,
|
||||||
Application::getInstance()->makeParticle(fingerTipPosition / (float)TREE_SCALE,
|
_toyBallVelocity / (float)TREE_SCALE,
|
||||||
TOY_BALL_RADIUS / (float) TREE_SCALE,
|
TOY_BALL_GRAVITY / (float) TREE_SCALE,
|
||||||
color,
|
TOY_BALL_DAMPING,
|
||||||
_toyBallVelocity / (float)TREE_SCALE,
|
TOY_BALL_UPDATE_SCRIPT);
|
||||||
gravity / (float) TREE_SCALE, damping, updateScript);
|
|
||||||
|
// 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 _ballParticleEditHandle;
|
||||||
|
_ballParticleEditHandle = NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Simulate toy ball
|
// Simulate toy ball
|
||||||
_toyBallPosition += _toyBallVelocity * deltaTime;
|
_toyBallPosition += _toyBallVelocity * deltaTime;
|
||||||
|
|
||||||
if (!_toyBallInHand) {
|
if (!_toyBallInHand) {
|
||||||
_toyBallVelocity += TOYBALL_GRAVITY * deltaTime;
|
_toyBallVelocity += TOY_BALL_GRAVITY * deltaTime;
|
||||||
}
|
}
|
||||||
if (_toyBallPosition.y < 0.f) {
|
if (_toyBallPosition.y < 0.f) {
|
||||||
_toyBallPosition.y = 0.f;
|
_toyBallPosition.y = 0.f;
|
||||||
_toyBallVelocity.y *= -1.f;
|
_toyBallVelocity.y *= -1.f;
|
||||||
}
|
}
|
||||||
_toyBallVelocity -= (_toyBallVelocity * TOYBALL_DAMPING) * deltaTime;
|
_toyBallVelocity -= (_toyBallVelocity * TOY_BALL_DAMPING) * deltaTime;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
#include <AvatarData.h>
|
#include <AvatarData.h>
|
||||||
#include <HandData.h>
|
#include <HandData.h>
|
||||||
|
#include <ParticleEditHandle.h>
|
||||||
|
|
||||||
#include "Balls.h"
|
#include "Balls.h"
|
||||||
#include "InterfaceConfig.h"
|
#include "InterfaceConfig.h"
|
||||||
|
@ -26,9 +27,11 @@
|
||||||
#include "devices/SerialInterface.h"
|
#include "devices/SerialInterface.h"
|
||||||
#include "VoxelSystem.h"
|
#include "VoxelSystem.h"
|
||||||
|
|
||||||
|
|
||||||
class Avatar;
|
class Avatar;
|
||||||
class ProgramObject;
|
class ProgramObject;
|
||||||
|
|
||||||
|
|
||||||
class Hand : public HandData {
|
class Hand : public HandData {
|
||||||
public:
|
public:
|
||||||
Hand(Avatar* owningAvatar);
|
Hand(Avatar* owningAvatar);
|
||||||
|
@ -95,7 +98,8 @@ private:
|
||||||
|
|
||||||
glm::vec3 _toyBallPosition;
|
glm::vec3 _toyBallPosition;
|
||||||
glm::vec3 _toyBallVelocity;
|
glm::vec3 _toyBallVelocity;
|
||||||
bool _toyBallInHand;
|
bool _toyBallInHand;
|
||||||
|
ParticleEditHandle* _ballParticleEditHandle;
|
||||||
|
|
||||||
float _pitchUpdate;
|
float _pitchUpdate;
|
||||||
|
|
||||||
|
|
|
@ -85,6 +85,7 @@ void ParticleEditHandle::handleAddResponse(unsigned char* packetData , int packe
|
||||||
if (_allHandles.find(creatorTokenID) != _allHandles.end()) {
|
if (_allHandles.find(creatorTokenID) != _allHandles.end()) {
|
||||||
ParticleEditHandle* theHandle = _allHandles[creatorTokenID];
|
ParticleEditHandle* theHandle = _allHandles[creatorTokenID];
|
||||||
theHandle->_id = particleID;
|
theHandle->_id = particleID;
|
||||||
|
theHandle->_isKnownID = true;
|
||||||
printf("handleAddResponse() for creatorTokenID=%u theHandle->_id=%u\n",creatorTokenID, particleID);
|
printf("handleAddResponse() for creatorTokenID=%u theHandle->_id=%u\n",creatorTokenID, particleID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue