//---------------------------------------------------------------------------- Polysegment* BSplineFitContinuous::ReducedPolysegment (int numCtrlPoints, Vector3d* ctrlPoints, double fraction) { int numLSCtrlPoints; Vector3d* lsCtrlPoints; BSplineReduction3d(numCtrlPoints, ctrlPoints, mDegree, fraction, numLSCtrlPoints, lsCtrlPoints); BSplineCurve3d spline(numLSCtrlPoints, lsCtrlPoints, mDegree, false, true); delete1(lsCtrlPoints); VertexFormat* vformat = VertexFormat::Create(2, VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0, VertexFormat::AU_COLOR, VertexFormat::AT_FLOAT3, 0); int vstride = vformat->GetStride(); VertexBuffer* vbuffer = new0 VertexBuffer(numCtrlPoints, vstride); VertexBufferAccessor vba(vformat, vbuffer); Float3 blue(0.0f, 0.0f, 1.0f); for (int i = 0; i < numCtrlPoints; ++i) { double t = i/(double)numCtrlPoints; Vector3d pos = spline.GetPosition(t); vba.Position<Float3>(i) = Float3((float)pos[0], (float)pos[1], (float)pos[2]); vba.Color<Float3>(0, i) = blue; } Polysegment* segment = new0 Polysegment(vformat, vbuffer, true); segment->SetEffectInstance(VertexColor3Effect::CreateUniqueInstance()); return segment; }
//---------------------------------------------------------------------------- void Polysegments::CreateScene () { mScene = new0 Node(); VertexFormat* vformat = VertexFormat::Create(2, VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0, VertexFormat::AU_COLOR, VertexFormat::AT_FLOAT3, 0); int vstride = vformat->GetStride(); VertexBuffer* vbuffer = new0 VertexBuffer(128, vstride); VertexBufferAccessor vba(vformat, vbuffer); for (int i = 0; i < vba.GetNumVertices(); ++i) { vba.Position<Float3>(i) = Float3(Mathf::SymmetricRandom(), Mathf::SymmetricRandom(), Mathf::SymmetricRandom()); vba.Color<Float3>(0, i) = Float3(Mathf::UnitRandom(), Mathf::UnitRandom(), Mathf::UnitRandom()); } mPolysegment = new0 Polysegment(vformat, vbuffer, true); mPolysegment->SetEffectInstance( VertexColor3Effect::CreateUniqueInstance()); mScene->AttachChild(mPolysegment); }
//---------------------------------------------------------------------------- Polysegment* PolyhedronDistance::CreateSegment () { VertexFormat* vformat = VertexFormat::Create(2, VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0, VertexFormat::AU_COLOR, VertexFormat::AT_FLOAT3, 0); int vstride = vformat->GetStride(); VertexBuffer* vbuffer = new0 VertexBuffer(2, vstride); VertexBufferAccessor vba(vformat, vbuffer); vba.Position<Vector3f>(0) = Vector3f::ZERO; vba.Position<Vector3f>(1) = Vector3f::UNIT_X; vba.Color<Float3>(0, 0) = Float3(1.0f, 1.0f, 1.0f); vba.Color<Float3>(0, 1) = Float3(1.0f, 1.0f, 1.0f); Polysegment* segment = new0 Polysegment(vformat, vbuffer, true); segment->SetEffectInstance(VertexColor3Effect::CreateUniqueInstance()); return segment; }
//---------------------------------------------------------------------------- void IntersectInfiniteCylinders::CreateScene () { mScene = new0 Node(); mWireState = new0 WireState(); mRenderer->SetOverrideWireState(mWireState); VertexFormat* vformat = VertexFormat::Create(2, VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0, VertexFormat::AU_COLOR, VertexFormat::AT_FLOAT3, 0); int vstride = vformat->GetStride(); StandardMesh sm(vformat); VertexBufferAccessor vba; int i; // Create the canonical cylinder. mCylinder0 = sm.Cylinder(32, 128, mRadius0, mHeight, true); mScene->AttachChild(mCylinder0); mVisible.Insert(mCylinder0); vba.ApplyTo(mCylinder0); for (i = 0; i < vba.GetNumVertices(); ++i) { vba.Color<Float3>(0, i) = Float3(0.5f, 0.0f, 0.0f); } mCylinder0->SetEffectInstance(VertexColor3Effect::CreateUniqueInstance()); // Create the other cylinder. mCylinder1 = sm.Cylinder(32, 128, mRadius1, mHeight, true); mScene->AttachChild(mCylinder1); mVisible.Insert(mCylinder1); vba.ApplyTo(mCylinder1); for (i = 0; i < vba.GetNumVertices(); ++i) { vba.Color<Float3>(0, i) = Float3(0.0f, 0.0f, 0.5f); } mCylinder1->SetEffectInstance(VertexColor3Effect::CreateUniqueInstance()); mCylinder1->LocalTransform.SetRotate(HMatrix(AVector::UNIT_X, -mAngle)); mCylinder1->LocalTransform.SetTranslate(APoint(mC0, 0.0f, 0.0f)); // Create the intersection curve. const float minTheta = 2.0f*Mathf::PI/3.0f; const float maxTheta = 4.0f*Mathf::PI/3.0f; float theta, cs, sn, t, tmp, discr; VertexBuffer* vbuffer = new0 VertexBuffer(1024, vstride); mCurve0 = new0 Polysegment(vformat, vbuffer, true); mScene->AttachChild(mCurve0); vba.ApplyTo(mCurve0); int numPoints = vba.GetNumVertices(); float multiplier = (maxTheta - minTheta)/(float)(numPoints - 1); for (i = 0; i < numPoints; ++i) { theta = minTheta + multiplier*i; cs = Mathf::Cos(theta); sn = Mathf::Sin(theta); tmp = mC0 + mRadius1*cs; discr = Mathf::FAbs(mRadius0*mRadius0 - tmp*tmp); t = (-mRadius1*mW2*sn - Mathf::Sqrt(discr))/mW1; Float3& position = vba.Position<Float3>(i); position[0] = mC0 + mRadius1*cs; position[1] = +mRadius1*sn*mW2 + t*mW1; position[2] = -mRadius1*sn*mW1 + t*mW2; vba.Color<Float3>(0, i) = Float3(0.0f, 0.5f, 0.0f); } mCurve0->SetEffectInstance(VertexColor3Effect::CreateUniqueInstance()); mVisible.Insert(mCurve0); vbuffer = new0 VertexBuffer(1024, vstride); mCurve1 = new0 Polysegment(vformat, vbuffer, true); mScene->AttachChild(mCurve1); vba.ApplyTo(mCurve1); numPoints = vba.GetNumVertices(); multiplier = (maxTheta - minTheta)/(float)(numPoints - 1); for (i = 0; i < numPoints; ++i) { theta = minTheta + multiplier*i; cs = Mathf::Cos(theta); sn = Mathf::Sin(theta); tmp = mC0 + mRadius1*cs; discr = Mathf::FAbs(mRadius0*mRadius0 - tmp*tmp); t = (-mRadius1*mW2*sn + Mathf::Sqrt(discr))/mW1; Float3& position = vba.Position<Float3>(i); position[0] = mC0 + mRadius1*cs; position[1] = +mRadius1*sn*mW2 + t*mW1; position[2] = -mRadius1*sn*mW1 + t*mW2; vba.Color<Float3>(0, i) = Float3(0.0f, 0.5f, 0.0f); } mCurve1->SetEffectInstance(VertexColor3Effect::CreateUniqueInstance()); mVisible.Insert(mCurve1); }
//---------------------------------------------------------------------------- void FreeFormDeformation::CreatePolylines () { // Generate the polylines that connect adjacent control points. mPolysegmentRoot = new0 Node(); mTrnNode->AttachChild(mPolysegmentRoot); VertexColor3Effect* effect = new0 VertexColor3Effect(); VertexFormat* vformat = VertexFormat::Create(2, VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0, VertexFormat::AU_COLOR, VertexFormat::AT_FLOAT3, 0); int vstride = vformat->GetStride(); VertexBufferAccessor vba; VertexBuffer* vbuffer; Polysegment* segment; int i0, i1, i2; for (i0 = 0; i0 < mQuantity; ++i0) { for (i1 = 0; i1 < mQuantity; ++i1) { for (i2 = 0; i2 < mQuantity-1; ++i2) { vbuffer = new0 VertexBuffer(2, vstride); vba.ApplyTo(vformat, vbuffer); vba.Position<Vector3f>(0) = mVolume->GetControlPoint(i0, i1, i2); vba.Position<Vector3f>(1) = mVolume->GetControlPoint(i0, i1, i2+1); vba.Color<Float3>(0, 0) = Float3(0.0f, 0.0f, 0.75f); vba.Color<Float3>(0, 1) = Float3(0.0f, 0.0f, 0.75f); segment = new0 Polysegment(vformat, vbuffer, true); segment->SetEffectInstance(effect->CreateInstance()); mPolysegmentRoot->AttachChild(segment); } } for (i2 = 0; i2 < mQuantity; ++i2) { for (i1 = 0; i1 < mQuantity-1; ++i1) { vbuffer = new0 VertexBuffer(2, vstride); vba.ApplyTo(vformat, vbuffer); vba.Position<Vector3f>(0) = mVolume->GetControlPoint(i0, i1, i2); vba.Position<Vector3f>(1) = mVolume->GetControlPoint(i0, i1+1, i2); vba.Color<Float3>(0, 0) = Float3(0.0f, 0.75f, 0.0f); vba.Color<Float3>(0, 1) = Float3(0.0f, 0.75f, 0.0f); segment = new0 Polysegment(vformat, vbuffer, true); segment->SetEffectInstance(effect->CreateInstance()); mPolysegmentRoot->AttachChild(segment); } } } for (i0 = 0; i0 < mQuantity-1; ++i0) { for (i1 = 0; i1 < mQuantity; ++i1) { for (i2 = 0; i2 < mQuantity; ++i2) { vbuffer = new0 VertexBuffer(2, vstride); vba.ApplyTo(vformat, vbuffer); vba.Position<Vector3f>(0) = mVolume->GetControlPoint(i0, i1, i2); vba.Position<Vector3f>(1) = mVolume->GetControlPoint(i0+1, i1, i2); vba.Color<Float3>(0,0) = Float3(0.75f, 0.0f, 0.0f); vba.Color<Float3>(0,1) = Float3(0.75f, 0.0f, 0.0f); segment = new0 Polysegment(vformat, vbuffer, true); segment->SetEffectInstance(effect->CreateInstance()); mPolysegmentRoot->AttachChild(segment); } } } }