BOOL _XKeyframeController::LoadNode_TM( FILE* pFile, _XM_SUBNODE* pSubNode ) { D3DXMATRIX matScale, matWorld; D3DXMatrixIdentity(&pSubNode->matTM); D3DXVECTOR3 tmPos = D3DXVECTOR3(0, 0, 0), tmScale = D3DXVECTOR3(1, 1, 1); D3DXQUATERNION tmRot; D3DXQuaternionIdentity(&tmRot); fread(&tmPos, 1, sizeof(D3DXVECTOR3), pFile); fread(&tmRot, 1, sizeof(D3DXQUATERNION), pFile); fread(&tmScale, 1, sizeof(D3DXVECTOR3), pFile); tmRot.x = sinf(tmRot.w/2.0f)*tmRot.x; tmRot.y = sinf(tmRot.w/2.0f)*tmRot.y; tmRot.z = sinf(tmRot.w/2.0f)*tmRot.z; tmRot.w = cosf(tmRot.w/2.0f); D3DXMatrixRotationQuaternion(&matWorld, &tmRot); matWorld._41 = tmPos.x; matWorld._42 = tmPos.y; matWorld._43 = tmPos.z; D3DXMatrixScaling(&matScale, tmScale.x, tmScale.y, tmScale.z); D3DXMatrixMultiply(&pSubNode->matTM, &matScale, &matWorld); return TRUE; }
SpaceShip::SpaceShip(Terrain *Terrain, Vector3D Position) { m_Terrain = Terrain; m_Camera = new Camera(); m_Position = Position; m_Points = 0; m_Moving = false; m_Turning = false; m_Speed = 0.0f; m_MaxBank = 0.5f; m_MaxSpeed = 6.0f; m_RelativeTime = 0.0f; m_Acceleration = 0.1f; m_NumKPH = 20; m_KPH = new int[m_NumKPH]; ZeroMemory(m_KPH, sizeof(int) * m_NumKPH); m_NextKPH = 0; m_RotY = 0.0f; m_RotZ = 0.0f; D3DXQuaternionIdentity(&m_QuatY); D3DXQuaternionIdentity(&m_QuatZ); m_Mesh = NULL; }
void ArcBall::Reset() { D3DXQuaternionIdentity( &m_qDown ); D3DXQuaternionIdentity( &m_qNow ); D3DXQuaternionIdentity( &m_increament ) ; D3DXMatrixIdentity( &m_mRotation ); m_bDrag = FALSE; m_fRadius = 1.0f; }
void ArcBall::Reset() { D3DXQuaternionIdentity(&previous_quaternion_); D3DXQuaternionIdentity(¤t_quaternion_); D3DXQuaternionIdentity(&rotation_increament_) ; D3DXMatrixIdentity(&rotate_matrix_); is_dragged_ = false; radius_ = 1.0f; }
//-------------------------------------------------------------------------------------- void CD3DArcBall::Reset() { D3DXQuaternionIdentity( &m_qDown ); D3DXQuaternionIdentity( &m_qNow ); D3DXMatrixIdentity( &m_mRotation ); D3DXMatrixIdentity( &m_mTranslation ); D3DXMatrixIdentity( &m_mTranslationDelta ); m_bDrag = FALSE; m_fRadiusTranslation = 3.0f; m_fRadius = 1.0f; }
void ArcBall::Reset() { D3DXQuaternionIdentity( &m_qDown ); D3DXQuaternionIdentity( &m_qNow ); D3DXMatrixIdentity( &m_mRotation ); m_bDrag = FALSE; m_fRadius = 1.0f; RECT rc ; GetClientRect(GetForegroundWindow(), &rc) ; SetWindow(rc.right, rc.bottom) ; }
//----------------------------------------------------------------------------- // Name: // Desc: //----------------------------------------------------------------------------- CD3DArcBall::CD3DArcBall() { D3DXQuaternionIdentity( &m_qDown ); D3DXQuaternionIdentity( &m_qNow ); D3DXMatrixIdentity( &m_matRotation ); D3DXMatrixIdentity( &m_matRotationDelta ); D3DXMatrixIdentity( &m_matTranslation ); D3DXMatrixIdentity( &m_matTranslationDelta ); m_bDrag = FALSE; m_fRadiusTranslation = 1.0f; m_bRightHanded = FALSE; }
void KG3DTransformation::ReSet() { D3DXMatrixIdentity(&m_Matrix); m_ScalingCenter = D3DXVECTOR3(0,0,0); D3DXQuaternionIdentity(&m_ScalingRotation); m_Scaling = D3DXVECTOR3(1,1,1); m_RotationCenter = D3DXVECTOR3(0,0,0); D3DXQuaternionIdentity(&m_Rotation); m_Translation = D3DXVECTOR3(0,0,0); m_bSleep = FALSE; //m_fAngelY = 0.0f; //m_fAngelX = 0.0f; //m_fAngelZ = 0.0f; }
Object::Object(Mesh* mesh, variable_map* constructor_settings, variable_map* variable_settings) { //Assign dynamic variable pointer this->variable_settings = variable_settings; entity_type = boost::any_cast<std::string>(constructor_settings->at("entity_type")); //Assign mesh entity_mesh = mesh; scale_factor = boost::any_cast<float>(constructor_settings->at("scale")); //Set starting position vector_position.x = boost::any_cast<float>(constructor_settings->at("vec_x")); vector_position.y = boost::any_cast<float>(constructor_settings->at("vec_y")); vector_position.z = boost::any_cast<float>(constructor_settings->at("vec_z")); //Set rotations at zero D3DXQuaternionIdentity(&rotation); axis_rotation = cos(0/2); //Build Hit Sphere D3DXVECTOR3 hit_offset; hit_offset.x = boost::any_cast<float>(constructor_settings->at("hit_offset_x")); hit_offset.y = boost::any_cast<float>(constructor_settings->at("hit_offset_y")); hit_offset.z = boost::any_cast<float>(constructor_settings->at("hit_offset_z")); float hit_radius = boost::any_cast<float>(constructor_settings->at("hit_radius")); this->hit_box = new Collision_Sphere(hit_offset, hit_radius); }
ElCamera::ElCamera() : mRight(1.0f, 0.0f, 0.0f) , mUp(0.0f, 1.0f, 0.0f) , mLook(0.0f, 0.0f, 1.0f) , mPosition(0.0f, 25.0f, 0.0f) , mYawFixed(true) , mDerivedPosition(0.0f, 0.0f, 0.0f) , mRealPosition(0.0f, 0.0f, 0.0f) { D3DXQuaternionIdentity(&mOrientation); D3DXQuaternionIdentity(&mDerivedOrientation); D3DXQuaternionIdentity(&mRealOrientation); invalidateFrustum(); invalidateView(); }
KG3DSceneEntityGroup::KG3DSceneEntityGroup(void) { m_dwID = 0; m_dwType = 0; m_ulRefCount = 0; D3DXQuaternionIdentity(&m_Rotation); }
AirPlane::AirPlane() { state = 0; lastinput = -1; D3DXQUATERNION q; D3DXQuaternionIdentity(&q); rotation = q; position = D3DXVECTOR3(0, 0, 0); }
State::State(bool rotvel_on, State* follow) { m_rotvel = D3DXVECTOR3(0.0f, 0.0f, 0.0f); m_posvel = D3DXVECTOR3(0.0f, 0.0f, 0.0f); D3DXQuaternionIdentity(&m_rot); D3DXQuaternionIdentity(&m_prevRot); m_pos = D3DXVECTOR3(0.0f, 0.0f, 0.0f); m_acceleration = D3DXVECTOR3(0.0f, 0.0f, 0.0f); m_friction = 0.0f; m_time = 0.0f; m_up = D3DXVECTOR3(0.0f, 1.0f, 0.0f); m_front = D3DXVECTOR3(0.0f, 0.0f, 1.0f); m_right = D3DXVECTOR3(1.0f, 0.0f, 0.0f); m_offset = D3DXVECTOR3(0.0f, 0.0f, 0.0f); m_follow = follow; m_rotvel_on = rotvel_on; }
Sun::Sun(void) { m_bDrag = FALSE; m_pGameModel = new GameModel; m_pGameModel->Create("ui/arrow/model"); m_pGameModel->SelectDefaultPart(); m_pGameModel->SetGroupVisible(TRUE); m_pAnimInfo = new GameModel::AnimInfo; D3DXQuaternionIdentity( &m_qOld); D3DXQuaternionIdentity( &m_qNow ); D3DXMatrixIdentity(&m_mRotSnapshot); D3DXMatrixIdentity(&m_mRot); m_vOldVector = D3DXVECTOR3(0,0,0); m_vCurVector = D3DXVECTOR3(0,0,0); m_vDefDirection = m_vCurDirection = D3DXVECTOR3(-0.70710671f,-0.70710671f,0.00000000f); m_fRadius = 1.0f; }
GdsNode::GdsNode(): m_bBillboard( false ), m_vTranslate(0.0f, 0.0f, 0.0f), m_vWorldTranslate(0.0f, 0.0f, 0.0f), m_vScale( 1.0f, 1.0f, 1.0f) , m_bUseOctree( false ) , m_pOctreeRootNode( NULL ) , m_iLimitedCountOfFacePerNode( 300 ) , m_bCull( false ) , m_bShowBox( false ) , m_bShowAxis( false ) { m_ChildNode.clear(); m_pParentNode = NULL; // m_matWorld.MakeIdentity(); // m_matLocal.MakeIdentity(); D3DXMatrixIdentity( &m_matWorld ); D3DXMatrixIdentity( &m_matLocal ); D3DXQuaternionIdentity(&m_qWorldRotate); D3DXQuaternionIdentity(&m_qRotate); }
IObj::IObj(void) :m_vPos( 0.f, 0.f, 0.f ), m_vScale( 1.0f, 1.0f, 1.0f ), m_vRotation( 0.f, 0.f, 0.f ), m_fAniKey( 0.0f ), m_pResourceFile( NULL ), m_fMoveSpeed( 1.0f ), m_vDirection( 0.0f, 0.0f, 0.0f ) { D3DXQuaternionIdentity( &m_quatLookAt ); D3DXMatrixIdentity( &m_matLookAt ); D3DXMatrixIdentity( &m_matWorld ); }
DirectionalLight::DirectionalLight(void) { m_bDrag = FALSE; m_pGameModel = CGameModelManager::GetInstance()->CreateDisplayModel("ui/arrow/model",false); m_pGameModel->ShowAllGroup(false); //m_pGameModel->Create("ui/arrow/model"); //m_pGameModel->SelectDefaultPart(); //m_pGameModel->SetGroupVisible(TRUE); m_pAnimInfo = new AnimInfo; D3DXQuaternionIdentity( &m_qOld); D3DXQuaternionIdentity( &m_qNow ); D3DXMatrixIdentity(&m_mRotSnapshot); D3DXMatrixIdentity(&m_mRot); m_vOldVector = D3DXVECTOR3(0,0,0); m_vCurVector = D3DXVECTOR3(0,0,0); m_vDefDirection = m_vCurDirection = D3DXVECTOR3(-0.70710671f,-0.70710671f,0.0f); m_fRadius = 1.0f; }
SunLight::SunLight(void) { m_bDrag = FALSE; m_pGameModel = CGameModelManager::GetInstance()->CreateDisplayModel("ui/arrow/model"); m_pGameModel->ShowAllGroup(); m_pAnimInfo = new AnimInfo; ZeroMemory(m_pAnimInfo->GetActionInfo(),sizeof(AnimInfo::tagActionInfo)); m_pAnimInfo->SetAnimTime(GetCurTickCount()); m_pAnimInfo->GetActionInfo()->dwCurAction = MAKEFOURCC('S','T','N','D'); m_pAnimInfo->GetActionInfo()->dwCurActionStartTime = GetCurTickCount(); D3DXQuaternionIdentity( &m_qOld); D3DXQuaternionIdentity( &m_qNow ); D3DXMatrixIdentity(&m_mRotSnapshot); D3DXMatrixIdentity(&m_mRot); m_vOldVector = D3DXVECTOR3(0,0,0); m_vCurVector = D3DXVECTOR3(0,0,0); m_vDefDirection = D3DXVECTOR3(0.2f,-0.8f,-0.4f); m_vCurDirection = D3DXVECTOR3(0.2f,-0.8f,-0.4f); m_fRadius = 5.0f; }
GameObject::GameObject() : m_pModelRenderer(NULL) , m_pPMDModelRenderer(NULL) , m_name(_T("GameObject")) , m_pAnimation(NULL) { m_localPosition = D3DXVECTOR3(0.0f,0.0f,0.0f); D3DXQuaternionIdentity( &m_localRotation ); m_localScale = D3DXVECTOR3(1.0f,1.0f,1.0f); D3DXMATRIX matParent; D3DXMatrixIdentity( &matParent ); m_changedLocal = true; UpdateTransform( matParent ); }
D3DXMATRIX to_matrix(const MMatrix& mtx) { MTransformationMatrix trans_mtx(mtx); MVector translation = trans_mtx.getTranslation(MSpace::kPostTransform); double q_x, q_y, q_z, q_w; trans_mtx.getRotationQuaternion(q_x, q_y, q_z, q_w); double scale[3]; trans_mtx.getScale(scale, MSpace::kPostTransform); D3DXVECTOR3 d3d_pos((float)translation.x, (float)translation.y, (float)-translation.z); D3DXVECTOR3 d3d_scale((float)scale[0], (float)scale[1], (float)-scale[2]); D3DXQUATERNION d3d_rot((float)q_x, (float)q_y, (float)-q_z, (float)q_w); D3DXVECTOR3 kvtxZero(0,0,0); D3DXQUATERNION qtId; D3DXQuaternionIdentity(&qtId); D3DXMATRIX d3d_mtx; D3DXMatrixTransformation(&d3d_mtx, &kvtxZero, &qtId, &d3d_scale, &kvtxZero, &d3d_rot, &d3d_pos); return d3d_mtx; }
Camera::Camera(void) :m_up(0,1,0), m_translation(0,0,0), m_clipPlane(0, 0, 0, 0), m_fovy(0), m_aspectRatio(0), m_near(0), m_far(0), m_orthoSize(0), m_projectionType(PERSPECTIVE), m_viewCacheValid(false), m_projectionCacheValid(false), m_reflected(false) { D3DXQuaternionIdentity(&m_orientation); D3DXMatrixIdentity(&m_viewMatrix); D3DXMatrixIdentity(&m_projMatrix); D3DXMatrixIdentity(&m_reflMatrix); }
void CRigidBox::RenderDebug ( void ) { if ( !m_pDebugMesh ) return; D3DXQUATERNION qIdent; D3DXQuaternionIdentity( &qIdent ); // D3DXMatrixTransformation ( &m_mTransform, &D3DXVECTOR3(0.0f, 0.0f, 0.0f), &qIdent, // &D3DXVECTOR3(m_vSize.x, m_vSize.y, m_vSize.z), &D3DXVECTOR3(0.0f, 0.0f, 0.0f), // &m_qRotation, &D3DXVECTOR3(m_vPosition.x, m_vPosition.y, m_vPosition.z) ); D3DXMATRIX mTralsation; D3DXMatrixTranslation( &mTralsation, m_vPosition.x, m_vPosition.y, m_vPosition.z ); m_mTransform = m_mRotation * mTralsation; D3DFRAME->GetDevice()->SetTransform( D3DTS_WORLD, &m_mTransform ); D3DFRAME->GetDevice()->SetTransform( D3DTS_VIEW, &D3DFRAME->m_mView ); D3DFRAME->GetDevice()->SetTransform( D3DTS_PROJECTION, &D3DFRAME->m_mProj ); D3DFRAME->GetDevice()->SetRenderState( D3DRS_FILLMODE, D3DFILL_WIREFRAME ); D3DFRAME->GetDevice()->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE ); D3DFRAME->GetDevice()->SetRenderState( D3DRS_ALPHATESTENABLE, FALSE ); m_pDebugMesh->DrawSubset(0); D3DFRAME->GetDevice()->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE ); D3DFRAME->GetDevice()->SetRenderState( D3DRS_ALPHATESTENABLE, TRUE ); D3DFRAME->GetDevice()->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID ); }
OBB::OBB() { m_pMesh = NULL; m_pos = D3DXVECTOR3(0.0f, 0.0f, 0.0f); D3DXQuaternionIdentity(&m_rot); SetSize(D3DXVECTOR3(1.0f, 1.0f, 1.0f)); }
Scene * D3D::BuildScene(IDirect3DDevice9 *d3dDevice) { // Setup some materials - we'll use these for // making the same mesh appear in multiple // colors D3DMATERIAL9 colors[8]; D3DUtil_InitMaterial( colors[0], 1.0f, 1.0f, 1.0f, 1.0f ); // white D3DUtil_InitMaterial( colors[1], 0.0f, 1.0f, 1.0f, 1.0f ); // cyan D3DUtil_InitMaterial( colors[2], 1.0f, 0.0f, 0.0f, 1.0f ); // red D3DUtil_InitMaterial( colors[3], 0.0f, 1.0f, 0.0f, 1.0f ); // green D3DUtil_InitMaterial( colors[4], 0.0f, 0.0f, 1.0f, 1.0f ); // blue D3DUtil_InitMaterial( colors[5], 0.4f, 0.4f, 0.4f, 0.4f ); // 40% grey D3DUtil_InitMaterial( colors[6], 0.25f, 0.25f, 0.25f, 0.25f ); // 25% grey D3DUtil_InitMaterial( colors[7], 0.65f, 0.65f, 0.65f, 0.65f ); // 65% grey // The identity matrix is always useful D3DXMATRIX ident; D3DXMatrixIdentity(&ident); // We'll use these rotations for some teapots and grid objects D3DXMATRIX rotateX, rotateY, rotateZ; // Create the root, and the camera. // Remeber how to use smart pointers?? I hope so! boost::shared_ptr<TransformNode> root(new TransformNode(&ident)); boost::shared_ptr<CameraNode> camera(new CameraNode(&ident)); root->m_children.push_back(camera); // We'll put the camera in the scene at (20,20,20) looking back at the Origin D3DXMATRIX rotOnly, result, inverse; float cameraYaw = - (3.0f * D3DX_PI) / 4.0f; float cameraPitch = D3DX_PI / 4.0f; D3DXQUATERNION q; D3DXQuaternionIdentity(&q); D3DXQuaternionRotationYawPitchRoll(&q, cameraYaw, cameraPitch, 0.0); D3DXMatrixRotationQuaternion(&rotOnly, &q); D3DXMATRIX trans; D3DXMatrixTranslation(&trans, 15.0f, 15.0f, 15.0f); D3DXMatrixMultiply(&result, &rotOnly, &trans); D3DXMatrixInverse(&inverse, NULL, &result); camera->VSetTransform(&result, &inverse); D3DXMatrixRotationZ(&rotateZ, D3DX_PI / 2.0f); D3DXMatrixRotationX(&rotateX, -D3DX_PI / 2.0f); D3DXVECTOR3 target(30, 2, 15); // ID3DXMesh *teapot; if( SUCCEEDED( D3DXCreateTeapot( d3dDevice, &teapot, NULL ) ) ) { // Teapot #1 - a white one at (x=6,y=2,z=4) D3DXMatrixTranslation(&trans,6,2,4); boost::shared_ptr<SceneNode> mesh1(new MeshNode(teapot, &trans, colors[2])); root->m_children.push_back(mesh1); // Teapot #2 - a cyan one at (x=3,y=2,z=1) // with a D3DXMatrixTranslation(&trans, 3,2,1); D3DXMATRIX result; D3DXMatrixMultiply(&result, &rotateZ, &trans); boost::shared_ptr<SceneNode> mesh2(new MeshNode(teapot, &result, colors[1])); root->m_children.push_back(mesh2); // Teapot #3 - another white one at (x=30, y=2, z=15) D3DXMATRIX rotateY90; D3DXMatrixRotationY(&rotateY90, D3DX_PI / 2.0f); D3DXMatrixTranslation(&trans, target.x, target.y, target.z); D3DXMatrixMultiply(&result, &rotateY90, &trans); boost::shared_ptr<SceneNode> mesh3(new MeshNode(teapot, &result, colors[0])); root->m_children.push_back(mesh3); // We can release the teapot now, mesh1 and mesh2 AddRef'd it. SAFE_RELEASE(teapot); } ID3DXMesh *sphere; if ( SUCCEEDED( D3DXCreateSphere( d3dDevice, .25, 16, 16, &sphere, NULL) ) ) { // We're going to create a spiral of spheres... // starting at (x=3, y=0, z=3), and spiraling // upward about a local Y axis. D3DXMatrixTranslation(&trans, 3,0,3); boost::shared_ptr<SceneNode> sphere1(new MeshNode(sphere, &trans, colors[4]) ); root->m_children.push_back(sphere1); // Here's the local rotation and translation. // We'll rotate about Y, and then translate // up (along Y) and forward (along Z). D3DXMatrixRotationY(&rotateY, D3DX_PI / 8.0f); D3DXMATRIX trans2; D3DXMatrixTranslation(&trans2, 0, 0.5, 0.5); D3DXMatrixMultiply(&result, &trans2, &rotateY); for (int i=0; i<25; i++) { // If you didn't think smart pointers were cool - // watch this! No leaked memory.... // Notice this is a heirarchy.... boost::shared_ptr<SceneNode> sphere2(new MeshNode(sphere, &result, colors[i%5]) ); sphere1->m_children.push_back(sphere2); sphere1 = sphere2; } // We can release the sphere now, all the cylinders AddRef'd it. SAFE_RELEASE(sphere); } // D3DXMatrixTranslation(&trans,-25,20,20); //D3DXMatrixScaling(&trans, -10, -10, -10); ScaleMtrl scale; scale.x = -50.0f; scale.y = -50.0f; scale.z = -50.0f; boost::shared_ptr<SceneNode> xmesh1(new XMeshNode(L"gf3.x", d3dDevice, &trans, &scale)); root->m_children.push_back(xmesh1); root->m_children.push_back(xmesh1); /*D3DXMatrixTranslation(&trans,-45,20,20); boost::shared_ptr<SceneNode> xmesh11(new XMeshNode(L"gf3.x", d3dDevice, &trans, &scale)); root->m_children.push_back(xmesh11);*/ XMeshNode *mm = new XMeshNode(L"gow_m1.x", d3dDevice, &trans, &scale); D3DXMatrixTranslation(&trans,10,10,10); //D3DXMatrixScaling(&trans, -10, -10, -10); //ScaleMtrl scale; scale.x = 100.0f; scale.y = 100.0f; scale.z = 100.0f; boost::shared_ptr<SceneNode> xmesh2( new XMeshNode(L"gow_m1.x", d3dDevice, &trans, &scale)); root->m_children.push_back(xmesh2); /*D3DXMatrixTranslation(&trans,20,20,20); boost::shared_ptr<SceneNode> xmesh3(new XMeshNode(mm->m_mesh, mm->Mtrls, mm->Textures, &trans, 0)); root->m_children.push_back(xmesh3);*/ int col = 10; int row= 10; int zoom = 10; const int COUNT = 13; for(int i = 0; i < COUNT; i++) { for (int j = 0; j< COUNT; j++) { for(int z = 0; z< COUNT; z++) { D3DXMatrixTranslation(&trans, col + i, row + j , zoom + z); boost::shared_ptr<SceneNode> xmeshNew(new XMeshNode(mm->m_mesh, mm->Mtrls, mm->Textures, &trans, 0)); root->m_children.push_back(xmeshNew); } } } //D3DXMatrixScaling(&trans, 10, 10, 10); // Here are the grids...they make it easy for us to // see where the coordinates are in 3D space. boost::shared_ptr<SceneNode> grid1(new Grid(40, 0x00404040, L"Textures\\grid.dds", &ident)); root->m_children.push_back(grid1); boost::shared_ptr<SceneNode> grid2(new Grid(40, 0x00004000, L"Textures\\grid.dds", &rotateX)); root->m_children.push_back(grid2); boost::shared_ptr<SceneNode> grid3(new Grid(40, 0x00000040, L"Textures\\grid.dds", &rotateZ)); root->m_children.push_back(grid3); // Here's the sky node that never worked!!!! boost::shared_ptr<SkyNode> sky(new SkyNode(_T("Sky2"), camera)); root->m_children.push_back(sky); D3DXMatrixTranslation(&trans,15,2,15); D3DXMatrixRotationY(&rotateY, D3DX_PI / 4.0f); D3DXMatrixMultiply(&result, &rotateY, &trans); boost::shared_ptr<SceneNode> arrow1(new ArrowNode(2, &result, colors[0], d3dDevice)); root->m_children.push_back(arrow1); D3DXMatrixRotationY(&rotateY, D3DX_PI / 2.0f); D3DXMatrixMultiply(&result, &rotateY, &trans); boost::shared_ptr<SceneNode> arrow2(new ArrowNode(2, &result, colors[5], d3dDevice)); root->m_children.push_back(arrow2); D3DXMatrixMultiply(&result, &rotateX, &trans); boost::shared_ptr<SceneNode> arrow3(new ArrowNode(2, &result, colors[0], d3dDevice)); root->m_children.push_back(arrow3); // Everything has been attached to the root. Now // we attach the root to the scene. Scene *scene = new Scene(d3dDevice, root); scene->Restore(); // A movement controller is going to control the camera, // but it could be constructed with any of the objects you see in this // function. You can have your very own remote controlled sphere. What fun... boost::shared_ptr<MovementController> m_pMovementController(new MovementController(camera, cameraYaw, cameraPitch)); scene->m_pMovementController = m_pMovementController; return scene; }
void RagDoll::InitRagdoll() { Release(); InitBones((Bone*)m_pRootBone); Bone* Head_End = (Bone*)D3DXFrameFind(m_pRootBone, "Head_End"); Bone* Head = (Bone*)D3DXFrameFind(m_pRootBone, "Head"); Bone* Neck = (Bone*)D3DXFrameFind(m_pRootBone, "Neck"); Bone* Pelvis = (Bone*)D3DXFrameFind(m_pRootBone, "Pelvis"); Bone* Spine = (Bone*)D3DXFrameFind(m_pRootBone, "Spine"); Bone* R_Shoulder = (Bone*)D3DXFrameFind(m_pRootBone, "Shoulder_Right"); Bone* L_Shoulder = (Bone*)D3DXFrameFind(m_pRootBone, "Shoulder_Left"); Bone* U_R_Arm = (Bone*)D3DXFrameFind(m_pRootBone, "Upper_Arm_Right"); Bone* U_L_Arm = (Bone*)D3DXFrameFind(m_pRootBone, "Upper_Arm_Left"); Bone* L_R_Arm = (Bone*)D3DXFrameFind(m_pRootBone, "Lower_Arm_Right"); Bone* L_L_Arm = (Bone*)D3DXFrameFind(m_pRootBone, "Lower_Arm_Left"); Bone* R_Hand = (Bone*)D3DXFrameFind(m_pRootBone, "Hand_Right"); Bone* L_Hand = (Bone*)D3DXFrameFind(m_pRootBone, "Hand_Left"); Bone* R_Pelvis = (Bone*)D3DXFrameFind(m_pRootBone, "Pelvis_Right"); Bone* L_Pelvis = (Bone*)D3DXFrameFind(m_pRootBone, "Pelvis_Left"); Bone* R_Thigh = (Bone*)D3DXFrameFind(m_pRootBone, "Thigh_Right"); Bone* L_Thigh = (Bone*)D3DXFrameFind(m_pRootBone, "Thigh_Left"); Bone* R_Calf = (Bone*)D3DXFrameFind(m_pRootBone, "Calf_Right"); Bone* L_Calf = (Bone*)D3DXFrameFind(m_pRootBone, "Calf_Left"); Bone* R_Foot = (Bone*)D3DXFrameFind(m_pRootBone, "Foot_Right"); Bone* L_Foot = (Bone*)D3DXFrameFind(m_pRootBone, "Foot_Left"); Bone* R_Foot_End = (Bone*)D3DXFrameFind(m_pRootBone, "Foot_Right_End"); Bone* L_Foot_End = (Bone*)D3DXFrameFind(m_pRootBone, "Foot_Left_End"); D3DXQUATERNION q, q2; D3DXQuaternionIdentity(&q); D3DXQuaternionRotationAxis(&q2, &D3DXVECTOR3(0.0f, 0.0f, 1.0f), D3DX_PI * -0.5f); //Head OBB* o01 = CreateBoneBox(Head, Head_End, D3DXVECTOR3(0.3f, 0.2f, 0.2f), q); //Right Arm OBB* o03 = CreateBoneBox(U_R_Arm, L_R_Arm, D3DXVECTOR3(0.3f, 0.12f, 0.12f), q); OBB* o04 = CreateBoneBox(L_R_Arm, R_Hand, D3DXVECTOR3(0.3f, 0.12f, 0.12f), q); //Left Arm OBB* o06 = CreateBoneBox(U_L_Arm, L_L_Arm, D3DXVECTOR3(0.3f, 0.12f, 0.12f), q); OBB* o07 = CreateBoneBox(L_L_Arm, L_Hand, D3DXVECTOR3(0.3f, 0.12f, 0.12f), q); //Spine OBB* o08 = CreateBoneBox(Spine, Neck, D3DXVECTOR3(0.5f, 0.35f, 0.15f), q); //Right Leg OBB* o09 = CreateBoneBox(R_Thigh, R_Calf, D3DXVECTOR3(0.4f, 0.15f, 0.15f), q); OBB* o10 = CreateBoneBox(R_Calf, R_Foot, D3DXVECTOR3(0.4f, 0.14f, 0.14f), q); OBB* o11 = CreateBoneBox(R_Foot, R_Foot_End, D3DXVECTOR3(0.15f, 0.06f, 0.12f), q2); //Left Leg OBB* o12 = CreateBoneBox(L_Thigh, L_Calf, D3DXVECTOR3(0.4f, 0.15f, 0.15f), q); OBB* o13 = CreateBoneBox(L_Calf, L_Foot, D3DXVECTOR3(0.4f, 0.14f, 0.14f), q); OBB* o14 = CreateBoneBox(L_Foot, L_Foot_End, D3DXVECTOR3(0.15f, 0.06f, 0.12f), q2); //Constraints CreateTwistCone(Neck, o01, o08, D3DX_PI * 0.15f, D3DXVECTOR3(0.0f, 0.0f, D3DX_PI * 0.5f), D3DXVECTOR3(0.0f, 0.0f, D3DX_PI * 0.5f)); CreateTwistCone(L_Pelvis, o08, o12, D3DX_PI * 0.5f, D3DXVECTOR3(0.3f, D3DX_PI * 0.5f, -D3DX_PI * 0.5f), D3DXVECTOR3(0.0f, 0.0f, D3DX_PI * 0.5f)); CreateHinge(L_Calf, o12, o13, 0.0f, -2.0f, D3DXVECTOR3(0.0f, 0.0f, D3DX_PI * 0.5f), D3DXVECTOR3(0.0f, 0.0f, D3DX_PI * 0.5f)); CreateHinge(L_Foot, o13, o14, 1.5f, 1.0f, D3DXVECTOR3(0.0f, 0.0f, D3DX_PI * 0.5f), D3DXVECTOR3(0.0f, 0.0f, D3DX_PI * 0.5f)); CreateTwistCone(R_Pelvis, o08, o09, D3DX_PI * 0.5f, D3DXVECTOR3(0.3f, D3DX_PI * 0.5f, -D3DX_PI * 0.5f), D3DXVECTOR3(0.0f, 0.0f, D3DX_PI * 0.5f)); CreateHinge(R_Calf, o09, o10, 0.0f, -2.0f, D3DXVECTOR3(0.0f, 0.0f, D3DX_PI * 0.5f), D3DXVECTOR3(0.0f, 0.0f, D3DX_PI * 0.5f)); CreateHinge(R_Foot, o10, o11, 1.5f, 1.0f, D3DXVECTOR3(0.0f, 0.0f, D3DX_PI * 0.5f), D3DXVECTOR3(0.0f, 0.0f, D3DX_PI * 0.5f)); CreateTwistCone(U_L_Arm, o08, o06, D3DX_PI * 0.6f, D3DXVECTOR3(0.0f, D3DX_PI * 0.75f, D3DX_PI * 0.0f), D3DXVECTOR3(0.0f, 0.0f, 0.0f)); CreateHinge(L_L_Arm, o06, o07, 2.0f, 0.0f, D3DXVECTOR3(0.0f, 0.0f, D3DX_PI * 0.5f), D3DXVECTOR3(0.0f, 0.0f, D3DX_PI * 0.5f)); CreateTwistCone(U_R_Arm, o08, o03, D3DX_PI * 0.6f, D3DXVECTOR3(0.0f, D3DX_PI * 0.75f, D3DX_PI * 0.0f), D3DXVECTOR3(D3DX_PI, 0.0f, 0.0f)); CreateHinge(L_R_Arm, o03, o04, 2.0f, 0.0f, D3DXVECTOR3(0.0f, 0.0f, -D3DX_PI * 0.5f), D3DXVECTOR3(0.0f, 0.0f, -D3DX_PI * 0.5f)); //Assign Pelvis bone to Spine OBB Pelvis->m_pObb = o08; D3DXVECTOR3 PelvisPos(Pelvis->CombinedTransformationMatrix(3, 0), Pelvis->CombinedTransformationMatrix(3, 1), Pelvis->CombinedTransformationMatrix(3, 2)); Pelvis->m_pivot = o08->SetPivot(PelvisPos); }
void resetToIdentity() { t[0] = 0.0f; t[1] = 0.0f; t[2] = 0.0f; D3DXQuaternionIdentity(rotation()); s[0] = 1.0f; s[1] = 1.0f; s[2] = 1.0f; }
void OmniMapD3D::SetupAllShaderVaribles() { int N_Channels; int TextureIds[OMNIMAP_maxChannelFaces]; D3DXMATRIX textureMats[OMNIMAP_maxChannelFaces]; GetShaderVariables(N_Channels, TextureIds); ((OmniMapShaderD3D *) shaders)->SetTextureIds(N_Channels); for (int i = 0; i < N_Channels; i++) { OmniMapChannelBase *channel = this->GetChannel(i); D3DXQUATERNION tmpQuat; D3DXMATRIX *pTextureMat = &textureMats[i]; D3DXMATRIX tmpMat; D3DXMatrixIdentity(pTextureMat); const D3DXVECTOR3 zeroVec(0.0,0.0,0.0); const D3DXVECTOR3 transVec(.5,.5,.5); D3DXMatrixAffineTransformation(pTextureMat, .5, &zeroVec, D3DXQuaternionIdentity(&tmpQuat), &transVec); D3DXMATRIX channelProj; ((OmniMapChannelD3D *) channel)->GetProjectionMatrixRH(&channelProj); D3DXMatrixMultiply(pTextureMat, &channelProj, pTextureMat); D3DXMATRIX viewMatrix; ((OmniMapChannelD3D *) channel)->GetViewMatrix2(&viewMatrix); D3DXMatrixMultiply(pTextureMat, &viewMatrix, pTextureMat); } ((OmniMapShaderD3D *) shaders)->SetTextureMatrices(textureMats, N_Channels); D3DVIEWPORT9 vp; d3dDevice->GetViewport(&vp); float yOffset1, yOffset2, yScale; if (((glViewportsettings0 + glViewportsettings2) <= vp.Width) && (glViewportsettings0 >= 0) && ((glViewportsettings1 + glViewportsettings3) <= vp.Height) && (glViewportsettings1 >= 0)) { //if image circle is inside of the viewport, use opengl approach vp.X = (DWORD) glViewportsettings0; vp.Y = (DWORD) glViewportsettings1; vp.Width = (DWORD) glViewportsettings2; vp.Height = (DWORD) glViewportsettings3; d3dDevice->SetViewport(&vp); yOffset1 = 0.0; yOffset2 = 0.0; yScale = 1.0; } else { // FIX FOR DX11 VIEWPORT if image circle is outside of the viewport if (glViewportsettings2 <1.0f) glViewportsettings2 = (float)vp.Width; // UNTESTED if(glViewportsettings3<1.0f) glViewportsettings3 = (float) vp.Height; // UNTESTED float HeightImageCircle = glViewportsettings3; // back out the offset from the lua... this float offsetSuggestedByLua = (glViewportsettings1 - .5f* vp.Height + .5f* vp.Width)/vp.Width; float aspect = vp.Width/(float)vp.Height; float offsetByDX11 =offsetSuggestedByLua*2.0f*aspect; yScale = HeightImageCircle /((float)vp.Height); yOffset1 = 0; yOffset2 = offsetByDX11; } if (yOffset1 != 0.0) yOffset2 = 0.0; ((OmniMapShaderD3D *) shaders)->omnimapFX->SetFloat( "yScale", yScale); ((OmniMapShaderD3D *) shaders)->omnimapFX->SetFloat( "yOffset1", yOffset1); ((OmniMapShaderD3D *) shaders)->omnimapFX->SetFloat( "yOffset2", yOffset2); ((OmniMapShaderD3D *) shaders)->omnimapFX->SetMatrix( "g_mProjection", &worldViewProjection ); ((OmniMapShaderD3D *) shaders)->omnimapFX->SetMatrix( "g_mWorldView", &worldView ); if(StencilMask_filename) ((OmniMapShaderD3D *) shaders)->StencilMask_Bind(6);//+1 }