//---------------------------------------------------------------------------- void WrigglingSnake::ModifyCurve () { // Perturb the snake medial curve. float time = (float)GetTimeInSeconds(); for (int i = 0; i < mNumCtrlPoints; ++i) { Vector3f ctrl = mCenter->GetControlPoint(i); ctrl.Z() = mAmplitudes[i]*Mathf::Sin(3.0f*time + mPhases[i]); mCenter->SetControlPoint(i, ctrl); } UpdateSnake(); }
//---------------------------------------------------------------------------- void WrigglingSnake::ModifyCurve () { // perturb the snake medial curve float fTime = GetTimeInSeconds(); for (int i = 0; i < m_iNumCtrl; i++) { Vector3f kCtrl = m_pkCenter->GetControlPoint(i); kCtrl.Z() = m_afAmplitude[i]*Mathf::Sin(3.0f*fTime+m_afPhase[i]); m_pkCenter->SetControlPoint(i,kCtrl); } UpdateSnake(); }
//---------------------------------------------------------------------------- void WrigglingSnake::CreateSnakeHead () { VertexFormat* vformat = VertexFormat::Create(2, VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0, VertexFormat::AU_COLOR, VertexFormat::AT_FLOAT3, 0); int vstride = vformat->GetStride(); // Create the snake head as a paraboloid that is attached to the last // ring of vertices on the snake body. These vertices are generated // for t = 1. int numSliceSamples = mSnakeBody->GetNumSliceSamples(); mSlice = new1<Vector3f>(numSliceSamples + 1); // Number of rays (determined by slice samples of tube surface). int numRays = numSliceSamples - 1; // Number of shells less one (your choice, specified in application // constructor). int numShellsM1 = mNumShells - 1; // Generate vertices (positions to be filled in by UpdateSnakeHead). int numVertices = 1 + numRays*numShellsM1; VertexBuffer* vbuffer = new0 VertexBuffer(numVertices, vstride); VertexBufferAccessor vba(vformat, vbuffer); Float3 darkGreen(0.0f, 0.25f, 0.0f); for (int i = 0; i < numVertices; ++i) { vba.Color<Float3>(0, i) = darkGreen; } // Generate triangles. int numTriangles = numRays*(2*numShellsM1 - 1); int numIndices = 3*numTriangles; IndexBuffer* ibuffer = new0 IndexBuffer(numIndices, sizeof(int)); int* indices = (int*)ibuffer->GetData(); for (int r0 = numRays - 1, r1 = 0, t = 0; r1 < numRays; r0 = r1++) { *indices++ = 0; *indices++ = 1 + numShellsM1*r0; *indices++ = 1 + numShellsM1*r1; ++t; for (int s = 1; s < numShellsM1; ++s) { int i00 = s + numShellsM1*r0; int i01 = s + numShellsM1*r1; int i10 = i00 + 1; int i11 = i01 + 1; *indices++ = i00; *indices++ = i10; *indices++ = i11; *indices++ = i00; *indices++ = i11; *indices++ = i01; t += 2; } } mSnakeHead = new0 TriMesh(vformat, vbuffer, ibuffer); mSnakeHead->SetEffectInstance(VertexColor3Effect::CreateUniqueInstance()); mSnakeRoot->AttachChild(mSnakeHead); UpdateSnake(); }