mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 21:43:13 +02:00
making toy ball
This commit is contained in:
parent
3d84b72e22
commit
83a1654d9c
6 changed files with 67 additions and 10 deletions
|
@ -2475,6 +2475,7 @@ void Application::updateAvatar(float deltaTime) {
|
||||||
|
|
||||||
// apply pitch from touch
|
// apply pitch from touch
|
||||||
_myAvatar.getHead().setMousePitch(_myAvatar.getHead().getMousePitch() + _pitchFromTouch);
|
_myAvatar.getHead().setMousePitch(_myAvatar.getHead().getMousePitch() + _pitchFromTouch);
|
||||||
|
|
||||||
_pitchFromTouch = 0.0f;
|
_pitchFromTouch = 0.0f;
|
||||||
|
|
||||||
// Update my avatar's state from gyros and/or webcam
|
// Update my avatar's state from gyros and/or webcam
|
||||||
|
|
|
@ -27,7 +27,10 @@ Hand::Hand(Avatar* owningAvatar) :
|
||||||
_ballColor(0.0, 0.0, 0.4),
|
_ballColor(0.0, 0.0, 0.4),
|
||||||
_collisionCenter(0,0,0),
|
_collisionCenter(0,0,0),
|
||||||
_collisionAge(0),
|
_collisionAge(0),
|
||||||
_collisionDuration(0)
|
_collisionDuration(0),
|
||||||
|
_toyBallPosition(0),
|
||||||
|
_toyBallVelocity(0),
|
||||||
|
_toyBallInHand(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,13 +67,50 @@ void Hand::simulate(float deltaTime, bool isMine) {
|
||||||
calculateGeometry();
|
calculateGeometry();
|
||||||
|
|
||||||
if (isMine) {
|
if (isMine) {
|
||||||
// Create a voxel at fingertip if controller button is pressed
|
|
||||||
const float FINGERTIP_VOXEL_SIZE = 0.0125;
|
const float FINGERTIP_VOXEL_SIZE = 0.0125;
|
||||||
|
|
||||||
|
// Iterate hand controllers, take actions as needed
|
||||||
|
|
||||||
for (size_t i = 0; i < getNumPalms(); ++i) {
|
for (size_t i = 0; i < getNumPalms(); ++i) {
|
||||||
PalmData& palm = getPalms()[i];
|
PalmData& palm = getPalms()[i];
|
||||||
if (palm.isActive()) {
|
if (palm.isActive()) {
|
||||||
FingerData& finger = palm.getFingers()[0]; // Sixense has only one finger
|
FingerData& finger = palm.getFingers()[0]; // Sixense has only one finger
|
||||||
glm::vec3 fingerTipPosition = finger.getTipPosition();
|
glm::vec3 fingerTipPosition = finger.getTipPosition();
|
||||||
|
// Toy ball game
|
||||||
|
if (palm.getSixenseID() == 0) {
|
||||||
|
if (palm.getControllerButtons() & BUTTON_FWD) {
|
||||||
|
// If grabbing toy ball, add forces to it
|
||||||
|
if (!_toyBallInHand) {
|
||||||
|
// Test for whether close enough to catch and catch
|
||||||
|
bool isCaught = true;
|
||||||
|
if (isCaught) {
|
||||||
|
_toyBallInHand = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (_toyBallInHand) {
|
||||||
|
// Ball is in hand
|
||||||
|
_toyBallPosition = fingerTipPosition;
|
||||||
|
_toyBallVelocity = glm::vec3(0);
|
||||||
|
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// If toy ball just released, add velocity to it!
|
||||||
|
if (_toyBallInHand) {
|
||||||
|
_toyBallInHand = false;
|
||||||
|
glm::vec3 handVelocity = palm.getVelocity();
|
||||||
|
printVector(handVelocity);
|
||||||
|
_toyBallVelocity += handVelocity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Simulate toy ball
|
||||||
|
const glm::vec3 TOYBALL_GRAVITY (0, -1, 0);
|
||||||
|
_toyBallPosition += _toyBallVelocity * deltaTime;
|
||||||
|
if (!_toyBallInHand) {
|
||||||
|
_toyBallVelocity += TOYBALL_GRAVITY * deltaTime;
|
||||||
|
}
|
||||||
|
_toyBallVelocity *= 0.99f;
|
||||||
|
}
|
||||||
|
|
||||||
if (palm.getControllerButtons() & BUTTON_1) {
|
if (palm.getControllerButtons() & BUTTON_1) {
|
||||||
if (glm::length(fingerTipPosition - _lastFingerAddVoxel) > (FINGERTIP_VOXEL_SIZE / 2.f)) {
|
if (glm::length(fingerTipPosition - _lastFingerAddVoxel) > (FINGERTIP_VOXEL_SIZE / 2.f)) {
|
||||||
QColor paintColor = Menu::getInstance()->getActionForOption(MenuOption::VoxelPaintColor)->data().value<QColor>();
|
QColor paintColor = Menu::getInstance()->getActionForOption(MenuOption::VoxelPaintColor)->data().value<QColor>();
|
||||||
|
@ -253,6 +293,14 @@ void Hand::render( bool isMine) {
|
||||||
renderLeapHands();
|
renderLeapHands();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Render toy ball
|
||||||
|
if (isMine) {
|
||||||
|
glPushMatrix();
|
||||||
|
glColor4f(1, 0, 0, 0.5);
|
||||||
|
glTranslatef(_toyBallPosition.x, _toyBallPosition.y, _toyBallPosition.z);
|
||||||
|
glutSolidSphere(0.1f, 10, 10);
|
||||||
|
glPopMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
if (isMine) {
|
if (isMine) {
|
||||||
// If hand/voxel collision has happened, render a little expanding sphere
|
// If hand/voxel collision has happened, render a little expanding sphere
|
||||||
|
|
|
@ -86,6 +86,11 @@ private:
|
||||||
void calculateGeometry();
|
void calculateGeometry();
|
||||||
|
|
||||||
void handleVoxelCollision(PalmData* palm, const glm::vec3& fingerTipPosition, VoxelTreeElement* voxel, float deltaTime);
|
void handleVoxelCollision(PalmData* palm, const glm::vec3& fingerTipPosition, VoxelTreeElement* voxel, float deltaTime);
|
||||||
|
|
||||||
|
glm::vec3 _toyBallPosition;
|
||||||
|
glm::vec3 _toyBallVelocity;
|
||||||
|
bool _toyBallInHand;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -42,8 +42,6 @@ void SixenseManager::update(float deltaTime) {
|
||||||
sixenseControllerData data;
|
sixenseControllerData data;
|
||||||
sixenseGetNewestData(i, &data);
|
sixenseGetNewestData(i, &data);
|
||||||
|
|
||||||
//printf("si: %i\n", data.controller_index);
|
|
||||||
|
|
||||||
// Set palm position and normal based on Hydra position/orientation
|
// Set palm position and normal based on Hydra position/orientation
|
||||||
|
|
||||||
// Either find a palm matching the sixense controller, or make a new one
|
// Either find a palm matching the sixense controller, or make a new one
|
||||||
|
@ -82,16 +80,18 @@ void SixenseManager::update(float deltaTime) {
|
||||||
const glm::vec3 SPHERE_TO_TORSO(-250.f, -300.f, -300.f);
|
const glm::vec3 SPHERE_TO_TORSO(-250.f, -300.f, -300.f);
|
||||||
position = SPHERE_TO_TORSO + position;
|
position = SPHERE_TO_TORSO + position;
|
||||||
|
|
||||||
// Compute current velocity from position change
|
|
||||||
palm->setVelocity((position - palm->getRawPosition()) / deltaTime / 1000.f); // meters/sec
|
|
||||||
palm->setRawPosition(position);
|
|
||||||
|
|
||||||
// Rotation of Palm
|
// Rotation of Palm
|
||||||
glm::quat rotation(data.rot_quat[3], -data.rot_quat[0], data.rot_quat[1], -data.rot_quat[2]);
|
glm::quat rotation(data.rot_quat[3], -data.rot_quat[0], data.rot_quat[1], -data.rot_quat[2]);
|
||||||
rotation = glm::angleAxis(180.0f, 0.f, 1.f, 0.f) * rotation;
|
rotation = glm::angleAxis(180.0f, 0.f, 1.f, 0.f) * rotation;
|
||||||
const glm::vec3 PALM_VECTOR(0.0f, -1.0f, 0.0f);
|
const glm::vec3 PALM_VECTOR(0.0f, -1.0f, 0.0f);
|
||||||
palm->setRawNormal(rotation * PALM_VECTOR);
|
glm::vec3 newNormal = rotation * PALM_VECTOR;
|
||||||
|
palm->setRawNormal(newNormal);
|
||||||
|
|
||||||
|
// Compute current velocity from position change
|
||||||
|
glm::vec3 rawVelocity = (position - palm->getRawPosition()) / deltaTime / 1000.f;
|
||||||
|
palm->setVelocity(rotation * rawVelocity); // meters/sec
|
||||||
|
palm->setRawPosition(position);
|
||||||
|
|
||||||
// initialize the "finger" based on the direction
|
// initialize the "finger" based on the direction
|
||||||
FingerData finger(palm, &hand);
|
FingerData finger(palm, &hand);
|
||||||
finger.setActive(true);
|
finger.setActive(true);
|
||||||
|
|
|
@ -62,6 +62,7 @@ PalmData::PalmData(HandData* owningHandData) :
|
||||||
_rawPosition(0, 0, 0),
|
_rawPosition(0, 0, 0),
|
||||||
_rawNormal(0, 1, 0),
|
_rawNormal(0, 1, 0),
|
||||||
_velocity(0, 0, 0),
|
_velocity(0, 0, 0),
|
||||||
|
_rotationalVelocity(0, 0, 0),
|
||||||
_controllerButtons(0),
|
_controllerButtons(0),
|
||||||
_isActive(false),
|
_isActive(false),
|
||||||
_leapID(LEAPID_INVALID),
|
_leapID(LEAPID_INVALID),
|
||||||
|
|
|
@ -140,7 +140,7 @@ public:
|
||||||
void setRawNormal(const glm::vec3& normal) { _rawNormal = normal; }
|
void setRawNormal(const glm::vec3& normal) { _rawNormal = normal; }
|
||||||
void setVelocity(const glm::vec3& velocity) { _velocity = velocity; }
|
void setVelocity(const glm::vec3& velocity) { _velocity = velocity; }
|
||||||
const glm::vec3& getVelocity() const { return _velocity; }
|
const glm::vec3& getVelocity() const { return _velocity; }
|
||||||
|
const glm::vec3& getRotationalVelocity() const { return _rotationalVelocity; }
|
||||||
void addToPosition(const glm::vec3& delta);
|
void addToPosition(const glm::vec3& delta);
|
||||||
|
|
||||||
void incrementFramesWithoutData() { _numFramesWithoutData++; }
|
void incrementFramesWithoutData() { _numFramesWithoutData++; }
|
||||||
|
@ -165,6 +165,8 @@ private:
|
||||||
glm::vec3 _rawPosition;
|
glm::vec3 _rawPosition;
|
||||||
glm::vec3 _rawNormal;
|
glm::vec3 _rawNormal;
|
||||||
glm::vec3 _velocity;
|
glm::vec3 _velocity;
|
||||||
|
glm::vec3 _rotationalVelocity;
|
||||||
|
glm::quat _lastRotation;
|
||||||
int _controllerButtons;
|
int _controllerButtons;
|
||||||
float _trigger;
|
float _trigger;
|
||||||
float _joystickX, _joystickY;
|
float _joystickX, _joystickY;
|
||||||
|
|
Loading…
Reference in a new issue