//----------------------------------------------------------------------------- // Name: // Desc: //----------------------------------------------------------------------------- VOID FillCurve(DWORD dwStep, DWORD dwSize, DWORD dwStride, VERTICES* pvVertices) { while(dwStep>0) { int halfstep = dwStep / 2; int doublestep = dwStep * 2; for(DWORD i = 0; i < dwSize - 1; i += doublestep) { int left = i * dwStride; int mid = (i + dwStep) * dwStride; int right = (i + doublestep) * dwStride; // lerp vertex position D3DXVECTOR3 a,b; D3DXVec3Lerp(&a, &pvVertices[left].vPosition, &pvVertices[mid].vPosition, 0.5f); D3DXVec3Lerp(&b, &pvVertices[mid].vPosition, &pvVertices[right].vPosition, 0.5f); D3DXVec3Lerp(&pvVertices[mid].vPosition, &a, &b, 0.5f); if(halfstep>0) { int half_left = (i+halfstep) * dwStride; int half_right = (i+halfstep*3) * dwStride; pvVertices[half_left].vPosition = a; pvVertices[half_right].vPosition = b; } // texture coords D3DXVECTOR2 u,v; D3DXVec2Lerp(&u, &pvVertices[left].uv, &pvVertices[mid].uv, 0.5f); D3DXVec2Lerp(&v, &pvVertices[mid].uv, &pvVertices[right].uv, 0.5f); D3DXVec2Lerp(&pvVertices[mid].uv, &u, &v, 0.5f); if(halfstep>0) { int half_left = (i+halfstep) * dwStride; int half_right = (i+halfstep*3) * dwStride; pvVertices[half_left].uv = u; pvVertices[half_right].uv = v; } } dwStep = halfstep; } }
void Homing::Move(float dtime) { D3DXVECTOR2 dir = m_pTarget->GetPosition() - m_pSelf->GetPosition(); float distance = D3DXVec2Length(&dir); if (distance > 10) { D3DXVec2Normalize(&dir, &dir); D3DXVECTOR2 curDir = D3DXVECTOR2(cos(m_pSelf->GetAngle()), sin(m_pSelf->GetAngle())); D3DXVECTOR2 alteredDir; D3DXVec2Lerp(&alteredDir, &curDir, &dir, m_TurningSpeed); float alteredAngle = atan2(alteredDir.y, alteredDir.x); //update angle and position m_pSelf->SetRotation(alteredAngle); m_pSelf->SetPosition(m_pSelf->GetPosition() + (D3DXVECTOR2(cos(alteredAngle), sin(alteredAngle)) * m_MoveSpeed * dtime)); } }
/** * CABT::splitTriangle * @date Modified Apr 18, 2006 */ void CABT::splitTriangle(CMesh::SVertex* pVertex, SPlane& oPlane, std::vector<CMesh::SVertex>& vFront, std::vector<CMesh::SVertex>& vBack) { unsigned int nResA, nResB; CMesh::SVertex vA, vB; vA = pVertex[2]; nResA = getPointClassification(vA.vPosition, oPlane); std::vector<CMesh::SVertex> vFrontFaces, vBackFaces; // Check triangle edges for(unsigned int i = 0; i < 3; ++i) { // Get the next triangle point vB = pVertex[i]; nResB = getPointClassification(vB.vPosition, oPlane); if(nResB == PT_FRONT) { if(nResA == PT_BACK) { // Find intersection D3DXVECTOR3 vIntersect; D3DXPLANE oDXPlane; D3DXPlaneIntersectLine(&vIntersect, D3DXPlaneFromPointNormal(&oDXPlane, &oPlane.point, &oPlane.normal), &vA.vPosition, &vB.vPosition); // Calculate interpolation factor D3DXVECTOR3 vNew, vWhole; D3DXVec3Subtract(&vNew, &vA.vPosition, &vIntersect); D3DXVec3Subtract(&vWhole, &vA.vPosition, &vB.vPosition); float fFactor = D3DXVec3Length(&vNew) / D3DXVec3Length(&vWhole); // Interpolate vertex data. CMesh::SVertex vNewVertex; D3DXCOLOR oColor; vNewVertex.vPosition = vIntersect; D3DXVec3Lerp(&vNewVertex.vNormal, &vA.vNormal, &vB.vNormal, fFactor); D3DXVec2Lerp(&vNewVertex.vTexCoord0, &vA.vTexCoord0, &vB.vTexCoord0, fFactor); D3DXColorLerp(&oColor, &D3DXCOLOR(vA.Color), &D3DXCOLOR(vB.Color), fFactor); vNewVertex.Color = oColor; vFrontFaces.push_back(vNewVertex); vBackFaces.push_back(vNewVertex); } vFrontFaces.push_back(vB); } else if(nResB == PT_BACK) { if(nResA == PT_FRONT) { // Find intersection D3DXVECTOR3 vIntersect; D3DXPLANE oDXPlane; D3DXPlaneIntersectLine(&vIntersect, D3DXPlaneFromPointNormal(&oDXPlane, &oPlane.point, &oPlane.normal), &vA.vPosition, &vB.vPosition); // Calculate interpolation factor D3DXVECTOR3 vNew, vWhole; D3DXVec3Subtract(&vNew, &vA.vPosition, &vIntersect); D3DXVec3Subtract(&vWhole, &vA.vPosition, &vB.vPosition); float fFactor = D3DXVec3Length(&vNew) / D3DXVec3Length(&vWhole); // Interpolate vertex data. CMesh::SVertex vNewVertex; D3DXCOLOR oColor; vNewVertex.vPosition = vIntersect; D3DXVec3Lerp(&vNewVertex.vNormal, &vA.vNormal, &vB.vNormal, fFactor); D3DXVec2Lerp(&vNewVertex.vTexCoord0, &vA.vTexCoord0, &vB.vTexCoord0, fFactor); D3DXColorLerp(&oColor, &D3DXCOLOR(vA.Color), &D3DXCOLOR(vB.Color), fFactor); vNewVertex.Color = oColor; vFrontFaces.push_back(vNewVertex); vBackFaces.push_back(vNewVertex); } vBackFaces.push_back(vB); } else { vFrontFaces.push_back(vB); vBackFaces.push_back(vB); } // Next Edge vA = vB; nResA = nResB; } // Make a triangle list out of the the vertices created. for(unsigned int i = 1; i < vFrontFaces.size() - 1; ++i) { vFront.push_back(vFrontFaces[0]); vFront.push_back(vFrontFaces[i]); vFront.push_back(vFrontFaces[i+1]); } for(unsigned int i = 1; i < vBackFaces.size() - 1; ++i) { vBack.push_back(vBackFaces[0]); vBack.push_back(vBackFaces[i]); vBack.push_back(vBackFaces[i+1]); } }