Matrix44f AnimChannel::getRotation( float time ) { if(numRKeys < 1) { return Matrix44f(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); } else if (numRKeys == 1) { return rotationKeys[0]->toMatrix(); } //else interpolate float w,x,y,z,w0,x0,y0,z0,w1,x1,y1,z1,t0,t1; int i = 0; for(; i < numRKeys && rKeyTimes[i] < time; i++){} if(i == 0 || i == numRKeys)//after last point { w0 = rotationKeys[numRKeys - 1]->getW(); x0 = rotationKeys[numRKeys - 1]->getX(); y0 = rotationKeys[numRKeys - 1]->getY(); z0 = rotationKeys[numRKeys - 1]->getZ(); w1 = rotationKeys[0]->getW(); x1 = rotationKeys[0]->getX(); y1 = rotationKeys[0]->getY(); z1 = rotationKeys[0]->getZ(); t0 = rKeyTimes[numRKeys-2]; t1 = rKeyTimes[numRKeys-1]; } else { w0 = rotationKeys[i-1]->getW(); x0 = rotationKeys[i-1]->getX(); y0 = rotationKeys[i-1]->getY(); z0 = rotationKeys[i-1]->getZ(); w1 = rotationKeys[i]->getW(); x1 = rotationKeys[i]->getX(); y1 = rotationKeys[i]->getY(); z1 = rotationKeys[i]->getZ(); t0 = rKeyTimes[i-1]; t1 = rKeyTimes[i]; } Quaternionf rotQuat(Mathf::lerp(time,t0,t1,w0,w1), Mathf::lerp(time,t0,t1,x0,x1), Mathf::lerp(time,t0,t1,y0,y1), Mathf::lerp(time,t0,t1,z0,z1)); return rotQuat.toMatrix(); }
void Transform::Rotate(const Kiwi::Vector3& rotationAxis, float rotationAmount) { Kiwi::Quaternion rotQuat(rotationAxis, rotationAmount); this->Rotate(rotQuat); }
CChangeCameraRTKey::CChangeCameraRTKey( int frame, const Mth::Quat& theQuat, const Mth::Vector& theVector, bool isEndKey ) : CCustomAnimKey( frame ) { // rotate by 90 degrees, // eventually, we should do this in the build tools Mth::Quat rotQuat( Mth::Vector(1,0,0), Mth::DegToRad(90.0f) ); m_rot = theQuat * rotQuat; m_trans[X] = theVector[X]; m_trans[Y] = theVector[Z]; m_trans[Z] = -theVector[Y]; m_trans[W] = 1.0f; m_endKey = isEndKey; }
///This code is actually wrong: the order of transformations is lost, so we need to rewrite this! btTransform GetbtTransformFromCOLLADA_DOM(domMatrix_Array& matrixArray, domRotate_Array& rotateArray, domTranslate_Array& translateArray, float meterScaling ) { btTransform startTransform; startTransform.setIdentity(); unsigned int i; //either load the matrix (worldspace) or incrementally build the transform from 'translate'/'rotate' for (i=0;i<matrixArray.getCount();i++) { domMatrixRef matrixRef = matrixArray[i]; domFloat4x4 fl16 = matrixRef->getValue(); btVector3 origin((btScalar)fl16.get(3), (btScalar)fl16.get(7), (btScalar)fl16.get(11)); startTransform.setOrigin(origin*meterScaling); btMatrix3x3 basis((btScalar)fl16.get(0),(btScalar)fl16.get(1),(btScalar)fl16.get(2), (btScalar)fl16.get(4),(btScalar)fl16.get(5),(btScalar)fl16.get(6), (btScalar)fl16.get(8),(btScalar)fl16.get(9),(btScalar)fl16.get(10)); startTransform.setBasis(basis); } for (i=0;i<rotateArray.getCount();i++) { domRotateRef rotateRef = rotateArray[i]; domFloat4 fl4 = rotateRef->getValue(); btScalar angleRad = (btScalar)SIMD_RADS_PER_DEG*(btScalar)fl4.get(3); btQuaternion rotQuat(btVector3((btScalar)fl4.get(0),(btScalar)fl4.get(1),(btScalar)fl4.get(2)),angleRad); startTransform.getBasis() = startTransform.getBasis() * btMatrix3x3(rotQuat); } for (i=0;i<translateArray.getCount();i++) { domTranslateRef translateRef = translateArray[i]; domFloat3 fl3 = translateRef->getValue(); btVector3 orgTrans((btScalar)fl3.get(0),(btScalar)fl3.get(1),(btScalar)fl3.get(2)); startTransform.getOrigin() += orgTrans*meterScaling; } return startTransform; }
void cBatchRenderManager::push(sSphere const* sphere, DWORD color) { // int vertNum = 50; float unitAngle = cMath::TWOPI/(float)vertNum; // sVector3 pos(1.0f, 0.0f, 0.0f); sVector3 out, startV, endV; addMulVec3(sphere->m_center, pos, sphere->m_radius, startV); // sQuaternion quat; float angle = 0.0f; for (int i = 0; i <= vertNum; ++i, angle += unitAngle) { rotQuat(pos, sVector3(0.0f, 1.0f, 0.0f), angle, out); addMulVec3(sphere->m_center, out, sphere->m_radius, endV); push(&startV, &endV, color); startV = endV; } }
bool Gizmo3D::RotateEditNodes(Vector3 adjust) { bool moved = false; /* if (rotateSnap) { float rotateStepScaled = rotateStep * snapScale; adjust.x = Floor(adjust.x / rotateStepScaled + 0.5) * rotateStepScaled; adjust.y = Floor(adjust.y / rotateStepScaled + 0.5) * rotateStepScaled; adjust.z = Floor(adjust.z / rotateStepScaled + 0.5) * rotateStepScaled; } */ if (adjust.Length() > M_EPSILON) { moved = true; for (unsigned i = 0; i < editNodes_->Size(); ++i) { Node* node = editNodes_->At(i); Quaternion rotQuat(adjust.x_, adjust.y_, adjust.z_); if (axisMode_ == AXIS_LOCAL && editNodes_->Size() == 1) node->SetRotation(node->GetRotation() * rotQuat); else { Vector3 offset = node->GetWorldPosition() - gizmoAxisX_.axisRay_.origin_; if (node->GetParent() && node->GetParent()->GetWorldRotation() != Quaternion(1, 0, 0, 0)) rotQuat = node->GetParent()->GetWorldRotation().Inverse() * rotQuat * node->GetParent()->GetWorldRotation(); node->SetRotation(rotQuat * node->GetRotation()); Vector3 newPosition = gizmoAxisX_.axisRay_.origin_ + rotQuat * offset; if (node->GetParent()) newPosition = node->GetParent()->WorldToLocal(newPosition); node->SetPosition(newPosition); } } } return moved; }
OffsetObject* ObjectPool::getObject(const irr::core::vector3df& apos, const irr::core::vector3df& scale, const irr::core::vector3df& rot, bool addToOffsetManager) { //dprintf(MY_DEBUG_NOTE, "ObjectPool::getObject(): %s\n", name.c_str()); OffsetObject* offsetObject = 0; if (!objectList.empty()) { offsetObject = objectList.front(); // *objectList.begin(); objectList.erase(objectList.begin()); } else { offsetObject = createNewInstance(); } offsetObject->setUpdateCB(0); //offsetObject->setPos(apos); offsetObject->getNode()->setPosition(apos); offsetObject->getNode()->setScale(scale); offsetObject->getNode()->setRotation(rot); offsetObject->getNode()->setMaterialType(material); if (Shaders::getInstance()->getSupportedSMVersion() < 2) { offsetObject->getNode()->setMaterialFlag(irr::video::EMF_LIGHTING, Settings::getInstance()->nonshaderLight); } else { offsetObject->getNode()->setMaterialFlag(irr::video::EMF_LIGHTING, false); } //printf("-------------- texture: %p\n", texture); offsetObject->getNode()->setMaterialTexture(0, texture); if (hkShape) { hk::lock(); hkpRigidBodyCinfo groundInfo; groundInfo.m_shape = hkShape; groundInfo.m_position.set(apos.X, apos.Y, apos.Z); if (rot != irr::core::vector3df()) { irr::core::vector3df rotRad = rot * irr::core::DEGTORAD; irr::core::quaternion rotQuat(rotRad); groundInfo.m_rotation = hkQuaternion(rotQuat.X, rotQuat.Y, rotQuat.Z, rotQuat.W); } if (objectType == Vehicle) { groundInfo.m_motionType = hkpMotion::MOTION_BOX_INERTIA; groundInfo.m_mass = mass; // TODO //groundInfo.m_position.set(0.0f, 0.0f, 0.0f); groundInfo.m_inertiaTensor.setDiagonal(1.0f, 1.0f, 1.0f); groundInfo.m_centerOfMass.set(center.X, center.Y, center.Z); groundInfo.m_collisionFilterInfo = hkpGroupFilter::calcFilterInfo(hk::materialType::vehicleId); } else { groundInfo.m_motionType = hkpMotion::MOTION_FIXED; groundInfo.m_collisionFilterInfo = hkpGroupFilter::calcFilterInfo(hk::materialType::treeId); } groundInfo.m_friction = friction; hkpRigidBody* hkBody = new hkpRigidBody(groundInfo); if (objectType != Vehicle) { hkpPropertyValue val(1); hkBody->addProperty(hk::materialType::treeId, val); hk::hkWorld->addEntity(hkBody); } else { hkpPropertyValue val(1); hkBody->addProperty(hk::materialType::vehicleId, val); } hk::unlock(); offsetObject->setBody(hkBody); //hkBody->activate(); } offsetObject->setPool(this); inUse++; if (addToOffsetManager) { offsetObject->addToManager(); } offsetObject->getNode()->setVisible(true); switch (objectType) { case Grass: case MyTree: break; default: ObjectPoolManager::getInstance()->addShadowNode(offsetObject->getNode()); break; } return offsetObject; }