void DebugLineSystem::AddArrow( const LTVector & vStart, const LTVector & vEnd, const DebugLine::Color & color /* = Color::White */, uint8 nAlpha /* = 255 */ ) { const float fHeadSize = 4.0f; LTVector vStartToEnd = vEnd - vStart; float fLen = vStartToEnd.Mag(); if( vStartToEnd != LTVector::GetIdentity() ) { vStartToEnd.Normalize(); } AddLine( vStart, vEnd, color, nAlpha); LTVector vArrow = vStart + ( ( fLen * 0.9f ) * vStartToEnd ); LTVector vUp( 0.f, 1.f, 0.f ); LTVector vNorm; if( vStartToEnd != vUp ) { vNorm = vStartToEnd.Cross( vUp ); } else { vNorm = LTVector( 1.f, 0.f, 0.f ); } vNorm *= ( fHeadSize/2.0f ); AddLine( vArrow - vNorm, vArrow + vNorm, color, nAlpha); AddLine( vArrow + vNorm, vEnd, color, nAlpha); AddLine( vArrow - vNorm, vEnd, color, nAlpha); }
void Scene::_parseOrthographicCamera( ){ float position[3], lookAt[3], up[3]; _checkToken( "OrthographicCamera" ); _nextToken( ); _checkToken( "{" ); _nextToken( ); _checkToken( "position" ); for( int i = 0; i < 3; i++ ){ _nextToken( ); position[i] = _parseFloat( ); } Point3 pPosition(position); _nextToken( ); _checkToken( "lookAt" ); for( int i = 0; i < 3; i++ ){ _nextToken( ); lookAt[i] = _parseFloat( ); } Point3 pLookAt(lookAt); _nextToken( ); _checkToken( "up" ); for( int i = 0; i < 3; i++ ){ _nextToken( ); up[i] = _parseFloat( ); } Vec3 vUp(up); _nextToken( ); _checkToken( "}" ); // Fill me in! }
void CBillBoard::onRender(const D3DXMATRIX& mView, const D3DXVECTOR3& vPos) { CDirect3D::getInstance()->AlphaTestEnable(TRUE); CDirect3D::getInstance()->AlphaFunction(D3DCMP_GREATER); CDirect3D::getInstance()->AlphaReference(0x80); CDirect3D::getInstance()->SetD3DFVF(SVertexT::FVF); CDirect3D::getInstance()->SetStreamSource(0, m_pVB, 0, sizeof(SVertexT)); CDirect3D::getInstance()->SetTexture(0, m_pTexture); D3DXVECTOR3 vUp(mView._12, mView._22, mView._32); /* simpler, yet supposed-to-be less efficient * D3DXMatrixLookAtRH(&m_matWorld, &m_vPos, &vPos, &vUp); // Backward Direction m_matWorld._41 = m_matWorld._42 = m_matWorld._43 = 0.0f; D3DXMatrixTranspose(&m_matWorld, &m_matWorld); /* optimized by doing manually */ D3DXVECTOR3 zaxis(m_vPos - vPos); D3DXVec3Normalize(&zaxis, &zaxis); D3DXVECTOR3 xaxis; D3DXVec3Normalize(D3DXVec3Cross(&xaxis, &vUp, &zaxis), &xaxis); D3DXVECTOR3 yaxis; D3DXVec3Cross(&yaxis, &zaxis, &xaxis); m_matWorld._11 = xaxis.x; m_matWorld._12 = xaxis.y; m_matWorld._13 = xaxis.z; m_matWorld._21 = yaxis.x; m_matWorld._22 = yaxis.y; m_matWorld._23 = yaxis.z; m_matWorld._31 = zaxis.x; m_matWorld._32 = zaxis.y; m_matWorld._33 = zaxis.z; /**/ m_matWorld._41 = m_vPos.x; m_matWorld._42 = m_vPos.y; m_matWorld._43 = m_vPos.z; CDirect3D::getInstance()->SetTransform(D3DTS_WORLD, &m_matWorld); CDirect3D::getInstance()->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); CDirect3D::getInstance()->SetTexture(0, NULL); CDirect3D::getInstance()->AlphaTestEnable(FALSE); }
void MatrixSet() { D3DXMATRIX matWorld; D3DXMatrixIdentity(&matWorld); gPD3DDevice->SetTransform(D3DTS_WORLD, &matWorld); D3DXMATRIX matView; D3DXVECTOR3 vEye(0.0f, 0.0f, -50.0f); D3DXVECTOR3 vAt(0.0f, 0.0f, 0.0f); D3DXVECTOR3 vUp(0.f, 1.f, 0.f); D3DXMatrixLookAtLH(&matView, &vEye, &vAt, &vUp); gPD3DDevice->SetTransform(D3DTS_VIEW, &matView); D3DXMATRIX matProj; D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI / 6.0f, 1.0f, 1.0f, 1000.0f); gPD3DDevice->SetTransform(D3DTS_PROJECTION, &matProj); D3DVIEWPORT9 viewPort; viewPort.Width = WINDOW_WIDTH; viewPort.Height = WINDOW_HEIGHT; viewPort.X = 0; viewPort.Y = 0; viewPort.MinZ = 0.0f; viewPort.MaxZ = 1.0f; gPD3DDevice->SetViewport(&viewPort); }
bool FindNearestPointOnLine( const LTVector& l0, const LTVector& l1, const LTVector& vPos, LTVector* pvPosNearest ) { // Sanity check. if( !pvPosNearest ) { return false; } // Find the line's normal. LTVector vUp( 0.f, 1.f, 0.f ); LTVector vDir = l1 - l0; vDir.Normalize(); LTVector vNormal = vDir.Cross( vUp ); vNormal.Normalize(); // Find the nearest intersection point between the point and the line. LTVector vRay0 = vPos + ( vNormal * 100000.f ); LTVector vRay1 = vPos - ( vNormal * 100000.f ); return ( kRayIntersect_Failure != RayIntersectLineSegment( l0, l1, vRay0, vRay1, true, pvPosNearest ) ); }
//--------------------------------------- //NAME : SetTransform() //DESC : 坐标转换 //--------------------------------------- void SetTransform() { //设置世界变换矩阵 D3DXMATRIX matWorld,Rx,Ry,Rz; D3DXMatrixIdentity(&matWorld);//单位矩阵 D3DXMatrixRotationX(&Rx,::timeGetTime()/1000.f);//绕x轴旋转 D3DXMatrixRotationY(&Ry,::timeGetTime()/1000.f);//绕y轴旋转 D3DXMatrixRotationZ(&Rz,::timeGetTime()/1000.f);//绕z轴旋转 matWorld=Rx*Ry*Rz*matWorld; g_pd3dDevice->SetTransform(D3DTS_WORLD,&matWorld); //设置取景变换矩阵 D3DXMATRIX matView; D3DXVECTOR3 vEye(0.0f,0.0f,-30.0f); D3DXVECTOR3 vAt(0.0f,0.0f,0.0f); D3DXVECTOR3 vUp(0.0f,1.0f,0.0f); D3DXMatrixLookAtLH(&matView,&vEye,&vAt,&vUp); g_pd3dDevice->SetTransform(D3DTS_VIEW,&matView); //设置投影变换矩阵 D3DXMATRIX matProj; D3DXMatrixPerspectiveFovLH(&matProj,D3DX_PI/4.0f,1.0f,1.0f,1000.0f); g_pd3dDevice->SetTransform(D3DTS_PROJECTION,&matProj); }
PVRTVec3 SimpleCamera::getUp() const { PVRTVec3 vUp(f2vt(0.0f),f2vt(1.0f),f2vt(0.0f)); PVRTMat3 mRotY = PVRTMat3::RotationY(m_fHeading); PVRTMat3 mRotX = PVRTMat3::RotationX(m_fElevation); vUp = (vUp*mRotX)*mRotY; return vUp; }
void Camera::right(){ Vector3 vUp(up.x,up.y,up.z); Vector3 vEye(eye.x-look.x,eye.y-look.y,eye.z-look.z); Vector3 left(vUp.cross(vEye)); eye.x+=left.x*0.03; eye.y+=left.y*0.03; eye.z+=left.z*0.03; look.x+=left.x*0.03; look.y+=left.y*0.03; look.z+=left.z*0.03; }
/*!**************************************************************************** @Function RenderScene @Return bool true if no error occured @Description Main rendering loop function of the program. The shell will call this function every frame. eglSwapBuffers() will be performed by PVRShell automatically. PVRShell will also manage important OS events. Will also manage relevent OS events. The user has access to these events through an abstraction layer provided by PVRShell. ******************************************************************************/ bool OGLES3TextureStreaming::RenderScene() { // Clears the color and depth buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Time based animation and locks the app to 60 FPS. // Uses the shell function PVRShellGetTime() to get the time in milliseconds. unsigned long ulTime = PVRShellGetTime(); unsigned long ulDeltaTime = ulTime - m_ulTimePrev; m_ulTimePrev = ulTime; m_fFrame += (float)ulDeltaTime * (60.0f/1000.0f); m_fBandScroll += (float)ulDeltaTime * (60.0f/1000.0f) * c_fBandScrollSpeed; if(m_fFrame > m_Scene.nNumFrame - 1) m_fFrame = 0.0f; if(m_fBandScroll > 1.0f) m_fBandScroll = -c_fBandWidth; bool bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen); m_Scene.SetFrame(m_fFrame); // Setup the main camera PVRTVec3 vFrom, vTo(0.0f), vUp(0.0f, 1.0f, 0.0f); float fFOV; // Camera nodes are after the mesh and light nodes in the array int i32CamID = m_Scene.pNode[m_Scene.nNumMeshNode + m_Scene.nNumLight + c_ui32Camera].nIdx; // Get the camera position, target and field of view (fov) if(m_Scene.pCamera[i32CamID].nIdxTarget != -1) // Does the camera have a target? fFOV = m_Scene.GetCameraPos( vFrom, vTo, c_ui32Camera); // vTo is taken from the target node else fFOV = m_Scene.GetCamera( vFrom, vTo, vUp, c_ui32Camera); // vTo is calculated from the rotation float fTargetAspect = 960.0f/640.0f; float fAspect = (float)PVRShellGet(prefWidth) / (float)PVRShellGet(prefHeight); fFOV *= fTargetAspect / fAspect; PVRTMat4 mView = PVRTMat4::LookAtRH(vFrom, vTo, vUp); PVRTMat4 mProjection = PVRTMat4::PerspectiveFovRH(fFOV, (float)PVRShellGet(prefWidth)/(float)PVRShellGet(prefHeight), c_fCameraNear, c_fCameraFar, PVRTMat4::OGL, bRotate); PVRTMat4 mViewProjection = mProjection * mView; DrawPODScene(mViewProjection); // Displays the demo name using the tools. For a detailed explanation, see the training course IntroducingPVRTools m_Print3D.DisplayDefaultTitle("Texture Streaming", c_pszDescription, ePVRTPrint3DSDKLogo); m_Print3D.Flush(); ++m_i32Frame; return true; }
MStatus sgHair_controlJoint::getJointPositionBaseWorld() { MStatus status; if( !m_bStaticRotation ) { MVector vAim; MVector vUp( m_mtxJointParentBase(1,0), m_mtxJointParentBase(1,1), m_mtxJointParentBase(1,2) ); MVector vCross; MMatrix mtxLocal; MMatrix mtxWorld = m_mtxJointParentBase; m_mtxArrBase.setLength( m_cvs.length() ); for( int i=0; i< m_cvs.length()-1; i++ ) { vAim = ( m_cvs[i+1] - m_cvs[i] )*m_mtxBaseCurve; vCross = vAim ^ vUp; vUp = vCross ^ vAim; vAim.normalize(); vUp.normalize(); vCross.normalize(); m_mtxArrBase[i] = buildMatrix( vAim, vUp, vCross, m_cvs[i]*m_mtxBaseCurve ); } MPoint pointWorld = m_cvs[m_cvs.length()-1]*m_mtxBaseCurve; MMatrix mtxLastWorld; mtxLastWorld( 3, 0 ) = pointWorld.x; mtxLastWorld( 3, 1 ) = pointWorld.y; mtxLastWorld( 3, 2 ) = pointWorld.z; m_mtxArrBase[m_cvs.length()-1] = mtxLastWorld; } else { MVector aim( 1,0,0 ); MVector up( 0,1,0 ); MVector cross( 0,0,1 ); m_mtxArrBase.setLength( m_cvs.length() ); aim *= m_mtxJointParentBase; up *= m_mtxJointParentBase; cross *= m_mtxJointParentBase; for( int i=0; i< m_cvs.length(); i++ ) { m_mtxArrBase[i] = buildMatrix( aim, up, cross, m_cvs[i]*m_mtxBaseCurve ); } } return MS::kSuccess; }
void CreatePropDebris(LTVector & vPos, LTVector & vDir, uint8 nDebrisId) { CLIENTDEBRIS cd; LTVector vUp(0.0f, 1.0f, 0.0f); g_pLTServer->AlignRotation(&(cd.rRot), &vDir, &vUp); cd.vPos = vPos; cd.nDebrisId = nDebrisId; ::CreateDebris(cd); }
Matrix calcLightMatrix(const BBox& bbox, const Vec3D& vLightDir) { float fLength = (bbox.vMax-bbox.vMin).length(); Vec3D vLookAt=(bbox.vMax+bbox.vMin)*0.5f; Vec3D vEyePt = vLookAt - vLightDir*fLength*0.5f; Vec3D vUp(0,1,0); Matrix mView, mProj; mView.MatrixLookAtLH(vEyePt,vLookAt,vUp); mProj.MatrixOrthoLH(fLength,fLength, 0, fLength); Matrix mLight = mProj*mView; return mLight; }
void sgHair_controlJoint::normalizeMatrix( MMatrix& mtx ) { MVector vAim( mtx(0,0), mtx(0,1), mtx(0,2) ); MVector vUp( mtx(1,0), mtx(1,1), mtx(1,2) ); MVector vCross( mtx(2,0), mtx(2,1), mtx(2,2) ); vAim.normalize(); vUp.normalize(); vCross.normalize(); mtx( 0, 0 ) = vAim.x; mtx( 0, 1 ) = vAim.y; mtx( 0, 2 ) = vAim.z; mtx( 1, 0 ) = vUp.x; mtx( 1, 1 ) = vUp.y; mtx( 1, 2 ) = vUp.z; mtx( 2, 0 ) = vCross.x; mtx( 2, 1 ) = vCross.y; mtx( 2, 2 ) = vCross.z; }
void M2EffectRender::UpdateParicles() { if (!ParticleData_.gpEffect10) return; //if (fElapsedTime > 0.1f) fElapsedTime = 0.1f; D3DXVECTOR3 vEye; GetCamera()->getFrom(vEye); D3DXMATRIX mView; memcpy(&mView, GetCamera()->getViewMatrix(), SIZE16); D3DXVECTOR3 vRight( mView._13, mView._23, mView._33 ); D3DXVECTOR3 vUp( mView._12, mView._22, mView._32 ); D3DXVECTOR3 vFoward( mView._11, mView._21, mView._31 ); D3DXVec3Normalize( &vRight, &vRight ); D3DXVec3Normalize( &vUp, &vUp ); D3DXVec3Normalize( &vFoward, &vFoward ); //gpvRight->SetFloatVector( ( float* )&vRight ); //gpvUp->SetFloatVector( ( float* )&vUp ); //gpvForward->SetFloatVector( ( float* )&vFoward ); ParticleData_.gpvEyePt->SetFloatVector( ( float* )&vEye ); ParticleVertex* pVerts = NULL; M2ParticleSystem* ps ; for (size_t i=0; i < Owner_->header.nParticleEmitters; ++i) { ps = &Owner_->particleSystems[i]; ID3D11Resource* pRes = ParticleData_.ParticleBuffers.at(i); D3D11_MAPPED_SUBRESOURCE Data; HRESULT hr = GetApp()->GetContext()->Map( pRes, 0, D3D11_MAP_WRITE_DISCARD, 0, &Data ); if (FAILED(hr)) assert(false); pVerts = (ParticleVertex*)Data.pData; CopyParticlesToVertexBuffer(i, ps, pVerts, vEye, -vFoward, vUp ); GetApp()->GetContext()->Unmap(pRes, 0); } }
void CAXModel::UpdateMatrix(void) { D3DXMATRIX matPosition; D3DXMATRIX matSize; D3DXMATRIX matRotate; D3DXMATRIX matAnchorPoint; D3DXMATRIX matComplate; D3DXMATRIX mT; { AVector3 vLeft(1.0f, 0.0f, 0.0f); AVector3 vUp(0.0f, 1.0f, 0.0f); AVector3 vLook(0.0f, 0.0f, 1.0f); AVector3 vUpNew, vLeftNew, vLookNew; D3DXMATRIX mX, mY, mZ; D3DXMatrixRotationX(&mX, m_fRotX); D3DXMatrixRotationY(&mY, m_fRotY); D3DXMatrixRotationZ(&mZ, -m_fRotZ); D3DXMatrixTranslation(&mT, vUp.x, vUp.y, vUp.z); mT *= mX; D3DXMatrixTranslation(&mT, mT._41, mT._42, mT._43); mT *= mY; D3DXMatrixTranslation(&mT, mT._41, mT._42, mT._43); mT *= mZ; vUpNew = AVector3(mT._41, mT._42, mT._43); D3DXMatrixTranslation(&mT, vLeft.x, vLeft.y, vLeft.z); mT *= mX; D3DXMatrixTranslation(&mT, mT._41, mT._42, mT._43); mT *= mY; D3DXMatrixTranslation(&mT, mT._41, mT._42, mT._43); mT *= mZ; vLeftNew = AVector3(mT._41, mT._42, mT._43); D3DXMatrixTranslation(&mT, vLook.x, vLook.y, vLook.z); mT *= mX; D3DXMatrixTranslation(&mT, mT._41, mT._42, mT._43); mT *= mY; D3DXMatrixTranslation(&mT, mT._41, mT._42, mT._43); mT *= mZ; vLookNew = AVector3(mT._41, mT._42, mT._43); mT._11 = vLeftNew.x; mT._12 = vLeftNew.y; mT._13 = vLeftNew.z; mT._14 = 0.0f; // Left Vector mT._21 = vUpNew.x; mT._22 = vUpNew.y; mT._23 = vUpNew.z; mT._24 = 0.0f; // Up Vector mT._31 = vLookNew.x; mT._32 = vLookNew.y; mT._33 = vLookNew.z; mT._34 = 0.0f; // Front Vector mT._41 = 0.0f; mT._42 = 0.0f; mT._43 = 0.0f; mT._44 = 1.0f; // Translation } D3DXMatrixTranslation(&matAnchorPoint, m_vAnchorPoint.x, m_vAnchorPoint.y, m_vAnchorPoint.z); D3DXMatrixScaling(&matSize, m_vSize.x, m_vSize.y, m_vSize.z); D3DXMatrixTranslation(&matPosition, m_vPosition.x, m_vPosition.y, m_vPosition.z); m_matComplate = matAnchorPoint * matSize * mT * matPosition; m_bUpdateMatrix = false; }
void M2EffectRender::CopyRibbonsToVertexBuffer( int index, M2RibbonEmitter& Ribbon, RibbonVertex* pVB ) { noVec3 vRight(0,0,-1); noVec3 vUp(0,1,0); UINT iVBIndex = 0; uint32 gNumActiveParticles = 0; for (size_t i=0; i< 1 ; i++) { std::list<M2RibbonSegment>::iterator it = Ribbon.segs.begin(); float l = 0; for (; it != Ribbon.segs.end(); ++it) { float u = l/Ribbon.length; pVB[iVBIndex].pos = it->pos + Ribbon.tabove * it->up; pVB[iVBIndex].uv = noVec2(u, 0); pVB[iVBIndex].color = Ribbon.tcolor; pVB[++iVBIndex].pos = it->pos - Ribbon.tbelow * it->up; pVB[iVBIndex].uv = noVec2(u,1); pVB[iVBIndex].color = Ribbon.tcolor; ++iVBIndex; gNumActiveParticles ++; l += it->len; } if (Ribbon.segs.size() > 1) { // last segment...? --it; pVB[iVBIndex].pos = it->pos + Ribbon.tabove * it->up + (it->len/it->len0) * it->back; pVB[iVBIndex].uv = noVec2(1, 0); pVB[iVBIndex].color = Ribbon.tcolor; pVB[++iVBIndex].pos = it->pos - Ribbon.tbelow * it->up + (it->len/it->len0) * it->back; pVB[iVBIndex].uv = noVec2(1,1); pVB[iVBIndex].color = Ribbon.tcolor; gNumActiveParticles++; } } RibbonData_.gNumActiveParticles.at(index) = gNumActiveParticles; }
void CameraDefaultCtrl::updateViewMat() { D3DXMATRIX matR; D3DXMatrixRotationYawPitchRoll(&matR, m_yaw, m_pitch, m_roll); Vector3 vViewDir = Vector3(0,0,1); Vector3 vUp(0,1,0); vViewDir = vViewDir * matR; vUp = vUp * matR; m_eyePos = vViewDir*m_dist + m_lookAt; m_camera.setViewLookAt(m_eyePos, m_lookAt, vUp); }
/******************************************************************************* * Function Name : CameraGetMatrix * Global Used : * Description : Function to setup camera position * *******************************************************************************/ void OGLESSkinning::CameraGetMatrix() { PVRTVec3 vFrom, vTo, vUp(0.0f, 1.0f, 0.0f); float fFOV; bool bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen); //.. get the Camera's position, direction and FOV. fFOV = m_Scene.GetCamera(vFrom, vTo, vUp, 0); // Set up the view matrix m_mView = PVRTMat4::LookAtRH(vFrom, vTo, vUp); // Set up the projection matrix m_mProjection = PVRTMat4::PerspectiveFovRH(fFOV, (float) PVRShellGet(prefWidth) / (float) PVRShellGet(prefHeight), g_fCameraNear, g_fCameraFar, PVRTMat4::OGL, bRotate); }
void VFreeCamera::ProcessInput(float fTimeDiff) { hkvVec3 vMoveDelta = hkvVec3::ZeroVector(); // Handle movement. hkvVec3 vForward(hkvNoInitialization), vRight(hkvNoInitialization), vUp(hkvNoInitialization); GetCurrentMoveAxes(vForward, vRight, vUp); float fMaxSpeed = m_fMoveSpeed; if (m_pInputMap->GetTrigger(CONTROL_SPEED_FAST)) fMaxSpeed *= 3.0f; else if (m_pInputMap->GetTrigger(CONTROL_SPEED_FASTER)) fMaxSpeed *= 9.0f; // Accumulate move directions (multiply in order to take analog input into account). vMoveDelta += vForward * m_pInputMap->GetTrigger(CONTROL_MOVE_FORWARD); vMoveDelta -= vForward * m_pInputMap->GetTrigger(CONTROL_MOVE_BACKWARD); vMoveDelta -= vRight * m_pInputMap->GetTrigger(CONTROL_MOVE_RIGHT); vMoveDelta += vRight * m_pInputMap->GetTrigger(CONTROL_MOVE_LEFT); vMoveDelta += vUp * m_pInputMap->GetTrigger(CONTROL_MOVE_UP); vMoveDelta -= vUp * m_pInputMap->GetTrigger(CONTROL_MOVE_DOWN); vMoveDelta *= fMaxSpeed; // Clamp movement, so that moving diagonally is not faster than moving straight when using digital input. const float fSpeed = vMoveDelta.getLength(); if (fSpeed > fMaxSpeed) vMoveDelta.setLength(fMaxSpeed); vMoveDelta *= fTimeDiff; // Look around. const float dx = m_pInputMap->GetTrigger(CONTROL_HORIZONTAL_LOOK); const float dy = m_pInputMap->GetTrigger(CONTROL_VERTICAL_LOOK); hkvVec3 vOrientation = GetOrientation(); vOrientation.x += -dx * m_fSensitivity; vOrientation.y = hkvMath::clamp(vOrientation.y + dy * m_fSensitivity, -89.5f, 89.5f); SetOrientation(vOrientation); // Apply delta. if (GetPhysicsObject() != NULL) { IncMotionDeltaWorldSpace(vMoveDelta); } else { IncPosition(vMoveDelta); } }
BOOL VWallmarkManager::TryAlignWallmark( const hkvVec3& vCenter, const hkvVec3& vNormal, float fSize, float fRotation, hkvVec3& vNewCenter, hkvMat3 &alignment, float fEpsilon ) { VISION_PROFILE_FUNCTION(PROFILING_WALLMARK_CREATION); hkvVec3 vNewNormal(hkvNoInitialization); float fTraceRad = fSize; if (!IsTracePointOnPlane(vCenter,vNormal,fTraceRad,fEpsilon,vNewNormal)) return false; hkvVec3 vRight(hkvNoInitialization),vUp(hkvNoInitialization),vRotRight(hkvNoInitialization),vRotUp(hkvNoInitialization), vDummy(hkvNoInitialization); if (hkvMath::Abs (vNewNormal.x)>0.5f) vRight.set(0.f,1.f,0.f); else vRight.set(1.f,0.f,0.f); vUp = vNewNormal.cross(vRight); vRight = vNewNormal.cross(vUp); float fSin = hkvMath::sinDeg (fRotation); float fCos = hkvMath::cosDeg (fRotation); vRotRight = vRight * fCos + vUp * fSin; vRotUp = vRight * -fSin + vUp * fCos; vRotRight.setLength(fSize*0.5f); vRotUp.setLength(fSize*0.5f); alignment.setAxisXYZ (vNewNormal,vRotRight,vRotUp); vNewCenter = vCenter + vNewNormal*fEpsilon; // check corners: if (!IsTracePointOnPlane(vCenter+vRotRight+vRotUp,vNewNormal,fTraceRad,fEpsilon,vDummy)) return false; if (!IsTracePointOnPlane(vCenter+vRotRight-vRotUp,vNewNormal,fTraceRad,fEpsilon,vDummy)) return false; if (!IsTracePointOnPlane(vCenter-vRotRight+vRotUp,vNewNormal,fTraceRad,fEpsilon,vDummy)) return false; if (!IsTracePointOnPlane(vCenter-vRotRight-vRotUp,vNewNormal,fTraceRad,fEpsilon,vDummy)) return false; return TRUE; }
//-------------------------------------------------------------------------------------- // Override for setting the view parameters //-------------------------------------------------------------------------------------- void CModelViewerCamera::SetViewParams( D3DXVECTOR3* pvEyePt, D3DXVECTOR3* pvLookatPt ) { CBaseCamera::SetViewParams( pvEyePt, pvLookatPt ); // Propogate changes to the member arcball D3DXQUATERNION quat; D3DXMATRIXA16 mRotation; D3DXVECTOR3 vUp(0,1,0); D3DXMatrixLookAtLH( &mRotation, pvEyePt, pvLookatPt, &vUp ); D3DXQuaternionRotationMatrix( &quat, &mRotation ); m_ViewArcBall.SetQuatNow( quat ); // Set the radius according to the distance D3DXVECTOR3 vEyeToPoint; D3DXVec3Subtract( &vEyeToPoint, pvLookatPt, pvEyePt ); SetRadius( D3DXVec3Length( &vEyeToPoint ) ); }
void Game::Init() { m_pShaderProgram = new CShaderProgram; m_pSphere = new CSphere; m_pTimer = new CHighResolutionTimer; // This sets the position, viewpoint, and up vector of the synthetic camera glm::vec3 vEye(0, 0, 20); glm::vec3 vView(0, 0, 0); glm::vec3 vUp(0, 1, 0); glm::mat4 mViewMatrix = glm::lookAt(vEye, vView, vUp); // This creates a view frustum glm::mat4 mProjectionMatrix = glm::perspective(45.0f, 1.333f, 1.0f, 150.0f); // This sets the background colour glClearColor(0.5f, 0.5f, 0.5f, 1.0f); glClearDepth(1.0); // Load and compile shaders CShader shVertex, shFragment; shVertex.LoadShader("data\\shaders\\shader.vert", GL_VERTEX_SHADER); shFragment.LoadShader("data\\shaders\\shader.frag", GL_FRAGMENT_SHADER); // Create shader program and add shaders m_pShaderProgram->CreateProgram(); m_pShaderProgram->AddShaderToProgram(&shVertex); m_pShaderProgram->AddShaderToProgram(&shFragment); // Link and use the program m_pShaderProgram->LinkProgram(); m_pShaderProgram->UseProgram(); // Set the modeling, viewing, and projection matrices in the shader m_pShaderProgram->SetUniform("viewMatrix", mViewMatrix); m_pShaderProgram->SetUniform("projectionMatrix", mProjectionMatrix); m_pShaderProgram->SetUniform("vlightDirection", glm::normalize(glm::vec3(0.5f, 0.5f, 0.5f))); m_pShaderProgram->SetUniform("sampler0", 0); m_pSphere->Create("data\\textures\\", "dirtpile01.jpg", 25, 25); // Texture downloaded from http://www.psionicgames.com/?page_id=26 on 24 Jan 2013 m_pTimer->Start(); }
//---------------------------------------------------------- /// Set Look At /// /// Set the camera orientation, target and position /// @param Position /// @param Look target /// @param Up direction //---------------------------------------------------------- void Transform::SetLookAt(const Core::Vector3& invPos, const Core::Vector3& invTarget, const Core::Vector3& invUp) { Core::Vector3 vUp(invUp); Core::Vector3 vForward(invTarget - invPos); vForward.Normalise(); Core::Vector3 vRight(Vector3::CrossProduct(vUp, vForward)); vUp = Core::Vector3::CrossProduct(vForward, vRight); vUp.Normalise(); vRight.Normalise(); Core::Quaternion cRot(vRight, vUp, vForward); cRot.Normalise(); SetPositionScaleOrientation(invPos, mvScale, cRot); }
Dvoid Camera::Yaw() { if (m_MouseMoveInterval.x == 0) return; m_bMove = true; Matrix44 matRot; Vector3 vUp(0, 1, 0); float fAngle = m_MouseMoveInterval.x * m_fMouseSens * m_fTimeDelta; matRot.Rotation(vUp, fAngle); for (Duint i = 0; i < CD_MAX; ++i) { m_vDir[i] = Vec4ToVec3(matRot * Vector4(m_vDir[i], 0), Vector4::W_IGNORE); m_vDir[i].Normalize(); } }
void CStaticCamera::SetCamera(void) { _vec3 vCamPos = m_pInfo->m_vDirection * - 1.f; D3DXVec3Normalize(&vCamPos, &vCamPos); //마우스 vCamPos *= m_fCamDistance; _vec3 vRight; memcpy(&vRight, &m_pInfo->m_matWorld.m[0][0], sizeof(float) * 3); D3DXVec3Normalize(&vRight, &vRight); _matrix matRotAxis; D3DXMatrixRotationAxis(&matRotAxis, &vRight, m_fCamAngle); D3DXVec3TransformNormal(&vCamPos, &vCamPos, &matRotAxis); _vec3 vUp(m_pInfo->m_matWorld.m[1][0], m_pInfo->m_matWorld.m[1][1], m_pInfo->m_matWorld.m[1][2]); vCamPos = m_pInfo->m_vPosition; m_vEye = vCamPos - m_pInfo->m_vDirection * 3.f ; m_vEye += 0.5f * _vec3(m_pInfo->m_matWorld.m[0][0], m_pInfo->m_matWorld.m[0][1], m_pInfo->m_matWorld.m[0][2]) + vUp * 20.f; m_vAt = (m_vEye + m_pInfo->m_vDirection ); }
MMatrix sgHair_controlJoint::getAngleWeightedMatrix( const MMatrix& targetMtx, double weight ) { MMatrix mtx; if( m_bStaticRotation ) { mtx = MMatrix() * ( weight-1 ) + targetMtx * weight; cleanMatrix( mtx ); } else { MVector vUpDefault( 0, 1, 0 ); MVector vCrossDefault( 0,0,1 ); MVector vUpInput( targetMtx(1,0), targetMtx(1,1), targetMtx(1,2) ); double angleUp = vUpInput.angle( vUpDefault ) * weight; if( vUpInput.x == 0 && vUpInput.z == 0 ) vUpInput.x = 1; MVector direction( vUpInput.x, 0, vUpInput.z ); direction.normalize(); MVector vUp( sin( angleUp ) * direction.x, cos( angleUp ), sin( angleUp ) * direction.z ); double dot = vUp * MVector( 0.0, 0.0, 1.0 ); MVector vCross( 0.0, -dot, (dot+1) ); MVector vAim = vUp ^ vCross; vAim.normalize(); vUp.normalize(); vCross = vAim ^ vUp; mtx( 0, 0 ) = vAim.x; mtx( 0, 1 ) = vAim.y; mtx( 0, 2 ) = vAim.z; mtx( 1, 0 ) = vUp.x; mtx( 1, 1 ) = vUp.y; mtx( 1, 2 ) = vUp.z; mtx( 2, 0 ) = vCross.x; mtx( 2, 1 ) = vCross.y; mtx( 2, 2 ) = vCross.z; } return mtx; }
static void sphereTraverseOcta(std::vector<Vec3f> &verts, int depth) { float t = sqrtf(0.5f); Vec3f vDn(0.0f, -1.0f, 0.0f); Vec3f vBL(-t, 0.0f, -t); Vec3f vFL(-t, 0.0f, t); Vec3f vFR( t, 0.0f, t); Vec3f vBR( t, 0.0f, -t); Vec3f vUp(0.0f, 1.0f, 0.0f); triTraverse(verts, vBL, vBR, vDn, depth, false); triTraverse(verts, vBR, vFR, vDn, depth, false); triTraverse(verts, vFR, vFL, vDn, depth, false); triTraverse(verts, vFL, vBL, vDn, depth, false); triTraverse(verts, vBL, vFL, vUp, depth, false); triTraverse(verts, vFL, vFR, vUp, depth, false); triTraverse(verts, vFR, vBR, vUp, depth, false); triTraverse(verts, vBR, vBL, vUp, depth, false); spherize(verts); }
const mtx& mtx::view(const vec3& pos, const vec3& at, const vec3& up) { vec3 vLook(at - pos); vLook.normalize(); vec3 vRight(up.cross(vLook)); vRight.normalize(); vec3 vUp(vLook.cross(vRight)); vUp.normalize(); _11 = vRight.x ; _12 = vUp.x ; _13 = vLook.x ; _14 = 0.0f; _21 = vRight.y ; _22 = vUp.y ; _23 = vLook.y ; _24 = 0.0f; _31 = vRight.z ; _32 = vUp.z ; _33 = vLook.z ; _34 = 0.0f; _41 = -vRight.dot(pos); _42 = -vUp.dot(pos); _43 = -vLook.dot(pos); _44 = 1.0f; return *this; }
quaternion(vector3 vDir) { vector3 vUp (vDir); vector3 vDirection (1, 0, 0); vector3 vRight = vUp.crossProduct(vDirection); // Step 2. Put the three vectors into the matrix to bulid a basis rotation matrix // This step isnt necessary, but im adding it because often you would want to convert from matricies to quaternions instead of vectors to quaternions // If you want to skip this step, you can use the vector values directly in the quaternion setup below matrix4x4 mBasis= matrix4x4(vRight.x, vRight.y, vRight.z, 0.0f, vUp.x, vUp.y, vUp.z, 0.0f, vDirection.x, vDirection.y, vDirection.z, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f); // Step 3. Build a quaternion from the matrix w = (float)Ogre::Math::Sqrt(1.0f + mBasis[0][0] + mBasis[1][1] + mBasis[2][2]) / 2.0f; double dfWScale = w * 4.0; x = (float)((mBasis[2][1] - mBasis[1][2]) / dfWScale); y = (float)((mBasis[0][2] - mBasis[2][0]) / dfWScale); z = (float)((mBasis[1][0] - mBasis[0][1]) / dfWScale); }
//----------------------------------------------------------------------------- // Name: RestoreDeviceObjects() // Desc: Initialize scene objects. //----------------------------------------------------------------------------- HRESULT CMyD3DApplication::RestoreDeviceObjects() { m_pFont->RestoreDeviceObjects(); // Set the matrices D3DXVECTOR3 vEye( 0.0f, 0.0f,-3.0f ); D3DXVECTOR3 vAt( 0.0f, 0.0f, 0.0f ); D3DXVECTOR3 vUp( 0.0f, 1.0f, 0.0f ); D3DXMATRIX matWorld, matView, matProj; D3DXMatrixIdentity( &matWorld ); D3DXMatrixLookAtLH( &matView, &vEye,&vAt, &vUp ); FLOAT fAspect = m_d3dsdBackBuffer.Width / (FLOAT)m_d3dsdBackBuffer.Height; D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, fAspect, 1.0f, 100.0f ); m_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld ); m_pd3dDevice->SetTransform( D3DTS_VIEW, &matView ); m_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj ); // Set state m_pd3dDevice->SetRenderState( D3DRS_DITHERENABLE, FALSE ); m_pd3dDevice->SetRenderState( D3DRS_CLIPPING, FALSE ); m_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE ); m_pd3dDevice->SetRenderState( D3DRS_CLIPPING, FALSE ); m_pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE ); m_pd3dDevice->SetRenderState( D3DRS_ZENABLE, FALSE ); m_pd3dDevice->SetRenderState( D3DRS_ZWRITEENABLE, FALSE ); m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ); m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE ); m_pd3dDevice->SetTextureStageState( 0, D3DTSS_MINFILTER, D3DTEXF_LINEAR ); m_pd3dDevice->SetTextureStageState( 0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR ); return S_OK; }