XMVECTOR BoidManager::vMult(XMVECTOR a, XMVECTOR b) { float x, y, z; if (XMVectorGetX(b) == -1.0f) { x = (XMVectorGetX(a) * XMVectorGetX(b)); } else { x = XMVectorGetX(a); } if (XMVectorGetY(b) == -1.0f) { y = (XMVectorGetY(a) * XMVectorGetY(b)); } else { y = XMVectorGetY(a); } if (XMVectorGetZ(b) == -1.0f) { z = (XMVectorGetZ(a) * XMVectorGetZ(b)); } else { z = XMVectorGetZ(a); } XMVECTOR mult = XMVectorSet(x, y, z, 0.0f); return mult; }
void GetBoundCornersFromPoints(const XMFLOAT3* points, uint32 numPoints, uint32 stride, XMVECTOR &minx, XMVECTOR &maxx, XMVECTOR &miny, XMVECTOR &maxy, XMVECTOR &minz, XMVECTOR &maxz) { Assert_(numPoints > 0); Assert_(points); minx = maxx = miny = maxy = minz = maxz = XMLoadFloat3(points); for (uint32 i = 1; i < numPoints; i++) { XMVECTOR Point = XMLoadFloat3((XMFLOAT3*)((BYTE*)points + i * stride)); float px = XMVectorGetX(Point); float py = XMVectorGetY(Point); float pz = XMVectorGetZ(Point); if (px < XMVectorGetX(minx)) minx = Point; if (px > XMVectorGetX(maxx)) maxx = Point; if (py < XMVectorGetY(miny)) miny = Point; if (py > XMVectorGetY(maxy)) maxy = Point; if (pz < XMVectorGetZ(minz)) minz = Point; if (pz > XMVectorGetZ(maxz)) maxz = Point; } }
void FirstPersonCamera::Update(const GameTime& gameTime) { XMFLOAT2 movementAmount = Vector2Helper::Zero; if (mKeyboard != nullptr) { if (mKeyboard->IsKeyDown(DIK_W)) { movementAmount.y = 1.0f; } if (mKeyboard->IsKeyDown(DIK_S)) { movementAmount.y = -1.0f; } if (mKeyboard->IsKeyDown(DIK_A)) { movementAmount.x = -1.0f; } if (mKeyboard->IsKeyDown(DIK_D)) { movementAmount.x = 1.0f; } } XMFLOAT2 rotationAmount = Vector2Helper::Zero; if ((mMouse != nullptr) && (mMouse->IsButtonHeldDown(MouseButtons::Left))) { LPDIMOUSESTATE mouseState = mMouse->CurrentState(); rotationAmount.x = -mouseState->lX * mMouseSensitivity; rotationAmount.y = -mouseState->lY * mMouseSensitivity; } float elapsedTime = (float)gameTime.ElapsedGameTime(); XMVECTOR rotationVector = XMLoadFloat2(&rotationAmount) * mRotationRate * elapsedTime; XMVECTOR right = XMLoadFloat3(&mRight); XMMATRIX pitchMatrix = XMMatrixRotationAxis(right, XMVectorGetY(rotationVector)); XMMATRIX yawMatrix = XMMatrixRotationY(XMVectorGetX(rotationVector)); ApplyRotation(XMMatrixMultiply(pitchMatrix, yawMatrix)); XMVECTOR position = XMLoadFloat3(&mPosition); XMVECTOR movement = XMLoadFloat2(&movementAmount) * mMovementRate * elapsedTime; XMVECTOR strafe = right * XMVectorGetX(movement); position += strafe; XMVECTOR forward = XMLoadFloat3(&mDirection) * XMVectorGetY(movement); position += forward; XMStoreFloat3(&mPosition, position); Camera::Update(gameTime); }
void BoneModel::createBone(){ auto& bones = mBoneAssetDataPtr->GetFileData().GetBoneData().mBoneBuffer; auto& boneName = mBoneAssetDataPtr->GetFileData().GetBoneData().mBoneName; DWORD mBoneNum = bones.size(); mBone.clear(); mIk.clear(); mBone.resize(mBoneNum); DWORD ikCount = 0; for (DWORD i = 0; i < mBoneNum; i++){ auto& bone = bones[i]; mBone[i].mStrName = boneName[i]; mBone[i].mHierarchy.mIdxSelf = i; mBone[i].mHierarchy.mIdxParent = bone.parent_bidx; if (bone.parent_bidx >= (int)mBoneNum) mBone[i].mHierarchy.mIdxParent = UINT(-1); XMVECTOR head_pos = XMVectorSet(bone.bone_head_pos[0], bone.bone_head_pos[1], bone.bone_head_pos[2], 0.0f); XMVECTOR parent_pos = { 0, 0, 0, 1 }; if (mBone[i].mHierarchy.mIdxParent < (int)mBoneNum){ UINT p = mBone[i].mHierarchy.mIdxParent; parent_pos = XMVectorSet(bones[p].bone_head_pos[0], bones[p].bone_head_pos[1], bones[p].bone_head_pos[2], 0.0f); } XMVECTOR local_pos = XMVectorSubtract(head_pos, parent_pos); mBone[i].mPos = XMFLOAT3(XMVectorGetX(local_pos), XMVectorGetY(local_pos), XMVectorGetZ(local_pos)); mBone[i].mScale = XMFLOAT3(1.0f, 1.0f, 1.0f); XMVECTOR q = XMQuaternionIdentity(); mBone[i].mRot = XMFLOAT4(XMVectorGetX(q), XMVectorGetY(q), XMVectorGetZ(q), XMVectorGetW(q)); //ワールド行列計算 XMVECTOR scale = { 1, 1, 1, 1 }; mBone[i].mMtxPose = SRTMatrix(scale, q, local_pos); if (mBone[i].mHierarchy.mIdxParent < (int)mBoneNum){ mBone[i].mMtxPose = XMMatrixMultiply(mBone[i].mMtxPose, mBone[mBone[i].mHierarchy.mIdxParent].mMtxPose); } if (bone.bone_flag & pmx::t_bone::BIT_IK){ mBone[i].mIkBoneIdx = (WORD)bone.t_ik_data_idx; createIk(ikCount, i); ikCount++; } else{ mBone[i].mIkBoneIdx = 0; } mBone[i].mMtxPoseInit = mBone[i].mMtxPose; } }
inline BOOL checkCamInOctree(const Engine::Octree *octree, const Engine::PerspCamera *cam) { const XMVECTOR p = cam->getCameraPosition(); if (XMVectorGetX(p) >= octree->vertex[0].x && XMVectorGetX(p) < octree->vertex[7].x && XMVectorGetY(p) >= octree->vertex[0].y && XMVectorGetY(p) < octree->vertex[7].y && XMVectorGetZ(p) >= octree->vertex[0].z && XMVectorGetZ(p) < octree->vertex[7].z) return TRUE; return FALSE; }
//-------------------------------------------------------------------------------------- // Name: Update() // Desc: Adds a new frame of positions, updates the coordiante system, and calculates // left and right hand. //-------------------------------------------------------------------------------------- VOID SpineRelativeCameraSpaceCoordinateSystem::Update( const NUI_SKELETON_FRAME* pRawSkeletonFrame, INT iSkeletonIndex, XMVECTOR vLeft, XMVECTOR vRight ) { if ( pRawSkeletonFrame == NULL ) return; if ( iSkeletonIndex < 0 || iSkeletonIndex >= NUI_SKELETON_COUNT ) return; CONST XMVECTOR *pSkeletonPosition = &pRawSkeletonFrame->SkeletonData[iSkeletonIndex].SkeletonPositions[0]; if ( m_dwLastTrackingID != pRawSkeletonFrame->SkeletonData[iSkeletonIndex].dwTrackingID ) { m_vAverageNormalToGravity = pRawSkeletonFrame->vNormalToGravity; } else { m_vAverageNormalToGravity = m_fSpineUpdateRate * m_vAverageNormalToGravity + pRawSkeletonFrame->vNormalToGravity * ( 1.0f - m_fSpineUpdateRate ); } #if 0 CHAR out[255]; sprintf_s( out, "x=%f,y=%f,z=%f,w=%f\n", pRawSkeletonFrame->vNormalToGravity.x, pRawSkeletonFrame->vNormalToGravity.y, pRawSkeletonFrame->vNormalToGravity.z, pRawSkeletonFrame->vNormalToGravity.w ); OutputDebugString( out ); #endif m_matRotateToNormalToGravity = NuiTransformMatrixLevel( m_vAverageNormalToGravity ); XMVECTOR vSpineTilted = XMVector3Transform( pSkeletonPosition[NUI_SKELETON_POSITION_SPINE], m_matRotateToNormalToGravity ); XMVECTOR vHeadTilted = XMVector3Transform( pSkeletonPosition[NUI_SKELETON_POSITION_HEAD], m_matRotateToNormalToGravity ); m_vLeftHandRelative = XMVector3Transform( vLeft, m_matRotateToNormalToGravity ); m_vRightHandRelative = XMVector3Transform( vRight, m_matRotateToNormalToGravity ); FLOAT fSpineHeadLength = XMVectorGetY( vHeadTilted ) - XMVectorGetY( vSpineTilted ); if ( m_dwLastTrackingID != pRawSkeletonFrame->SkeletonData[iSkeletonIndex].dwTrackingID ) { m_dwLastTrackingID = pRawSkeletonFrame->SkeletonData[iSkeletonIndex].dwTrackingID; m_vAverageSpine = vSpineTilted; m_fAverageSpineHeadLength = fSpineHeadLength; } else { m_vAverageSpine = m_vAverageSpine * m_fSpineUpdateRate + vSpineTilted * ( 1.0f - m_fSpineUpdateRate ); m_fAverageSpineHeadLength = ATG::Lerp( fSpineHeadLength, m_fAverageSpineHeadLength, m_fBodySizeUpdateRate ); } m_vEstiamtedPivotOffsetLeft = XMVectorSet( m_fAverageSpineHeadLength * 0.3f, m_fAverageSpineHeadLength * 0.1f, 0.0f, 0.0f ); m_vEstiamtedPivotOffsetRight = XMVectorSet( -m_fAverageSpineHeadLength * 0.3f, m_fAverageSpineHeadLength * 0.1f, 0.0f, 0.0f ); m_vRightHandRelative -= m_vAverageSpine; m_vRightHandRelative += m_vEstiamtedPivotOffsetRight; m_vLeftHandRelative -= m_vAverageSpine; m_vLeftHandRelative += m_vEstiamtedPivotOffsetLeft; static XMVECTOR vFlipZ = XMVectorSet( 1.0f, 1.0f, -1.0f, 1.0f ); m_vRightHandRelative *= vFlipZ; m_vLeftHandRelative *= vFlipZ; }
bool SceneNode::check_collision(SceneNode* compare_tree, SceneNode* object_tree_root) { // check to see if root of tree being compared is same as root node of object tree being checked // i.e. stop object node and children being checked against each other if (object_tree_root == compare_tree) return false; // only check for collisions if both nodes contain a model if (m_p_model && compare_tree->m_p_model) { XMVECTOR v1 = get_world_centre_position(); XMVECTOR v2 = compare_tree->get_world_centre_position(); XMVECTOR vdiff = v1 - v2; //XMVECTOR a = XMVector3Length(vdiff); float x1 = XMVectorGetX(v1); float x2 = XMVectorGetX(v2); float y1 = XMVectorGetY(v1); float y2 = XMVectorGetY(v2); float z1 = XMVectorGetZ(v1); float z2 = XMVectorGetZ(v2); float dx = x1 - x2; float dy = y1 - y2; float dz = z1 - z2; // check bounding sphere collision if (sqrt(dx*dx + dy*dy + dz*dz) < (compare_tree->m_p_model->GetBoundingSphereRadius() * compare_tree->m_world_scale) + (this->m_p_model->GetBoundingSphereRadius() * m_world_scale)) { return true; } } // iterate through compared tree child nodes for (int i = 0; i< compare_tree->m_children.size(); i++) { // check for collsion against all compared tree child nodes if (check_collision(compare_tree->m_children[i], object_tree_root) == true) return true; } // iterate through composite object child nodes for (int i = 0; i< m_children.size(); i++) { // check all the child nodes of the composite object against compared tree if (m_children[i]->check_collision(compare_tree, object_tree_root) == true) return true; } return false; }
//--------------------------------------------------------------------- Frustum::LocateSide Frustum::testContainState(FXMVECTOR plane, const Util::AABBPtr & aabb) { Util::real dist = XMVectorGetX(XMPlaneDotCoord(plane, aabb->getCenterPoint())); XMVECTOR halfSize = aabb->getHalfSize(); Util::real maxAbsDist = abs(XMVectorGetX(plane) * XMVectorGetX(halfSize)) + abs(XMVectorGetY(plane) * XMVectorGetY(halfSize)) + abs(XMVectorGetZ(plane) * XMVectorGetZ(halfSize)); if (dist < -maxAbsDist) return LS_NEGATIVE; if (dist > + maxAbsDist) return LS_POSITIVE; return LS_INTERSECT; }
void CFVec4::SetXY( CFVec2Arg fv2Source ) { const XMVECTOR& v2V = *reinterpret_cast<const XMVECTOR*>( &fv2Source ); XMVECTOR& v4V = *reinterpret_cast<XMVECTOR*>(this); v4V = XMVectorSetX( v4V, XMVectorGetX( v2V ) ); v4V = XMVectorSetY( v4V, XMVectorGetY( v2V ) ); }
void Game::UpdateScene() { floorWorld = XMMatrixIdentity(); scale = XMMatrixScaling(250.0f, 1.0f, 250.0f); translation = XMMatrixTranslation(0.0f, 0.0f, 0.0f); floorWorld = scale*translation; //Keep the cubes rotating rotSpeed += .0005f; if (rotSpeed > 6.26f) rotSpeed = 0.0f; //When used, these matrices will rotate objects rotateAboutX = XMMatrixRotationAxis(rotXAxis, -rotSpeed); rotateAboutY = XMMatrixRotationAxis(rotYAxis, -rotSpeed); rotateAboutZ = XMMatrixRotationAxis(rotZAxis, -rotSpeed); scale = XMMatrixScaling(2, scaleY, 2); //Reset cubes locations cube1World = XMMatrixIdentity(); cube2World = XMMatrixIdentity(); //When used, these matrices will set an objects position translation = XMMatrixTranslation(-5.0f, 2.0f, 0.0f); //Set cube1's world space using the transformations cube1World = rotateAboutX * translation * scale; //When used, these matrices will set an objects position translation = XMMatrixTranslation(5.0f, 2.0f, 0.0f); //Set cube2's world space matrix cube2World = rotateAboutY * translation * scale; meshWorld = XMMatrixIdentity(); travelSpeed += 0.0003f; //Setting meshes scale, translation and rotation scale = XMMatrixScaling(0.2f,0.2f,0.2f); translation = XMMatrixTranslation(-travelSpeed, 0.0f, 0.0f); rotation = XMMatrixRotationRollPitchYaw(0, XMConvertToRadians(180), 0); meshWorld = translation * rotation * scale; //Reset sphereWorld sphereWorld = XMMatrixIdentity(); //Define sphereWorld's world space matrix scale = XMMatrixScaling(5.0f, 5.0f, 5.0f); //Make sure the sphere is always centered around camera translation = XMMatrixTranslation(XMVectorGetX(camPosition), XMVectorGetY(camPosition), XMVectorGetZ(camPosition)); //Set sphereWorld's world space using the transformations sphereWorld = scale * translation; }
//ALEX OWEN - 26/01/15 - set the position with a vector void GameObject::setPositionVec(FXMVECTOR _position) { position.x = XMVectorGetX(_position); position.y = XMVectorGetY(_position); position.z = XMVectorGetZ(_position); updated = true; transformed = true; }
XMFLOAT3 CineCameraClass::StrafeRight() { wchar_t* outstring = L"CineCameraClass::Strafe Right\n"; WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), outstring, wcslen(outstring), NULL, NULL); XMVECTOR sideWaysVector = XMVector3Normalize(XMVector3Cross(XMLoadFloat3(&upDirection), XMLoadFloat3(&direction) )); return XMFLOAT3(XMVectorGetX(sideWaysVector) * STRAFE_SPEED, XMVectorGetY(sideWaysVector) * STRAFE_SPEED, XMVectorGetZ(sideWaysVector) * STRAFE_SPEED); }
void CFVec4::SetXYZ( CFVec3Arg fv3Source ) { const XMVECTOR& v3V = *reinterpret_cast<const XMVECTOR*>( &fv3Source ); XMVECTOR& v4V = *reinterpret_cast<XMVECTOR*>(this); v4V = XMVectorSetX( v4V, XMVectorGetX( v3V ) ); v4V = XMVectorSetY( v4V, XMVectorGetY( v3V ) ); v4V = XMVectorSetZ( v4V, XMVectorGetZ( v3V ) ); }
//ALEX OWEN - 26/01/15 - set the position with a vector void GameObject::setRotationVec(FXMVECTOR _rotation) { rotation.x = XMVectorGetX(_rotation); rotation.y = XMVectorGetY(_rotation); rotation.z = XMVectorGetZ(_rotation); updated = true; transformed = true; }
float ObjectToCamera(XMFLOAT4X4* _objMatrix, XMFLOAT3 _cameraPos) { XMVECTOR obj = XMVectorZero(); obj = XMVector3Transform(obj, XMLoadFloat4x4(_objMatrix)); float ObjtoCameraX = XMVectorGetX(obj) - _cameraPos.x; float ObjtoCameraY = XMVectorGetY(obj) - _cameraPos.y; float ObjtoCameraZ = XMVectorGetZ(obj) - _cameraPos.z; return ObjtoCameraX*ObjtoCameraX + ObjtoCameraY*ObjtoCameraY + ObjtoCameraZ*ObjtoCameraZ; }
void CGUIShaderDX::Project(float &x, float &y, float &z) { XMVECTOR vLocation = { x, y, z }; XMVECTOR vScreenCoord = XMVector3Project(vLocation, m_cbViewPort.TopLeftX, m_cbViewPort.TopLeftY, m_cbViewPort.Width, m_cbViewPort.Height, 0, 1, m_cbWorldViewProj.projection, m_cbWorldViewProj.view, m_cbWorldViewProj.world); x = XMVectorGetX(vScreenCoord); y = XMVectorGetY(vScreenCoord); z = 0; }
XMVECTOR GetAngle(XMVECTOR quat) { XMMATRIX mtx = XMMatrixRotationQuaternion(quat); //ZYX Y=-90〜90°Y軸=ねじり方向 float rx = -atan2f(XMVectorGetY(mtx.r[2]), XMVectorGetZ(mtx.r[2])); float ry = asinf(XMVectorGetX(mtx.r[2])); float rz = -atan2f(XMVectorGetX(mtx.r[1]), XMVectorGetX(mtx.r[0])); return XMVectorSet(rx, ry, rz, 0); }
XMFLOAT3 CineCameraClass::MoveBackward() { wchar_t* outstring = L"CineCameraClass::Move Backward\n"; WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), outstring, wcslen(outstring), NULL, NULL); XMVECTOR sideWaysVector = XMVector3Normalize(XMVector3Cross(XMLoadFloat3(&upDirection), XMLoadFloat3(&direction) )); XMVECTOR forwardVector = XMVector3Normalize(XMVector3Cross(XMLoadFloat3(&trueUpDirection), sideWaysVector )); return XMFLOAT3(XMVectorGetX(forwardVector) * ADVANCE_SPEED, XMVectorGetY(forwardVector) * ADVANCE_SPEED, XMVectorGetZ(forwardVector) * ADVANCE_SPEED); }
void D3DCamera::RebuildView() { // Keep camera's axes orthogonal to each other and of unit length. m_LookAt = XMVector3Normalize(m_LookAt); m_Up = XMVector3Cross(m_LookAt, m_Right); m_Up = XMVector3Normalize(m_Up); m_Right = XMVector3Cross(m_Up, m_LookAt); m_Right = XMVector3Normalize(m_Right); // Fill in the view matrix entries. float x = -XMVectorGetX(XMVector3Dot(m_Position, m_Right)); float y = -XMVectorGetX(XMVector3Dot(m_Position, m_Up)); float z = -XMVectorGetX(XMVector3Dot(m_Position, m_LookAt)); XMFLOAT4X4 tempView; tempView(0, 0) = XMVectorGetX(m_Right); tempView(1, 0) = XMVectorGetY(m_Right); tempView(2, 0) = XMVectorGetZ(m_Right); tempView(3, 0) = x; tempView(0, 1) = XMVectorGetX(m_Up); tempView(1, 1) = XMVectorGetY(m_Up); tempView(2, 1) = XMVectorGetZ(m_Up); tempView(3, 1) = y; tempView(0, 2) = XMVectorGetX(m_LookAt); tempView(1, 2) = XMVectorGetX(m_LookAt); tempView(2, 2) = XMVectorGetX(m_LookAt); tempView(3, 2) = z; tempView(0, 3) = 0.0f; tempView(1, 3) = 0.0f; tempView(2, 3) = 0.0f; tempView(3, 3) = 1.0f; m_ViewMatrix = XMLoadFloat4x4(&tempView); // Reconstuct the viewing frustum. //m_Frustum->ConstructFrustrum( m_zFar, m_ProjMatrix, m_ViewMatrix ); }
//-------------------------------------------------------------------------------------- // Name: NuiMenu::GetXYForVector() // Desc: Map normalized space coordinates to screen space. //-------------------------------------------------------------------------------------- XMFLOAT2 NuiMenu::GetXYForVector( FXMVECTOR vNormalizedSpace ) const { assert( m_dwBackBufferWidth > 0 ); assert( m_dwBackBufferHeight > 0 ); XMFLOAT2 rt; rt.x = XMVectorGetX( vNormalizedSpace ) * m_dwBackBufferWidth + m_dwBackBufferWidth; rt.y = m_dwBackBufferHeight - ( XMVectorGetY( vNormalizedSpace ) * m_dwBackBufferHeight / 2 + m_dwBackBufferHeight / 2 ); return rt; }
XMVECTOR ArcBall::QuatFromBallPoints(XMVECTOR startPoint, XMVECTOR endPoint ) { XMVECTOR dotVector = XMVector3Dot(startPoint, endPoint); float fDot = XMVectorGetX(dotVector); XMVECTOR vPart; vPart = XMVector3Cross(startPoint, endPoint); XMVECTOR result = XMVectorSet(XMVectorGetX(vPart), XMVectorGetY(vPart), XMVectorGetZ(vPart), fDot); return result; }
void CubeMesh::PreLoad(XCVec4 initialPosition, XCVec4 initialRotation, XCVec4 initialScaling, Material material, Texture2D* texture, RasterType rasterType) { m_currentPosition = initialPosition; m_MTranslation = XMMatrixTranslation(XMVectorGetX(initialPosition), XMVectorGetY(initialPosition), XMVectorGetZ(initialPosition)); ApplyRotation(initialRotation); m_material = material; if (m_texture) m_texture = texture; m_rasterType = rasterType; Logger("[CubeMesh] Preload done"); }
void LightPoint::update_radius() { XMVECTOR v = colorv(); float r = XMVectorGetX(v); float g = XMVectorGetY(v); float b = XMVectorGetZ(v); float max = std::fmaxf(std::fmaxf(r, g), b); m_radius = (-m_linear + std::sqrtf(m_linear * m_linear - 4 * m_quadratic * (m_constant - 256.0f * intensity() * max))) / (2 * m_quadratic); }
void Small::Draw() { if (TeamID == NONE) { renderTexture(PlayerTex, Renderer, (XMVectorGetX(Location) - 4.0f), (XMVectorGetY(Location) - 4.0f)); } else if (TeamID == RED) { renderTexture(RedTex, Renderer, (XMVectorGetX(Location) - 4.0f), (XMVectorGetY(Location) - 4.0f)); } else //(TeamID == BLUE) { renderTexture(BlueTex, Renderer, (XMVectorGetX(Location) - 4.0f), (XMVectorGetY(Location) - 4.0f)); } //renderTexture(PointingTex, Renderer, (XMVectorGetX(PointingOneLocation) - 8.0f), (XMVectorGetY(PointingOneLocation) - 8.0f)); if (TeamID != NONE) { renderTexture(PointingTex, Renderer, (XMVectorGetX(PointingTwoLocation) - 2.0f), (XMVectorGetY(PointingTwoLocation) - 2.0f)); } }
void D3DCamera::Move_Z(float d) { //m_Position += d*m_LookAt; // Set the current world matrix to the identity matrix m_WorldMatrix = XMMatrixIdentity(); XMMATRIX temp = XMMatrixTranslation(XMVectorGetX(m_Position), XMVectorGetY(m_Position), XMVectorGetZ(m_Position)); // Scale the temporary matrix m_WorldMatrix *= temp * m_ViewMatrix * m_ProjMatrix; }
void CameraHandler::updateCamera(float dt, InputHandler* inputH, GroundModel*model) { float speed = 90000; if (inputH->IsKeyDown(87)) { //W this->moveBackForward += dt/speed; } if (inputH->IsKeyDown(83)) { //S this->moveBackForward -= dt/speed; } if (inputH->IsKeyDown(65)) { //A this->moveLeftRight -= dt/speed; } if (inputH->IsKeyDown(68)) { //D this->moveLeftRight += dt/speed; } if (inputH->IsKeyReleased(VK_SPACE)) { //SPACE if (this->lockToTerrain == true) { this->lockToTerrain = false; } else { this->lockToTerrain = true; } } if (inputH->IsKeyDown(49)) { //1 this->moveUpDown += dt / speed; } if (inputH->IsKeyDown(50)) { //2 this->moveUpDown -= dt/speed; } if (this->lockToTerrain == true) { this->CameraMeshIntersect(model); } //Change Pitch/yaw values depending on mouse movement this->camPitch += (XMVectorGetY(inputH->GetMouseDeltaPos()) * 0.005); if (this->camPitch > 1.5f) { this->camPitch = 1.5f; } else if (this->camPitch < -1.5f) { this->camPitch = -1.5f; } this->camYaw += (XMVectorGetX(inputH->GetMouseDeltaPos()) * 0.005); return; }
void Scene::render() { t.begin(); DirectX11Core::clearRenderTargetViews(); terrain.draw(); box.draw(); sphere.draw(); car.draw(); static float f = 0.0f; f += 0.001f; Input::update(); //cbl.lightPosW = XMFLOAT3(-2 * sin(f), 2 * cos(f), -1); cbl.lightPosW = XMFLOAT3(XMVectorGetX(c->getPos()), XMVectorGetY(c->getPos()), XMVectorGetZ(c->getPos())); DirectX11Core::mDeviceContext->UpdateSubresource(light, 0, 0, &cbl, 0, 0); DirectX11Core::mDeviceContext->VSSetConstantBuffers(2, 1, &light); float lr = 0, bf = 0, dt = t.getDelta(), factor = 4.5f; if (Input::isKeyDown(DIK_W)) { bf = dt * factor; } else if (Input::isKeyDown(DIK_S)) { bf = -dt * factor; } if (Input::isKeyDown(DIK_A)) { lr = -dt * factor; } else if (Input::isKeyDown(DIK_D)) { lr = dt * factor; } static float yaw = 0, pitch = 0, mouseFactor = 1.2f; yaw += Input::getMouseX() * dt * mouseFactor; pitch += Input::getMouseY() * dt * mouseFactor; c->update(lr, bf, yaw, pitch); s.draw(c->getPos()); DirectX11Core::endScene(); t.end(1); FrameStats fs = t.getStats(); std::wstring s = L"FPS: "; s.append(std::to_wstring((int)fs.fps)); s.append(L" frametime: "); s.append(std::to_wstring(fs.msPerFrame)); s.append(L" (ms)"); SetWindowText(DirectX11Core::mWindow, s.c_str()); }
BBox ComputeBoundingBoxFromPoints(const XMFLOAT3* points, uint32 numPoints, uint32 stride) { BBox out; XMVECTOR MinX, MaxX, MinY, MaxY, MinZ, MaxZ; GetBoundCornersFromPoints(points, numPoints, sizeof(XMFLOAT3), MinX, MaxX, MinY, MaxY, MinZ, MaxZ); float maxx = XMVectorGetX(MaxX); float maxy = XMVectorGetY(MaxY); float maxz = XMVectorGetZ(MaxZ); float minx = XMVectorGetX(MinX); float miny = XMVectorGetY(MinY); float minz = XMVectorGetZ(MinZ); out.Max.x = maxx; out.Max.y = maxy; out.Max.z = maxz; out.Min.x = minx; out.Min.y = miny; out.Min.z = minz; return out; }
void Small::BigDetect() { if (TeamID != RED) { for (int i = 0; i < RedList->size(); i++) { XMVECTOR tempvector = {XMVectorGetX(RedList->at(i)->Location), XMVectorGetY(RedList->at(i)->Location), 0, 0}; XMVECTOR tempdifference = Location - tempvector; if (XMVectorGetX(XMVector2Length(tempdifference)) < 40) { SetChaseTarget(RedList->at(i)); TeamID = Target->TeamID; Chasing = true; Flocking = true; } } } if (TeamID != BLUE) { for (int i = 0; i < BlueList->size(); i++) { XMVECTOR tempvector = {XMVectorGetX(BlueList->at(i)->Location), XMVectorGetY(BlueList->at(i)->Location), 0, 0}; XMVECTOR tempdifference = Location - tempvector; if (XMVectorGetX(XMVector2Length(tempdifference)) < 40) { SetChaseTarget(BlueList->at(i)); TeamID = Target->TeamID; Chasing = true; Flocking = true; } } } }
//--------------------------------------------------------------------- LooseOctreeZonePtr & LooseOctreeZone::getFitChildZone(const Util::AABBPtr & aabb) { XMVECTOR nodeCenter = aabb->getCenterPoint(); XMVECTOR myCenter = mAABB->getCenterPoint(); Util::u_int x = (XMVectorGetX(nodeCenter) > XMVectorGetX(myCenter)) ? 1 : 0; Util::u_int y = (XMVectorGetY(nodeCenter) > XMVectorGetY(myCenter)) ? 1 : 0; Util::u_int z = (XMVectorGetZ(nodeCenter) > XMVectorGetZ(myCenter)) ? 1 : 0; if (NULL == mChildZones[x][y][z]) { XMVECTOR minPoint = mAABB->getMinPoint(); XMVECTOR maxPoint = mAABB->getMaxPoint(); XMFLOAT3 newMin; XMFLOAT3 newMax; if (0 == x) { newMin.x = XMVectorGetX(minPoint); newMax.x = XMVectorGetX(myCenter); } else { newMin.x = XMVectorGetX(myCenter); newMax.x = XMVectorGetX(maxPoint); } if (0 == y) { newMin.y = XMVectorGetY(minPoint); newMax.y = XMVectorGetY(myCenter); } else { newMin.y = XMVectorGetY(myCenter); newMax.y = XMVectorGetY(maxPoint); } if (0 == z) { newMin.z = XMVectorGetZ(minPoint); newMax.z = XMVectorGetZ(myCenter); } else { newMin.z = XMVectorGetZ(myCenter); newMax.z = XMVectorGetZ(maxPoint); } mChildZones[x][y][z] = boost::make_shared<LooseOctreeZone>(XMLoadFloat3(&newMin), XMLoadFloat3(&newMax), mDepth + 1); mChildZones[x][y][z]->setParentZone(this->shared_from_this()); } return mChildZones[x][y][z]; }