//----------------------------------------------------------------------------- // Name: XBUtil_InitLight() // Desc: Initializes a D3DLIGHT structure, setting the light position. The // diffuse color is set to white, specular and ambient left as black. //----------------------------------------------------------------------------- VOID XBUtil_InitLight( D3DLIGHT8& light, D3DLIGHTTYPE ltType, FLOAT x, FLOAT y, FLOAT z ) { ZeroMemory( &light, sizeof(D3DLIGHT8) ); light.Type = ltType; light.Diffuse.r = 1.0f; light.Diffuse.g = 1.0f; light.Diffuse.b = 1.0f; light.Position = D3DXVECTOR3(x,y,z); light.Position.x = x; light.Position.y = y; light.Position.z = z; D3DXVECTOR3 vSource(x,y,z); D3DXVec3Normalize( (D3DXVECTOR3*)&light.Direction, &vSource ); light.Range = 1000.0f; }
void ConstraintVisualizer::RenderSpring (IVRenderInterface* pRenderer, const hkvVec3& startPos, const hkvVec3& endPos) { // Calculate the look at matrix hkvVec3 vSource(startPos.x, startPos.y, startPos.z); hkvVec3 vTarget(endPos.x, endPos.y, endPos.z); hkvMat3 lookAtMat; lookAtMat.setLookInDirectionMatrix (vTarget - vSource); // Calculate the length and thickness of the spring float fVecLen = (vTarget - vSource).getLength(); float fSpringThickness = fVecLen / 40.0f; // Render the spring hkvVec3 vOldPos; for (int i = -5; i < 105; i++) { // Calculate the position on the spring line float fPosOnLine = fVecLen * ((float) i / 100.0f); fPosOnLine = hkvMath::clamp (fPosOnLine, 0.0f, fVecLen); hkvVec3 vCurrentPos = vSource + lookAtMat.getAxis(0) * fPosOnLine; // Calculate the local offset (to visualize circles) float fAngle = ((float)(i % 10)) * 2 * hkvMath::pi () / 10.0f; float diffX = sin(fAngle); float diffY = cos(fAngle); vCurrentPos += lookAtMat.getAxis(1) * fSpringThickness * diffX; vCurrentPos += lookAtMat.getAxis(2) * fSpringThickness * diffY; // Render the next line fragment if (!vOldPos.isZero (0.0f)) { VColorRef color(255, 255, 0); pRenderer->DrawLine(vOldPos, hkvVec3(vCurrentPos.x, vCurrentPos.y, vCurrentPos.z), color, 2); } vOldPos = hkvVec3(vCurrentPos.x, vCurrentPos.y, vCurrentPos.z); } }