mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 08:21:32 +02:00
cleanup test toy ball throwing code
This commit is contained in:
parent
bad5d82ceb
commit
2d72bea27a
3 changed files with 66 additions and 44 deletions
|
@ -1498,14 +1498,14 @@ void Application::shootParticle() {
|
|||
|
||||
glm::vec3 position = _viewFrustum.getPosition();
|
||||
glm::vec3 direction = _viewFrustum.getDirection();
|
||||
const float LINEAR_VELOCITY = 30.0f;
|
||||
const float LINEAR_VELOCITY = 5.f;
|
||||
glm::vec3 lookingAt = position + (direction * LINEAR_VELOCITY);
|
||||
|
||||
const float radius = 0.5 / TREE_SCALE;
|
||||
xColor color = { 255, 0, 0};
|
||||
const float radius = 0.125 / TREE_SCALE;
|
||||
xColor color = { 0, 255, 255};
|
||||
glm::vec3 velocity = lookingAt - position;
|
||||
glm::vec3 gravity = DEFAULT_GRAVITY;
|
||||
float damping = DEFAULT_DAMPING;
|
||||
glm::vec3 gravity = DEFAULT_GRAVITY * 0.f;
|
||||
float damping = DEFAULT_DAMPING * 0.01f;
|
||||
QString updateScript("");
|
||||
|
||||
makeParticle(position / (float)TREE_SCALE, radius, color,
|
||||
|
|
|
@ -19,7 +19,12 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
const float FINGERTIP_VOXEL_SIZE = 0.05;
|
||||
const int TOY_BALL_HAND = 1;
|
||||
const float TOY_BALL_RADIUS = 0.05f;
|
||||
const glm::vec3 TOYBALL_GRAVITY (0, -1, 0);
|
||||
float TOYBALL_DAMPING = 1.f;
|
||||
const float PALM_COLLISION_RADIUS = 0.03f;
|
||||
|
||||
Hand::Hand(Avatar* owningAvatar) :
|
||||
HandData((AvatarData*)owningAvatar),
|
||||
|
@ -50,37 +55,7 @@ void Hand::init() {
|
|||
void Hand::reset() {
|
||||
}
|
||||
|
||||
|
||||
void Hand::simulate(float deltaTime, bool isMine) {
|
||||
|
||||
if (_collisionAge > 0.f) {
|
||||
_collisionAge += deltaTime;
|
||||
}
|
||||
|
||||
const glm::vec3 leapHandsOffsetFromFace(0.0, -0.2, -0.3); // place the hand in front of the face where we can see it
|
||||
|
||||
Head& head = _owningAvatar->getHead();
|
||||
_baseOrientation = _owningAvatar->getOrientation();
|
||||
_basePosition = head.calculateAverageEyePosition() + _baseOrientation * leapHandsOffsetFromFace * head.getScale();
|
||||
|
||||
if (isMine) {
|
||||
updateCollisions();
|
||||
}
|
||||
|
||||
calculateGeometry();
|
||||
|
||||
if (isMine) {
|
||||
const float FINGERTIP_VOXEL_SIZE = 0.0125;
|
||||
|
||||
// Iterate hand controllers, take actions as needed
|
||||
|
||||
for (size_t i = 0; i < getNumPalms(); ++i) {
|
||||
PalmData& palm = getPalms()[i];
|
||||
if (palm.isActive()) {
|
||||
FingerData& finger = palm.getFingers()[0]; // Sixense has only one finger
|
||||
glm::vec3 fingerTipPosition = finger.getTipPosition();
|
||||
// Toy ball game
|
||||
if (palm.getSixenseID() == TOY_BALL_HAND) {
|
||||
void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, float deltaTime) {
|
||||
if (palm.getControllerButtons() & BUTTON_FWD) {
|
||||
// If grabbing toy ball, add forces to it
|
||||
if (!_toyBallInHand) {
|
||||
|
@ -105,15 +80,63 @@ void Hand::simulate(float deltaTime, bool isMine) {
|
|||
glm::quat avatarRotation = _owningAvatar->getOrientation();
|
||||
//printVector(avatarRotation * handVelocity);
|
||||
_toyBallVelocity += avatarRotation * fingerTipVelocity;
|
||||
|
||||
// Create a particle on the particle server
|
||||
xColor color = { 255, 255, 0}; // Slightly different color on server
|
||||
glm::vec3 gravity = glm::vec3(0, -1, 0);
|
||||
float damping = 0.99f;
|
||||
QString updateScript("");
|
||||
Application::getInstance()->makeParticle(fingerTipPosition / (float)TREE_SCALE,
|
||||
TOY_BALL_RADIUS / (float) TREE_SCALE,
|
||||
color,
|
||||
_toyBallVelocity / (float)TREE_SCALE,
|
||||
gravity / (float) TREE_SCALE, damping, updateScript);
|
||||
}
|
||||
}
|
||||
// Simulate toy ball
|
||||
const glm::vec3 TOYBALL_GRAVITY (0, -1, 0);
|
||||
_toyBallPosition += _toyBallVelocity * deltaTime;
|
||||
|
||||
if (!_toyBallInHand) {
|
||||
_toyBallVelocity += TOYBALL_GRAVITY * deltaTime;
|
||||
}
|
||||
_toyBallVelocity *= 0.99f;
|
||||
if (_toyBallPosition.y < 0.f) {
|
||||
_toyBallPosition.y = 0.f;
|
||||
_toyBallVelocity.y *= -1.f;
|
||||
}
|
||||
_toyBallVelocity -= (_toyBallVelocity * TOYBALL_DAMPING) * deltaTime;
|
||||
|
||||
}
|
||||
|
||||
void Hand::simulate(float deltaTime, bool isMine) {
|
||||
|
||||
if (_collisionAge > 0.f) {
|
||||
_collisionAge += deltaTime;
|
||||
}
|
||||
|
||||
const glm::vec3 leapHandsOffsetFromFace(0.0, -0.2, -0.3); // place the hand in front of the face where we can see it
|
||||
|
||||
Head& head = _owningAvatar->getHead();
|
||||
_baseOrientation = _owningAvatar->getOrientation();
|
||||
_basePosition = head.calculateAverageEyePosition() + _baseOrientation * leapHandsOffsetFromFace * head.getScale();
|
||||
|
||||
if (isMine) {
|
||||
updateCollisions();
|
||||
}
|
||||
|
||||
calculateGeometry();
|
||||
|
||||
if (isMine) {
|
||||
|
||||
// Iterate hand controllers, take actions as needed
|
||||
|
||||
for (size_t i = 0; i < getNumPalms(); ++i) {
|
||||
PalmData& palm = getPalms()[i];
|
||||
if (palm.isActive()) {
|
||||
FingerData& finger = palm.getFingers()[0]; // Sixense has only one finger
|
||||
glm::vec3 fingerTipPosition = finger.getTipPosition();
|
||||
|
||||
if (palm.getSixenseID() == TOY_BALL_HAND) {
|
||||
simulateToyBall(palm, fingerTipPosition, deltaTime);
|
||||
}
|
||||
|
||||
if (palm.getControllerButtons() & BUTTON_1) {
|
||||
|
@ -166,8 +189,6 @@ void Hand::simulate(float deltaTime, bool isMine) {
|
|||
}
|
||||
}
|
||||
|
||||
const float PALM_COLLISION_RADIUS = 0.03f;
|
||||
|
||||
void Hand::updateCollisions() {
|
||||
// use position to obtain the left and right palm indices
|
||||
int leftPalmIndex, rightPalmIndex;
|
||||
|
@ -301,7 +322,6 @@ void Hand::render( bool isMine) {
|
|||
// Render toy ball
|
||||
if (isMine) {
|
||||
glPushMatrix();
|
||||
const float TOY_BALL_RADIUS = 0.05f;
|
||||
glColor3f(1, 0, 0);
|
||||
glTranslatef(_toyBallPosition.x, _toyBallPosition.y, _toyBallPosition.z);
|
||||
glutSolidSphere(TOY_BALL_RADIUS, 10, 10);
|
||||
|
|
|
@ -91,6 +91,8 @@ private:
|
|||
|
||||
void handleVoxelCollision(PalmData* palm, const glm::vec3& fingerTipPosition, VoxelTreeElement* voxel, float deltaTime);
|
||||
|
||||
void simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, float deltaTime);
|
||||
|
||||
glm::vec3 _toyBallPosition;
|
||||
glm::vec3 _toyBallVelocity;
|
||||
bool _toyBallInHand;
|
||||
|
|
Loading…
Reference in a new issue