Don’t render collision if not own avatar, don’t check for collisions with voxel tree if not me.

This commit is contained in:
Philip Rosedale 2013-12-05 13:36:00 -08:00
parent 0d33593561
commit a7dacec63d
4 changed files with 100 additions and 97 deletions

View file

@ -785,7 +785,7 @@ void Avatar::renderBody(bool forceRenderHead) {
_head.render(alpha, false); _head.render(alpha, false);
} }
} }
_hand.render(); _hand.render(false);
} }
void Avatar::getSkinColors(glm::vec3& lighter, glm::vec3& darker) { void Avatar::getSkinColors(glm::vec3& lighter, glm::vec3& darker) {

View file

@ -70,56 +70,58 @@ void Hand::simulate(float deltaTime, bool isMine) {
updateRaveGloveParticles(deltaTime); updateRaveGloveParticles(deltaTime);
} }
// Create a voxel at fingertip if controller button is pressed if (isMine) {
const float FINGERTIP_VOXEL_SIZE = 0.0125; // Create a voxel at fingertip if controller button is pressed
for (size_t i = 0; i < getNumPalms(); ++i) { const float FINGERTIP_VOXEL_SIZE = 0.0125;
PalmData& palm = getPalms()[i]; for (size_t i = 0; i < getNumPalms(); ++i) {
if (palm.isActive()) { PalmData& palm = getPalms()[i];
FingerData& finger = palm.getFingers()[0]; // Sixense has only one finger if (palm.isActive()) {
glm::vec3 fingerTipPosition = finger.getTipPosition(); FingerData& finger = palm.getFingers()[0]; // Sixense has only one finger
if (palm.getControllerButtons() & BUTTON_1) { glm::vec3 fingerTipPosition = finger.getTipPosition();
if (glm::length(fingerTipPosition - _lastFingerAddVoxel) > (FINGERTIP_VOXEL_SIZE / 2.f)) { if (palm.getControllerButtons() & BUTTON_1) {
QColor paintColor = Menu::getInstance()->getActionForOption(MenuOption::VoxelPaintColor)->data().value<QColor>(); if (glm::length(fingerTipPosition - _lastFingerAddVoxel) > (FINGERTIP_VOXEL_SIZE / 2.f)) {
Application::getInstance()->makeVoxel(fingerTipPosition, QColor paintColor = Menu::getInstance()->getActionForOption(MenuOption::VoxelPaintColor)->data().value<QColor>();
FINGERTIP_VOXEL_SIZE, Application::getInstance()->makeVoxel(fingerTipPosition,
paintColor.red(), FINGERTIP_VOXEL_SIZE,
paintColor.green(), paintColor.red(),
paintColor.blue(), paintColor.green(),
true); paintColor.blue(),
_lastFingerAddVoxel = fingerTipPosition; true);
_lastFingerAddVoxel = fingerTipPosition;
}
} else if (palm.getControllerButtons() & BUTTON_2) {
if (glm::length(fingerTipPosition - _lastFingerDeleteVoxel) > (FINGERTIP_VOXEL_SIZE / 2.f)) {
Application::getInstance()->removeVoxel(fingerTipPosition, FINGERTIP_VOXEL_SIZE);
_lastFingerDeleteVoxel = fingerTipPosition;
}
} }
} else if (palm.getControllerButtons() & BUTTON_2) { // Check if the finger is intersecting with a voxel in the client voxel tree
if (glm::length(fingerTipPosition - _lastFingerDeleteVoxel) > (FINGERTIP_VOXEL_SIZE / 2.f)) { VoxelTreeElement* fingerNode = Application::getInstance()->getVoxels()->getVoxelEnclosing(
Application::getInstance()->removeVoxel(fingerTipPosition, FINGERTIP_VOXEL_SIZE); glm::vec3(fingerTipPosition / (float)TREE_SCALE));
_lastFingerDeleteVoxel = fingerTipPosition; if (fingerNode) {
} if (!palm.getIsCollidingWithVoxel()) {
} // Collision has just started
// Check if the finger is intersecting with a voxel in the client voxel tree palm.setIsCollidingWithVoxel(true);
VoxelTreeElement* fingerNode = Application::getInstance()->getVoxels()->getVoxelEnclosing( handleVoxelCollision(&palm, fingerTipPosition, fingerNode, deltaTime);
glm::vec3(fingerTipPosition / (float)TREE_SCALE)); // Set highlight voxel
if (fingerNode) { VoxelDetail voxel;
if (!palm.getIsCollidingWithVoxel()) { glm::vec3 pos = fingerNode->getCorner();
// Collision has just started voxel.x = pos.x;
palm.setIsCollidingWithVoxel(true); voxel.y = pos.y;
handleVoxelCollision(&palm, fingerTipPosition, fingerNode, deltaTime); voxel.z = pos.z;
// Set highlight voxel voxel.s = fingerNode->getScale();
VoxelDetail voxel; voxel.red = fingerNode->getColor()[0];
glm::vec3 pos = fingerNode->getCorner(); voxel.green = fingerNode->getColor()[1];
voxel.x = pos.x; voxel.blue = fingerNode->getColor()[2];
voxel.y = pos.y; Application::getInstance()->setHighlightVoxel(voxel);
voxel.z = pos.z; Application::getInstance()->setIsHighlightVoxel(true);
voxel.s = fingerNode->getScale(); }
voxel.red = fingerNode->getColor()[0]; } else {
voxel.green = fingerNode->getColor()[1]; if (palm.getIsCollidingWithVoxel()) {
voxel.blue = fingerNode->getColor()[2]; // Collision has just ended
Application::getInstance()->setHighlightVoxel(voxel); palm.setIsCollidingWithVoxel(false);
Application::getInstance()->setIsHighlightVoxel(true); Application::getInstance()->setIsHighlightVoxel(false);
} }
} else {
if (palm.getIsCollidingWithVoxel()) {
// Collision has just ended
palm.setIsCollidingWithVoxel(false);
Application::getInstance()->setIsHighlightVoxel(false);
} }
} }
} }
@ -217,7 +219,7 @@ void Hand::setRaveGloveEffectsMode(QKeyEvent* event) {
}; };
} }
void Hand::render() { void Hand::render( bool isMine) {
_renderAlpha = 1.0; _renderAlpha = 1.0;
@ -229,6 +231,7 @@ void Hand::render() {
// Use mood lighting for the hand itself // Use mood lighting for the hand itself
setRaveLights(RAVE_LIGHTS_AVATAR); setRaveLights(RAVE_LIGHTS_AVATAR);
} }
renderLeapFingerTrails();
renderLeapHands(); renderLeapHands();
} }
@ -242,54 +245,54 @@ void Hand::render() {
} }
} }
// If hand/voxel collision has happened, render a little expanding sphere if (isMine) {
if (_collisionAge > 0.f) { // If hand/voxel collision has happened, render a little expanding sphere
float opacity = glm::clamp(1.f - (_collisionAge / _collisionDuration), 0.f, 1.f); if (_collisionAge > 0.f) {
glColor4f(1, 0, 0, 0.5 * opacity); float opacity = glm::clamp(1.f - (_collisionAge / _collisionDuration), 0.f, 1.f);
glPushMatrix(); glColor4f(1, 0, 0, 0.5 * opacity);
glTranslatef(_collisionCenter.x, _collisionCenter.y, _collisionCenter.z); glPushMatrix();
glutSolidSphere(_collisionAge * 0.25f, 20, 20); glTranslatef(_collisionCenter.x, _collisionCenter.y, _collisionCenter.z);
glPopMatrix(); glutSolidSphere(_collisionAge * 0.25f, 20, 20);
if (_collisionAge > _collisionDuration) { glPopMatrix();
_collisionAge = 0.f; if (_collisionAge > _collisionDuration) {
_collisionAge = 0.f;
}
} }
}
// If hand controller buttons pressed, render stuff as needed
if (getPalms().size() > 0) {
for (size_t i = 0; i < getPalms().size(); ++i) {
PalmData& palm = getPalms()[i];
// If trigger pulled, thrust in that direction and draw beam
const float MAX_THRUSTER_BEAM_LENGTH = 5.f;
const float THRUSTER_MARKER_SIZE = 0.0125f;
if (palm.getJoystickY() != 0.f) {
FingerData& finger = palm.getFingers()[0];
if (finger.isActive()) {
if (palm.getJoystickY() > 0.f) {
glColor3f(0, 1, 0);
} else {
glColor3f(1, 0, 0);
}
glm::vec3 palmPosition = palm.getPosition();
glm::vec3 pointerPosition = palmPosition +
glm::normalize(finger.getTipPosition() - palmPosition) *
MAX_THRUSTER_BEAM_LENGTH;
glPushMatrix();
glm::vec3 markerPosition = palmPosition +
glm::normalize(finger.getTipPosition() - palmPosition) *
MAX_THRUSTER_BEAM_LENGTH *
(0.5f + palm.getJoystickY() / 2.f);
glTranslatef(markerPosition.x, markerPosition.y, markerPosition.z);
// If hand controller buttons pressed, render stuff as needed glutSolidSphere(THRUSTER_MARKER_SIZE, 10, 10);
if (getPalms().size() > 0) { glPopMatrix();
for (size_t i = 0; i < getPalms().size(); ++i) { glLineWidth(2.0);
PalmData& palm = getPalms()[i]; glBegin(GL_LINES);
// If trigger pulled, thrust in that direction and draw beam glVertex3f(palmPosition.x, palmPosition.y, palmPosition.z);
const float MAX_THRUSTER_BEAM_LENGTH = 5.f; glVertex3f(pointerPosition.x, pointerPosition.y, pointerPosition.z);
const float THRUSTER_MARKER_SIZE = 0.0125f; glEnd();
if (palm.getJoystickY() != 0.f) {
FingerData& finger = palm.getFingers()[0];
if (finger.isActive()) {
if (palm.getJoystickY() > 0.f) {
glColor3f(0, 1, 0);
} else {
glColor3f(1, 0, 0);
} }
glm::vec3 palmPosition = palm.getPosition();
glm::vec3 pointerPosition = palmPosition +
glm::normalize(finger.getTipPosition() - palmPosition) *
MAX_THRUSTER_BEAM_LENGTH;
glPushMatrix();
glm::vec3 markerPosition = palmPosition +
glm::normalize(finger.getTipPosition() - palmPosition) *
MAX_THRUSTER_BEAM_LENGTH *
(0.5f + palm.getJoystickY() / 2.f);
glTranslatef(markerPosition.x, markerPosition.y, markerPosition.z);
glutSolidSphere(THRUSTER_MARKER_SIZE, 10, 10);
glPopMatrix();
glLineWidth(2.0);
glBegin(GL_LINES);
glVertex3f(palmPosition.x, palmPosition.y, palmPosition.z);
glVertex3f(pointerPosition.x, pointerPosition.y, pointerPosition.z);
glEnd();
} }
} }
} }

View file

@ -52,7 +52,7 @@ public:
void init(); void init();
void reset(); void reset();
void simulate(float deltaTime, bool isMine); void simulate(float deltaTime, bool isMine);
void render(); void render(bool isMine);
void renderRaveGloveStage(); void renderRaveGloveStage();
void setRaveLights(RaveLightsSetting setting); void setRaveLights(RaveLightsSetting setting);

View file

@ -728,7 +728,7 @@ void MyAvatar::renderBody(bool forceRenderHead) {
_head.render(alpha, false); _head.render(alpha, false);
} }
} }
_hand.render(); _hand.render(true);
} }
void MyAvatar::updateThrust(float deltaTime, Transmitter * transmitter) { void MyAvatar::updateThrust(float deltaTime, Transmitter * transmitter) {