void Camera::lookAt(D3DXVECTOR3& pos, D3DXVECTOR3& target, D3DXVECTOR3& up) { D3DXVECTOR3 L = target - pos; D3DXVec3Normalize(&L, &L); D3DXVECTOR3 R; D3DXVec3Cross(&R, &up, &L); D3DXVec3Normalize(&R, &R); D3DXVECTOR3 U; D3DXVec3Cross(&U, &L, &R); D3DXVec3Normalize(&U, &U); m_posW = pos; m_rightW = R; m_upW = U; m_lookW = L; buildView(); buildFrustumPlanes(); m_viewProj = m_view * m_proj; }
void Geometry::setMesh(engine::Mesh* mesh) { assert( mesh->numVertices == _numVertices ); assert( mesh->numTriangles == _numTriangles ); assert( mesh->numUVs == _numUVSets ); unsigned int i,j; for( i=0; i<_numVertices; i++ ) { _vertices[i] = wrap( mesh->vertices[i] ); } for( i=0; i<_numUVSets; i++ ) { for( j=0; j<_numVertices; j++ ) { _uvs[i][j] = wrap( mesh->uvs[i][j] ); } } for( i=0; i<_numTriangles; i++ ) { _triangles[i].set( mesh->triangles[i].vertexId[0], mesh->triangles[i].vertexId[1], mesh->triangles[i].vertexId[2], mesh->triangles[i].shaderId ); } // calculate per-triangle normals Vector e01, e02, n; for( i=0; i<_numTriangles; i++ ) { D3DXVec3Subtract( &e01, _vertices + mesh->triangles[i].vertexId[1], _vertices + mesh->triangles[i].vertexId[0] ); D3DXVec3Subtract( &e02, _vertices + mesh->triangles[i].vertexId[2], _vertices + mesh->triangles[i].vertexId[0] ); D3DXVec3Cross( &n, &e02, &e01 ); D3DXVec3Normalize( &n, &n ); _normals[mesh->triangles[i].vertexId[0]] = n; _normals[mesh->triangles[i].vertexId[1]] = n; _normals[mesh->triangles[i].vertexId[2]] = n; } instance(); }
void CamerClass::GetViewMatrix(D3DXMATRIX* V) { //保持view局部坐标系,各自轴的彼此正交 D3DXVec3Normalize(&_look, &_look); //look X right D3DXVec3Cross(&_up, &_look, &_right); D3DXVec3Normalize(&_up, &_up); D3DXVec3Cross(&_right, &_up, &_look); D3DXVec3Normalize(&_right, &_right); // 生成view矩阵: float x = -D3DXVec3Dot(&_right, &_pos); float y = -D3DXVec3Dot(&_up, &_pos); float z = -D3DXVec3Dot(&_look, &_pos); (*V)(0,0) = _right.x; (*V)(0, 1) = _up.x; (*V)(0, 2) = _look.x; (*V)(0, 3) = 0.0f; (*V)(1,0) = _right.y; (*V)(1, 1) = _up.y; (*V)(1, 2) = _look.y; (*V)(1, 3) = 0.0f; (*V)(2,0) = _right.z; (*V)(2, 1) = _up.z; (*V)(2, 2) = _look.z; (*V)(2, 3) = 0.0f; (*V)(3,0) = x; (*V)(3, 1) = y; (*V)(3, 2) = z; (*V)(3, 3) = 1.0f; return; }
void Camera::buildView() { // Keep camera's axes orthogonal to each other and of unit length. D3DXVec3Normalize(&mLookW, &mLookW); D3DXVec3Cross(&mUpW, &mLookW, &mRightW); D3DXVec3Normalize(&mUpW, &mUpW); D3DXVec3Cross(&mRightW, &mUpW, &mLookW); D3DXVec3Normalize(&mRightW, &mRightW); // Fill in the view matrix entries. float x = -D3DXVec3Dot(&mPosW, &mRightW); float y = -D3DXVec3Dot(&mPosW, &mUpW); float z = -D3DXVec3Dot(&mPosW, &mLookW); mView(0,0) = mRightW.x; mView(1,0) = mRightW.y; mView(2,0) = mRightW.z; mView(3,0) = x; mView(0,1) = mUpW.x; mView(1,1) = mUpW.y; mView(2,1) = mUpW.z; mView(3,1) = y; mView(0,2) = mLookW.x; mView(1,2) = mLookW.y; mView(2,2) = mLookW.z; mView(3,2) = z; mView(0,3) = 0.0f; mView(1,3) = 0.0f; mView(2,3) = 0.0f; mView(3,3) = 1.0f; }
bool CPicking::CollisionCheckTriangle(D3DXVECTOR3 &PickPos, RAY &_ray, D3DXVECTOR3 &_v0, D3DXVECTOR3 &_v1, D3DXVECTOR3 &_v2) { float t,u,v; t = u = v = 0.0f; D3DXVECTOR3 v_edge1 = _v1 - _v0; D3DXVECTOR3 v_edge2 = _v2 - _v0; D3DXVECTOR3 tvec, pvec, qvec; float det, inv_det; D3DXVec3Cross(&pvec, &_ray.direction, &v_edge2); det = D3DXVec3Dot(&v_edge1, &pvec); if(det > -0.0001f && det < 0.0001f) return false; inv_det = 1.0f / det; tvec = _ray.origin - _v0; u = D3DXVec3Dot(&tvec, &pvec) * inv_det; if(u < 0.0001f || u > 1.0001f) return false; D3DXVec3Cross(&qvec, &tvec, &v_edge1); v = D3DXVec3Dot(&_ray.direction, &qvec) * inv_det; if(v < 0.0001f || (u+v) > 1.0001f ) return false; _ray.fT = D3DXVec3Dot(&v_edge2, &qvec) * inv_det; if(_ray.fT <= 0) return false; PickPos = _v0 + (u * (_v1 - _v0)) + (v * (_v2 - _v0)); return true; }
void Camera::BuildViewMatrix() { // Keep camera's axes orthogonal to each other and of unit length. D3DXVec3Normalize(&m_vForward, &m_vForward); D3DXVec3Cross(&m_vUp, &m_vForward, &m_vRight); D3DXVec3Normalize(&m_vUp, &m_vUp); D3DXVec3Cross(&m_vRight, &m_vUp, &m_vForward); D3DXVec3Normalize(&m_vRight, &m_vRight); // Fill in the view matrix entries. float x = -D3DXVec3Dot(&m_vEyePoint, &m_vRight); float y = -D3DXVec3Dot(&m_vEyePoint, &m_vUp); float z = -D3DXVec3Dot(&m_vEyePoint, &m_vForward); m_matView(0,0) = m_vRight.x; m_matView(1,0) = m_vRight.y; m_matView(2,0) = m_vRight.z; m_matView(3,0) = x; m_matView(0,1) = m_vUp.x; m_matView(1,1) = m_vUp.y; m_matView(2,1) = m_vUp.z; m_matView(3,1) = y; m_matView(0,2) = m_vForward.x; m_matView(1,2) = m_vForward.y; m_matView(2,2) = m_vForward.z; m_matView(3,2) = z; m_matView(0,3) = 0.0f; m_matView(1,3) = 0.0f; m_matView(2,3) = 0.0f; m_matView(3,3) = 1.0f; }
void AVCamera::walk(float units) { if( units == 0 ) return; if(m_type == CAMERA_TYPE_LANDOBJECT) { D3DXVECTOR3 dir; D3DXVec3Cross(&dir, &m_right, &D3DXVECTOR3(0,1,0)); m_pos += D3DXVECTOR3(dir.x, 0.f, dir.z) * units; } //type == air else m_pos += m_look * units; }
D3DXQUATERNION ArcBall::QuatFromBallPoints(D3DXVECTOR3& start_point, D3DXVECTOR3& end_point) { // Calculate rotate angle float angle = D3DXVec3Dot(&start_point, &end_point); // Calculate rotate axis D3DXVECTOR3 axis; D3DXVec3Cross(&axis, &start_point, &end_point); // Build and Normalize the Quaternion D3DXQUATERNION quat(axis.x, axis.y, axis.z, angle); D3DXQuaternionNormalize(&quat, &quat); return quat; }
void Camera::GetViewMatrix(D3DXMATRIX *view) { // Keep camera's axes orthogonal to each other: D3DXVec3Normalize(&m_vLook, &m_vLook); D3DXVec3Cross(&m_vUp, &m_vLook, &m_vRight); D3DXVec3Normalize(&m_vUp, &m_vUp); D3DXVec3Cross(&m_vRight, &m_vUp, &m_vLook); D3DXVec3Normalize(&m_vRight, &m_vRight); // Build the view matrix: float x = -D3DXVec3Dot(&m_vRight, &m_vPos); float y = -D3DXVec3Dot(&m_vUp, &m_vPos); float z = -D3DXVec3Dot(&m_vLook, &m_vPos); view->_11 = m_vRight.x ; view->_12 = m_vUp.x ; view->_13 = m_vLook.x ; view->_14 = 0.0f ; view->_21 = m_vRight.y ; view->_22 = m_vUp.y ; view->_23 = m_vLook.y ; view->_24 = 0.0f ; view->_31 = m_vRight.z ; view->_32 = m_vUp.z ; view->_33 = m_vLook.z ; view->_34 = 0.0f ; view->_41 = x ; view->_42 = y ; view->_43 = z ; view->_44 = 1.0f ; }
void Camera::lookAt(const D3DXVECTOR3 &eye, const D3DXVECTOR3 &target, const D3DXVECTOR3 &up) { m_eye = eye; m_zAxis = target - eye; D3DXVec3Normalize(&m_zAxis, &m_zAxis); m_viewDir = m_zAxis; D3DXVec3Cross(&m_xAxis, &up, &m_zAxis); D3DXVec3Normalize(&m_xAxis, &m_xAxis); D3DXVec3Cross(&m_yAxis, &m_zAxis, &m_xAxis); D3DXVec3Normalize(&m_yAxis, &m_yAxis); D3DXVec3Normalize(&m_xAxis, &m_xAxis); D3DXMatrixIdentity(&m_viewMatrix); m_viewMatrix(0,0) = m_xAxis.x; m_viewMatrix(1,0) = m_xAxis.y; m_viewMatrix(2,0) = m_xAxis.z; m_viewMatrix(3,0) = -D3DXVec3Dot(&m_xAxis, &eye); m_viewMatrix(0,1) = m_yAxis.x; m_viewMatrix(1,1) = m_yAxis.y; m_viewMatrix(2,1) = m_yAxis.z; m_viewMatrix(3,1) = -D3DXVec3Dot(&m_yAxis, &eye); m_viewMatrix(0,2) = m_zAxis.x; m_viewMatrix(1,2) = m_zAxis.y; m_viewMatrix(2,2) = m_zAxis.z; m_viewMatrix(3,2) = -D3DXVec3Dot(&m_zAxis, &eye); // Extract the pitch angle from the view matrix. m_accumPitchDegrees = D3DXToDegree(-asinf(m_viewMatrix(1,2))); }
void Camera::UpdateView() { D3DXMatrixRotationYawPitchRoll(&rotationMatrix, yaw, pitch, 0); D3DXVec3TransformCoord(&view, &v, &rotationMatrix); D3DXVec3TransformCoord(&up, &u, &rotationMatrix); D3DXVec3Normalize(&forward, &view); D3DXVec3Cross(&right, &up, &view); D3DXVec3Normalize(&right, &right); view = eye + view; D3DXMatrixLookAtLH(&viewMatrix, &eye, &view, &up); }
void Camera::updateView(float dt) { //rotation D3DXMatrixRotationYawPitchRoll(&rotationMatrix, heading, pitch, 0); D3DXVec3TransformCoord(&view,&dV,&rotationMatrix); D3DXVec3TransformCoord(&up,&dU,&rotationMatrix); D3DXVec3Normalize(&forward,&view); D3DXVec3Cross(&strafeRight,&up,&view); D3DXVec3Normalize(&strafeRight,&strafeRight); view = eye + view; D3DXMatrixLookAtLH(&viewMatrix,&eye,&view,&up); }
void CCameraKernel::CalculateViewMatrix(D3DXMATRIX *pMatrix) { //规范化三个向量使之成为正交矩阵 //规范化观察向量 D3DXVec3Normalize(&m_vLookVector, &m_vLookVector); //使上向量与观察向量垂直 D3DXVec3Cross(&m_vUpVector, &m_vLookVector, &m_vRightVector); //规范化上向量 D3DXVec3Normalize(&m_vUpVector, &m_vUpVector); //右向量与上向量垂直 D3DXVec3Cross(&m_vRightVector, &m_vUpVector, &m_vLookVector); //规范化右向量 D3DXVec3Normalize(&m_vRightVector, &m_vRightVector); //创建取景变换矩阵 pMatrix->_11 = m_vRightVector.x; pMatrix->_12 = m_vUpVector.x; pMatrix->_13 = m_vLookVector.x; pMatrix->_14 = 0.0f; pMatrix->_21 = m_vRightVector.y; pMatrix->_22 = m_vUpVector.y; pMatrix->_23 = m_vLookVector.y; pMatrix->_24 = 0.0f; pMatrix->_31 = m_vRightVector.z; pMatrix->_32 = m_vUpVector.z; pMatrix->_33 = m_vLookVector.z; pMatrix->_34 = 0.0f; pMatrix->_41 = -D3DXVec3Dot(&m_vRightVector, &m_vCameraPosition); pMatrix->_42 = -D3DXVec3Dot(&m_vUpVector, &m_vCameraPosition); pMatrix->_43 = -D3DXVec3Dot(&m_vLookVector, &m_vCameraPosition); pMatrix->_44 = 1.0f; }
bool U2IntectRayBox3D::Test() { float aWdU[3], aAWdU[3], aDdU[3], aADdU[3], aAWxDdU[3], fRhs; D3DXVECTOR3 diff = m_pRay->m_vOrigin - m_pBox->m_vCenter; aWdU[0] = D3DXVec3Dot(&m_pRay->m_vDir, &m_pBox->m_avAxis[0]); aAWdU[0] = U2Math::FAbs(aWdU[0]); aDdU[0] = D3DXVec3Dot(&diff, &m_pBox->m_avAxis[0]); aADdU[0] = U2Math::FAbs(aDdU[0]); if(aADdU[0] > m_pBox->m_afExtent[0] && aDdU[0] * aWdU[0] >= 0.f) return false; aWdU[1] = D3DXVec3Dot(&m_pRay->m_vDir, &m_pBox->m_avAxis[1]); aAWdU[1] = U2Math::FAbs(aWdU[1]); aDdU[1] = D3DXVec3Dot(&diff, &m_pBox->m_avAxis[1]); aADdU[1] = U2Math::FAbs(aDdU[1]); if(aADdU[1] > m_pBox->m_afExtent[1] && aDdU[1] * aWdU[1] >= 0.f) return false; aWdU[2] = D3DXVec3Dot(&m_pRay->m_vDir, &m_pBox->m_avAxis[2]); aAWdU[2] = U2Math::FAbs(aWdU[2]); aDdU[2] = D3DXVec3Dot(&diff, &m_pBox->m_avAxis[2]); aADdU[2] = U2Math::FAbs(aDdU[2]); if(aADdU[2] > m_pBox->m_afExtent[2] && aDdU[2] * aWdU[2] >= 0.f) return false; D3DXVECTOR3 WxD; D3DXVec3Cross(&WxD, &m_pRay->m_vDir, &diff); aAWxDdU[0] = U2Math::FAbs(D3DXVec3Dot(&WxD, &m_pBox->m_avAxis[0])); fRhs = m_pBox->m_afExtent[1] *aAWdU[2] + m_pBox->m_afExtent[2]*aAWdU[1]; if(aAWxDdU[0] > fRhs) return false; aAWxDdU[1] = U2Math::FAbs(D3DXVec3Dot(&WxD, &m_pBox->m_avAxis[1])); fRhs = m_pBox->m_afExtent[0] *aAWdU[2] + m_pBox->m_afExtent[2]*aAWdU[0]; if(aAWxDdU[1] > fRhs) return false; aAWxDdU[2] = U2Math::FAbs(D3DXVec3Dot(&WxD, &m_pBox->m_avAxis[2])); fRhs = m_pBox->m_afExtent[0] *aAWdU[1] + m_pBox->m_afExtent[1]*aAWdU[0]; if(aAWxDdU[2] > fRhs) return false; return true; }
OcTreeSector* RayIntersection::collideBSPOcTreeSector(OcTreeSector* ocTreeSector) { if( ocTreeSector->_triangles.size() ) { // collide octree sector triangles Triangle* triangle; Vector v0v1, v0v2, n; Vector hitPoint; for( unsigned int i=0; i<ocTreeSector->_triangles.size(); i++ ) { triangle = _triangles + ocTreeSector->_triangles[i]; if( ::intersectionRayTriangle( &_ray, _vertices + triangle->vertexId[0], _vertices + triangle->vertexId[1], _vertices + triangle->vertexId[2], &hitPoint, &_collisionTriangle.distance )) { _collisionTriangle.vertices[0] = wrap( _vertices[triangle->vertexId[0]] ); _collisionTriangle.vertices[1] = wrap( _vertices[triangle->vertexId[1]] ); _collisionTriangle.vertices[2] = wrap( _vertices[triangle->vertexId[2]] ); v0v1 = _vertices[triangle->vertexId[1]] - _vertices[triangle->vertexId[0]]; v0v2 = _vertices[triangle->vertexId[2]] - _vertices[triangle->vertexId[0]]; D3DXVec3Cross( &n, &v0v1, &v0v2 ); D3DXVec3Normalize( &n, &n ); _collisionTriangle.normal = wrap( n ); _collisionTriangle.collisionPoint = wrap( hitPoint ); _collisionTriangle.shader = _geometry->shader( triangle->shaderId ); _collisionTriangle.triangleId = ocTreeSector->_triangles[i]; if( !_callBack( &_collisionTriangle, _bspSector, NULL, _callBackData ) ) return NULL; return ocTreeSector; } } } else if( ocTreeSector->_subtree[0] ) { for( unsigned int i=0; i<8; i++ ) { if( intersectionRayAABB( &_ray, &ocTreeSector->_subtree[i]->_boundingBox ) ) { if( !collideBSPOcTreeSector( ocTreeSector->_subtree[i] ) ) return NULL; } } } return ocTreeSector; }
/// 카메라 행렬을 생성하기위한 기본 벡터값들을 설정한다. D3DXMATRIXA16* ZCamera::SetView( D3DXVECTOR3* pvEye,D3DXVECTOR3* pvLookat,D3DXVECTOR3* pvUp) { m_vEye = *pvEye; m_vLookat = *pvLookat; m_vUp = *pvUp; D3DXVec3Normalize( &m_vView, &( m_vLookat - m_vEye ) ); D3DXVec3Cross( &m_vCross, &m_vUp, &m_vView ); D3DXMatrixLookAtLH( &m_matView, &m_vEye, &m_vLookat, &m_vUp); D3DXMatrixInverse( &m_matBill, NULL, &m_matView ); m_matBill._41 = 0.0f; m_matBill._42 = 0.0f; m_matBill._43 = 0.0f; return &m_matView; }
//---------------------------------------------------- // CSimpleTriangle //---------------------------------------------------- float CSimpleTriangle::GetPointHeight(float x,float z) { D3DXVECTOR3 pV1 = D3DXVECTOR3(m_Vertex[0].x - m_Vertex[1].x,m_Vertex[0].y - m_Vertex[1].y,m_Vertex[0].z - m_Vertex[1].z); D3DXVECTOR3 pV2 = D3DXVECTOR3(m_Vertex[1].x - m_Vertex[2].x,m_Vertex[1].y - m_Vertex[2].y,m_Vertex[1].z - m_Vertex[2].z); D3DXVECTOR3 normal; D3DXVec3Cross(&normal,&pV1,&pV2); if(normal.y < 0) { normal.x = -normal.x; normal.y = -normal.y; normal.z = -normal.z; } return(m_Vertex[0].y - 1/normal.y*(normal.x*(x - m_Vertex[0].x) + normal.z*(z - m_Vertex[0].z) ) ); }
void Camera::moveCameraViewRelative(FLOAT x, FLOAT y, FLOAT z) { D3DXVECTOR3 dir(0,0,1); D3DXVECTOR3 up = m_up; D3DXVECTOR3 right; D3DXQUATERNION conj; D3DXQuaternionConjugate(&conj, &m_orientation); dir = MathUtil::rotateVec3ByQuat(&dir,&conj); up = MathUtil::rotateVec3ByQuat(&up,&conj); D3DXVec3Cross(&right, &up, &dir); m_translation -= x*right + y*up + z*dir; m_viewCacheValid = false; }
//----------------------------------------------------------------------------- // Name: // Desc: //----------------------------------------------------------------------------- VOID C3DCamera::SetViewParams( D3DXVECTOR3 &vEyePt, D3DXVECTOR3& vLookatPt, D3DXVECTOR3& vUpVec ) { // Set attributes for the view matrix m_vEyePt = vEyePt; m_vLookatPt = vLookatPt; m_vUpVec = vUpVec; D3DXVec3Normalize( &m_vView, &(m_vLookatPt - m_vEyePt) ); D3DXVec3Cross( &m_vCross, &m_vView, &m_vUpVec ); D3DXMatrixLookAtRH( &m_matView, &m_vEyePt, &m_vLookatPt, &m_vUpVec ); D3DXMatrixInverse( &m_matBillboard, NULL, &m_matView ); m_matBillboard._41 = 0.0f; m_matBillboard._42 = 0.0f; m_matBillboard._43 = 0.0f; }
void CBall::CalcReflect(CSimpleTriangle *tri, D3DXVECTOR3 *velo,bool isGreen) { D3DXVECTOR3 r1 = tri->m_Vertex[0] - tri->m_Vertex[1]; D3DXVECTOR3 r2 = tri->m_Vertex[1] - tri->m_Vertex[2]; D3DXVECTOR3 N; D3DXVec3Cross(&N,&r1,&r2); //N = -N; D3DXVec3Normalize(&N,&N); *velo = *velo - 2*D3DXVec3Dot(&N,velo)*N; float V = D3DXVec3Length(velo); if(m_isReflected) { if(m_isPutter) { if(isGreen) { velo->x *= 0.8f; velo->y *= 0.05f; velo->z *= 0.8f; } else { velo->x *= 0.8f; velo->y *= 0.01f; velo->z *= 0.8f; } } else { if(isGreen == false) { velo->x *= 0.5f; velo->y *= 0.4f; velo->z *= 0.5f; } else { velo->x *= 0.7f; velo->y *= 0.5f; velo->z *= 0.7f; } } m_isReflected = true; } }
Camera::Camera(D3DXVECTOR3 Position, D3DXVECTOR3 Forward, float Offset) { offset = Offset; Camera::Position = Position; D3DXVec3Normalize(&(Camera::Forward), &D3DXVECTOR3(Forward.x, 0 , Forward.z)); Up = D3DXVECTOR3(0, 1, 0); D3DXVec3Cross(&(Camera::Right), &Up, &(Camera::Forward)); crouching = false; onGround = true; velocityY = 0.0f; characterHeight = 10; currentSpeed = 1000; currentHeight = 100; }
void Particle::randomPosAdjust() { if (type.compare("Faded") == 0) { D3DXVECTOR3 playerVec =EntityManager::getInstance()->currentPlayer->getPos() -startPosition ; D3DXVec3Normalize(&playerVec,&playerVec); float rando = (float)rand()/RAND_MAX; D3DXVECTOR3 randomVec(0.0f,-1.0f + rando * 2.0f,0.0f); D3DXVec3Cross(&randomVec,&playerVec,&randomVec); ge3D_position +=randomVec; rando = (float)rand()/RAND_MAX; //ge3D_position.z += (-.5f + dist(eng) * 1.0f)* playerVec.z; } }
bool ModelClass::HorizontalCollisionTest(D3DXVECTOR3& amount, std::vector<BoundingBox>& bb, float value) { bool result = false; D3DXVECTOR3 temp; D3DXVec3Cross(&temp, &D3DXVECTOR3(0.0f, 0.0f, 1.0f), &worldAxis); D3DXVECTOR3 offset; offset.x = position.x + ((amount.x * temp.x) * value); offset.y = position.y + ((amount.y * temp.y) * value); offset.z = position.z + ((amount.z * temp.z) * value); D3DXVECTOR3 tempMax = bBox.max; D3DXVECTOR3 tempMin = bBox.min; tempMax = offset + tempMax; tempMin = offset + tempMin; for (int j = 0; j < bb.size(); j++) { if (tempMax.x > bb[j].min.x && tempMin.x < bb[j].max.x && tempMax.y > bb[j].min.y && tempMin.y < bb[j].max.y && tempMax.z > bb[j].min.z && tempMin.z < bb[j].max.z) { if ((abs(temp.x) * amount.x) != 0.0f) { amount.x = 0.0f; result = true; } if ((abs(temp.y) * amount.y) != 0.0f) { amount.y = 0.0f; result = true; } if ((abs(temp.z) * amount.z) != 0.0f) { amount.z = 0.0f; result = true; } } } return result; }
void DXCamera::Update(float _dt) { D3DXMatrixRotationYawPitchRoll(&m_matrixRotation, m_yaw, m_pitch, 0); D3DXVec3TransformCoord(&m_vec3Target, &m_vec3DefaultForward, &m_matrixRotation); D3DXVec3Normalize(&m_vec3Target, &m_vec3Target); switch (m_type) { case eCamera::ECAMERA_DEFAULT: { D3DXVec3TransformNormal(&m_vec3Right, &m_vec3DefaultRight, &m_matrixRotation); D3DXVec3TransformNormal(&m_vec3Forward, &m_vec3DefaultForward, &m_matrixRotation); D3DXVec3Cross(&m_vec3Up, &m_vec3Forward, &m_vec3Right); } break; case eCamera::ECAMERA_FPS: { D3DXMATRIX RotateYTempMatrix; D3DXMatrixRotationY(&RotateYTempMatrix, m_yaw); D3DXVec3TransformNormal(&m_vec3Right, &m_vec3DefaultRight, &RotateYTempMatrix); D3DXVec3TransformNormal(&m_vec3Up, &m_vec3DefaultUp, &RotateYTempMatrix); D3DXVec3TransformNormal(&m_vec3Forward, &m_vec3DefaultForward, &RotateYTempMatrix); } break; case eCamera::ECAMERA_THIRD: { // TODO } break; } // Update position m_vec3Position += m_moveLR * m_vec3Right * _dt; m_vec3Position += m_moveFB * m_vec3Forward * _dt; // Reset the movement m_moveLR = 0.0f; m_moveFB = 0.0f; // Adjust the target m_vec3Target = m_vec3Position + m_vec3Target; D3DXMatrixLookAtLH(&m_matrixView, &m_vec3Position, &m_vec3Target, &m_vec3Up); }
void Camera::GetBillboardedWorldMatrix(D3DXMATRIX & out, D3DXVECTOR3 position) const { D3DXMATRIX rotationMatrix, translationMatrix; D3DXVECTOR3 up = D3DXVECTOR3(0.0f, 1.0f, 0.0f); D3DXVECTOR3 direction = D3DXVECTOR3(position.x - m_positionX, position.y - m_positionY, position.z - m_positionZ); //D3DXVECTOR3 direction = D3DXVECTOR3(m_positionX - position.x, m_positionY - position.y , m_positionZ - position.z); D3DXVECTOR3 right; D3DXVec3Cross(&right, &direction, &up); float magnitude = D3DXVec3Length(&direction); float yaw = atan2(direction.x, direction.z); float pitch = float(D3DX_PI/2 - acos(-direction.y / magnitude)); D3DXMatrixRotationYawPitchRoll(&rotationMatrix, yaw, pitch, 0.0f); D3DXMatrixTranslation(&translationMatrix, position.x, position.y, position.z); out = rotationMatrix * translationMatrix; }
void Camera::rotateCameraViewRelative(FLOAT x, FLOAT y, FLOAT z) { D3DXVECTOR3 dir(0,0,1); D3DXVECTOR3 up(0,1,0); D3DXVECTOR3 right; D3DXVec3Cross(&right, &up, &dir); D3DXQUATERNION xrot(right.x*sin(x*0.5f),right.y*sin(x*0.5f), right.z*sin(x*0.5f), cos(x*0.5f)); D3DXQUATERNION yrot(up.x*sin(y*0.5f),up.y*sin(y*0.5f), up.z*sin(y*0.5f), cos(y*0.5f)); D3DXQUATERNION zrot(dir.x*sin(z*0.5f),dir.y*sin(z*0.5f), dir.z*sin(z*0.5f), cos(z*0.5f)); m_orientation = yrot * m_orientation * xrot * zrot; m_viewCacheValid = false; }
void CollisionSolver::SolvePlaneSimplex(Simplex& simplex, D3DXVECTOR3& direction) { const D3DXVECTOR3& pointA = simplex.GetPoint(2); const D3DXVECTOR3& pointB = simplex.GetPoint(0); const D3DXVECTOR3& pointC = simplex.GetPoint(1); const D3DXVECTOR3 AB = pointB - pointA; const D3DXVECTOR3 AC = pointC - pointA; const D3DXVECTOR3 AO = -pointA; // Determine which side of the plane the origin is on D3DXVECTOR3 planeNormal; D3DXVec3Cross(&planeNormal, &AB, &AC); // Determine the new search direction towards the origin const float distanceToPlane = D3DXVec3Dot(&planeNormal, &AO); direction = (distanceToPlane < 0.0f) ? -planeNormal : planeNormal; }
void CCamera::SetViewParams( D3DXVECTOR3 &pos, D3DXVECTOR3 &lookat, D3DXVECTOR3 &up ) { m_EyePos = pos; m_LookAt = lookat; m_Up = up; m_Direction = m_LookAt - m_EyePos; D3DXVec3Cross( &m_Right, &m_Up, &m_Direction ); D3DXMatrixLookAtLH(&m_ViewTrans, &m_EyePos, &m_LookAt, &m_Up); D3DXMATRIX mInvView; D3DXMatrixInverse( &mInvView, NULL, &m_ViewTrans ); D3DXVECTOR3* pZBasis = (D3DXVECTOR3*) &mInvView._31; m_fCameraYawAngle = atan2f( pZBasis->x, pZBasis->z ); float fLen = sqrtf(pZBasis->z*pZBasis->z + pZBasis->x*pZBasis->x); m_fCameraPitchAngle = -atan2f( pZBasis->y, fLen ); }
////////////////////////////////////////////////////////////////////////// // UpdateNormal ////////////////////////////////////////////////////////////////////////// void ZClothEmblem::UpdateNormal() { int i, j, index, indexTemp[3]; //static rplane planeTemp; //rvector* pPoint[3]; rvector Point[3]; // 초기화 memset( m_pNormal, 0, sizeof(rvector)*m_nCntP ); memset( indexTemp, 0, sizeof(int)*3 ); for( i = 0 ; i < mpMeshNode->m_face_num; ++i ) { for( j = 0 ; j < 3; ++j ) { index = mpMeshNode->m_face_list[i].m_point_index[j]; //Debug if( index < 0 || index >= m_nCntP ) { _ASSERT(FALSE); mlog("Index of Particle is not profit to calculate...\n"); continue; } //End Debug //pPoint[j] = &m_pX[index]; Point[j] = m_pX[index]; indexTemp[j]= index; } rvector n; //D3DXVec3Cross( &n, &(*pPoint[2] - *pPoint[0]), &(*pPoint[2] - *pPoint[1]) ); D3DXVec3Cross( &n, &(Point[2] - Point[0]), &(Point[2] - Point[1] )); D3DXVec3Normalize(&n,&n); for( j = 0 ; j < 3; ++j ) { m_pNormal[indexTemp[j]] += n; } } for( i = 0 ; i < m_nCntP; ++i ) { D3DXVec3Normalize( &m_pNormal[i], &m_pNormal[i] ); } }
////////////////////////////////////////////////////////////////////////// // UpdateNormal ////////////////////////////////////////////////////////////////////////// void RCharCloth::UpdateNormal() { int i, j, index, indexTemp[3]; rplane planeTemp; rvector Point[3]; _ASSERT( m_pNormal ); memset( m_pNormal, 0, sizeof(rvector)*m_nCntP ); _ASSERT( mpMeshNode ); for( i = 0 ; i < mpMeshNode->m_face_num; ++i ) { for( j = 0 ; j < 3; ++j ) { index = mpMeshNode->m_face_list[i].m_point_index[j]; _ASSERT( index < m_nCntP ); _ASSERT( index >= 0 ); Point[j] = m_pX[index]; indexTemp[j] = index; } rvector n; D3DXVec3Cross( &n, &(Point[2] - Point[0]), &(Point[2] - Point[1] )); for( j = 0 ; j < 3; ++j ) { index = indexTemp[j]; _ASSERT( index < m_nCntP ); _ASSERT( index >= 0 ); m_pNormal[index] += n; } } for( i = 0 ; i < m_nCntP; ++i ) { D3DXVec3Normalize( &m_pNormal[i], &m_pNormal[i] ); } }