bool RayCastTriangle(const Float3& vStart,const Float3& vDir,const Float3& v0,const Float3& v1,const Float3& v2,float& fMaxDistance) { Float3 edge1 = v1 - v0; Float3 edge2 = v2 - v0; Float3 pvec = vDir.Cross(edge2); float det = edge1.Dot( pvec ); float u, v, t; Float3 tvec; if(det > 0){ tvec = vStart - v0; }else{ tvec = v0 - vStart; det = -det; } u = tvec.Dot(pvec); if(u<0.0f||u>det) return false; Float3 qvec = tvec.Cross(edge1); v = vDir.Dot(qvec); if(v<0.0f||u+v>det) return false; t = edge2.Dot(qvec)/det; if(t<0.0f||t>fMaxDistance) return false; fMaxDistance = t; //nor = cross(edge1,edge2); return true; };
void Actor::Update( const FrameTime& frameTime ) { float fDot = acos(m_vFaceDir.Dot(Float3(0,0,1))); //Float3 vAxis = Float3(0,0,1).Cross(vDir).Normalize(); if(m_vFaceDir.x < 0){ fDot*=-1; } m_pNode->SetQuat(Float4(Float3(0,1,0),fDot)); if(m_uiLowBodyBoneIndex!=0xffffffff){ if(m_vMoveDir.Length() < 0.5){ m_pModel->DisableBoneExtraRotate(m_uiLowBodyBoneIndex); }else{ Float3 vNewMoveDir = m_vMoveDir; float fRun = vNewMoveDir.Dot(m_vFaceDir); if(fRun <0){ vNewMoveDir*=-1;//m_pModel->EnableBoneExtraRotate(uiIndex,Float4(Float3(0,0,-1),fFootDot)); } float fFootAngle = acos(vNewMoveDir.Dot(m_vFaceDir)); if(fFootAngle < 0.00001f){ m_pModel->EnableBoneExtraRotate(m_uiLowBodyBoneIndex,Float4(Float3(0,0,1),0)); }else{ Float3 vAxis = m_vFaceDir.Cross(vNewMoveDir).Normalize(); m_pModel->EnableBoneExtraRotate(m_uiLowBodyBoneIndex,Float4(Float3(0,0,vAxis.y),-fFootAngle)); } } } //UpdateSkill U32 uiSkillCount = m_vecSkill.size(); for(U32 i=0;i<uiSkillCount;i++){ Skill* pSkill = m_vecSkill[i]; if(pSkill!=NULL){ pSkill->Update(frameTime,this); } } Move(frameTime.fTimeDelta); }