void VPathNode::updateWorldData( void ) { if ( !mPath ) { setWorldPosition( getLocalPosition() ); setWorldRotation( getLocalRotation() ); return; } // Fetch Path Details. const MatrixF &pathTransform = mPath->getTransform(); const QuatF &pathRotation( pathTransform ); // Calculate the World Position. Point3F newPosition = getLocalPosition(); newPosition.convolve( mPath->getScale() ); pathTransform.mulP( newPosition ); // Calculate the new Rotation. QuatF newRotation; newRotation.mul( getLocalRotation(), pathRotation ); // Apply. setWorldPosition( newPosition ); setWorldRotation( newRotation ); }
void Transform::setParent(Transform* transform) { if(this->parent != NULL) { for(int i = 0; i < this->parent->children.size(); i++) { if(this->parent->children.at(i) == this) { this->parent->children.erase(this->parent->children.begin() + i); break; } } } if(transform != NULL) { transform->children.push_back(this); } setLocalPosition(getPosition()); setLocalRotation(getRotation()); this->parent = transform; setPosition(getLocalPosition()); setRotation(getLocalRotation()); }
//---------------------------------------------------------------------- void SpaceGameActor::applyForwardImpulse() { vec3f impulseInDirOfShip = transformVector( vec3f( 0.0f, IMPULSE_POWER, 0.0f ), getLocalRotation() ); m_vel += vec2f( impulseInDirOfShip.x, impulseInDirOfShip.y ); m_forcesAppliedBitFlags |= APPLY_FORWARD_IMPULSE; }
//---------------------------------------------------------------------- void SpaceGameActor::applyReverseImpulse() { m_forwardImpulse -= 1.0f; vec3f impulseInDirOfShip = transformVector( vec3f( 0.0f, -IMPULSE_POWER, 0.0f ), getLocalRotation() ); m_vel += vec2f( impulseInDirOfShip.x, impulseInDirOfShip.y ); m_forcesAppliedBitFlags |= APPLY_REVERSE_IMPULSE; }
vec3 Transform::getGlobalRotation() { vec3 out = getLocalRotation(); if (object->parent != nullptr) { out += object->parent->getTransform()->getGlobalRotation(); } return out; }
//---------------------------------------------------------------------- void SpaceGameActor::update( double deltaTime ) { Actor::update( deltaTime ); m_wasSpawnedLastFrame = false; float dt = static_cast< float >( deltaTime ); setRotation( mat3f::createMatrixFromQuaternion( quatf::makeQuaternionFromAxisAngle( MathFuncs<float>::degreesToRadians( m_rotation ), vec3f( 0.0f, 0.0f, 1.0f ) ) ) ); //vec3f impulseInDirOfShip = transformVector( vec3f( 0.0f, IMPULSE_POWER, 0.0f ), getLocalRotation() ); //impulseInDirOfShip *= m_forwardImpulse; // //m_vel += vec2f( impulseInDirOfShip.x, impulseInDirOfShip.y ); m_frames[ m_currentFrame ].position += m_vel*dt; m_vel -= m_vel * m_drag * dt; //m_forwardImpulse = 0.0f; m_frames[ m_currentFrame ].position.x = (float)MathFuncs<int>::wrap( (int)m_frames[ m_currentFrame ].position.x, 0, SCREEN_WIDTH ); m_frames[ m_currentFrame ].position.y = (float)MathFuncs<int>::wrap( (int)m_frames[ m_currentFrame ].position.y, 0, SCREEN_HEIGHT ); vec3f tempDir = transformVector( vec3f( 0.0f, 1.0f, 0.0f ), getLocalRotation() ); tempDir.normalize(); m_dir = vec2f( tempDir.x, tempDir.y ); }
/** * creates a joint between to boxes * and moves box 2 in the correct possition according to box 1 */ int Physics::createJoint(int box1, int box2, int scewIn, int preX, int preY, int preS, int postX, int postY, int postS, int dofX, int dofY, int dofZ){ //default value if(preX==0){preX=50;} if(preY==0){preY=50;} if(postX==0){postX=50;} if(postY==0){postY=50;} preX=preX%99+1; preY=preY%99+1; preS=preS%6; postX=postX%99+1; postY=postY%99+1; postS=postS%6; scewIn=scewIn%360; btScalar scew = ((float)scewIn*2.f*PI)/360.f; //tjek input in debug mode btAssert(preX>0 && preX<100); btAssert(preY>0 && preY<100); btAssert(preS>-1 && preS<6); btAssert(postX>0 && postX<100); btAssert(postY>0 && postY<100); btAssert(postS>-1 && postS<6); //Get box pointers btRigidBody* Box1 = (btRigidBody*) m_dynamicsWorld->getCollisionObjectArray().at(box1); btRigidBody* Box2 = (btRigidBody*) m_dynamicsWorld->getCollisionObjectArray().at(box2); //Define the local transform on the shapes regarding to the joint. btTransform localBox1, localBox2; localBox1.setIdentity(); localBox2.setIdentity(); //box1 btVector3 halfside1 = ((btBoxShape*)Box1->getCollisionShape())->getHalfExtentsWithMargin(); btVector3 center1 =Box1->getWorldTransform().getOrigin(); btQuaternion rotation1 =Box1->getWorldTransform().getRotation(); btVector3 connection1 = getLocalJointPosition(preX,preY,preS,&halfside1); //translate joint localBox1.setOrigin(connection1); localBox1.setRotation(rotation1.inverse()); //box2 btVector3 halfside2 = ((btBoxShape*)Box2->getCollisionShape())->getHalfExtentsWithMargin(); btVector3 connection2 = getLocalJointPosition(postX,postY,postS,&halfside2); btQuaternion rotation2 = getLocalRotation(preS, postS,scew,box1); rotation2*=rotation1; btVector3 center2 = center1+rotate(&connection1,&rotation1.inverse())-rotate(&connection2,&rotation2); //rotate and translate box btTransform trans2; trans2.setIdentity(); //trans2.setRotation(rotation2); trans2.setRotation(rotation2.inverse()); trans2.setOrigin(center2); Box2->setCenterOfMassTransform(trans2); btDefaultMotionState* myMotionState = (btDefaultMotionState*)((Box2)->getMotionState()); myMotionState->setWorldTransform(Box2->getWorldTransform()); //rotate and translate joint localBox2.setRotation(rotation2); localBox2.setOrigin(connection2); //setup contraint/joint btGeneric6DofConstraint* gen6C; //int DOFx = dofX %1; int DOFy = dofY %1; int DOFz = dofZ %1; int DOFx = dofX %170; int DOFy = dofY %170; int DOFz = dofZ %170; // int DOFx = dofX %170+10; int DOFy = dofY%170+10; int DOFz = dofZ %170+10; float DOFxR = ((float)DOFx*2.f*PI)/360.f; float DOFyR = ((float)DOFy*2.f*PI)/360.f; float DOFzR = ((float)DOFz*2.f*PI)/360.f; // printf("%f %f %f\n", DOFxR,DOFyR,DOFzR); UserPointerStruct* theStruct = new UserPointerStruct(); btScalar mass1=1/Box1->getInvMass(); btScalar mass2=1/Box2->getInvMass(); gen6C = new btGeneric6DofConstraint(*Box1,*Box2,localBox1,localBox2,true); gen6C->setLimit(0,0,0);//dist to other box can be set as (0,dist,dist) gen6C->setLimit(1,0,0); gen6C->setLimit(2,0,0); gen6C->setAngularLowerLimit(btVector3(-DOFxR/2,-DOFyR/2,-DOFzR/2)); gen6C->setAngularUpperLimit(btVector3(DOFxR/2,DOFyR/2,DOFzR/2)); sensors.push_back(0); sensors.push_back(0); sensors.push_back(0); theStruct->sensorIndex=sensors.size()-3; float crossSection =getCrossSectionGen6d(preS, &halfside1,preX,preY,postS,&halfside2,postX,postY); theStruct->CrossSectionalStrength=crossSection*muscleStregnth; gen6C->setUserConstraintPtr(theStruct); gen6C->setBreakingImpulseThreshold(tensileStrength*crossSection); m_dynamicsWorld->addConstraint(gen6C,true); int returnVal = currentJointIndex; currentJointIndex++; return returnVal; }
//------------------------------------------- void Camera::update( double deltaTime ) { Node::update( deltaTime ); m_dir = transformVector( vec3f( 0.0f, 0.0f, -1.0f ), getLocalRotation() ); }