CSampleSceneNode(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id) : scene::ISceneNode(parent, mgr, id) { Descriptor = mgr->getVideoDriver()->getVertexDescriptor(0); VertexBuffer = new scene::CVertexBuffer<video::S3DVertex>(); IndexBuffer = new scene::CIndexBuffer(video::EIT_16BIT); MeshBuffer = new scene::CMeshBuffer<video::S3DVertex>(Descriptor); Material.Wireframe = false; Material.Lighting = false; video::S3DVertex Vertices[4]; Vertices[0] = video::S3DVertex(0,0,10, 1,1,0, video::SColor(255,0,255,255), 0, 1); Vertices[1] = video::S3DVertex(10,0,-10, 1,0,0, video::SColor(255,255,0,255), 1, 1); Vertices[2] = video::S3DVertex(0,20,0, 0,1,1, video::SColor(255,255,255,0), 1, 0); Vertices[3] = video::S3DVertex(-10,0,-10, 0,0,1, video::SColor(255,0,255,0), 0, 0); for (s32 i = 0; i<4; ++i) VertexBuffer->addVertex(&Vertices[i]); /* Indices into the 'Vertices' array. A triangle needs 3 vertices so you have to pass the 3 corresponding indices for each triangle to tell which of the vertices should be used for it. */ IndexBuffer->addIndex(0); IndexBuffer->addIndex(2); IndexBuffer->addIndex(3); IndexBuffer->addIndex(2); IndexBuffer->addIndex(1); IndexBuffer->addIndex(3); IndexBuffer->addIndex(1); IndexBuffer->addIndex(0); IndexBuffer->addIndex(3); IndexBuffer->addIndex(2); IndexBuffer->addIndex(0); IndexBuffer->addIndex(1); /* Append Vertex and Index buffers to the Mesh buffer. */ MeshBuffer->setVertexBuffer(VertexBuffer, 0); MeshBuffer->setIndexBuffer(IndexBuffer); /* The Irrlicht Engine needs to know the bounding box of a scene node. It will use it for automatic culling and other things. Hence, we need to create a bounding box from the 4 vertices we use. If you do not want the engine to use the box for automatic culling, and/or don't want to create the box, you could also call irr::scene::ISceneNode::setAutomaticCulling() with irr::scene::EAC_OFF. */ Box.reset(Vertices[0].Pos); for (s32 i=1; i<4; ++i) Box.addInternalPoint(Vertices[i].Pos); }
CSampleSceneNode(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id) : scene::ISceneNode(parent, mgr, id) { Material.Wireframe = false; Material.Lighting = false; Vertices[0] = video::S3DVertex(0,0,10, 1,1,0, video::SColor(255,0,255,255), 0, 1); Vertices[1] = video::S3DVertex(10,0,-10, 1,0,0, video::SColor(255,255,0,255), 1, 1); Vertices[2] = video::S3DVertex(0,20,0, 0,1,1, video::SColor(255,255,255,0), 1, 0); Vertices[3] = video::S3DVertex(-10,0,-10, 0,0,1, video::SColor(255,0,255,0), 0, 0); /* The Irrlicht Engine needs to know the bounding box of a scene node. It will use it for automatic culling and other things. Hence, we need to create a bounding box from the 4 vertices we use. If you do not want the engine to use the box for automatic culling, and/or don't want to create the box, you could also call irr::scene::ISceneNode::setAutomaticCulling() with irr::scene::EAC_OFF. */ Box.reset(Vertices[0].Pos); for (s32 i=1; i<4; ++i) Box.addInternalPoint(Vertices[i].Pos); }
CSampleSceneNode(scene::ISceneNode* parent, scene::ISceneManager *mgr, s32 id) :scene::ISceneNode(parent, mgr, id) { Material.Wireframe = false; Material.Lighting = false; Vertices[0] = video::S3DVertex(0,0,10, 1,1,0, video::SColor(255,0,255,255), 0, 1); Vertices[1] = video::S3DVertex(10,0,-10, 1,0,0, video::SColor(255,255,0,255), 1, 1); Vertices[2] = video::S3DVertex(0,20,0, 0,1,1, video::SColor(255,255,255,0), 1, 0); Vertices[3] = video::S3DVertex(-10,0,-10, 0,0,1, video::SColor(255,0, 255, 0), 0, 0); Box.reset(Vertices[0].Pos); for (s32 i=1; i<4; ++i) { Box.addInternalPoint(Vertices[i].Pos); } }
void BuildCylinder( core::array<video::S3DVertex>& vertexArray, core::array<u16>& indexArray, core::aabbox3d<f32>& boundingBox, f32 height, f32 startRadius, f32 endRadius, s32 radialSegments, const core::matrix4& transform, f32 startTCoordY = 0.0f, f32 endTCoordY = 1.0f, video::SColor startColor = video::SColor(255,255,255,255), video::SColor endColor = video::SColor(255,255,255,255) ) { u16 vertexIndex = vertexArray.size(); s32 radialVertices = radialSegments + 1; // We want one additional vertex to make the texture wraps correctly // Place bottom cap for ( s32 i=0; i<radialVertices; i++ ) { f32 angle = 2.0f * core::PI * i / (f32)( radialSegments ); core::vector3df dir; dir.X = cos(angle); dir.Z = sin(angle); core::vector3df pos; core::vector3df normal = dir; pos = dir * startRadius; // Place bottom vertex transform.transformVect( pos ); transform.rotateVect( normal ); core::vector2df tcoord; tcoord.X = (f32)( i ) / (f32)( radialSegments ); tcoord.Y = startTCoordY; vertexArray.push_back( video::S3DVertex( pos, normal, startColor, tcoord ) ); boundingBox.addInternalPoint( pos ); } // Place top cap and indices for ( s32 i=0; i<radialVertices; i++ ) { f32 angle = 2.0f * core::PI * i / (f32)( radialSegments ); core::vector3df dir; dir.X = cos(angle); dir.Z = sin(angle); core::vector3df normal = dir; core::vector3df pos = dir * endRadius; pos.Y = height; transform.transformVect( pos ); transform.rotateVect( normal ); core::vector2df tcoord; tcoord.X = (f32)( i ) / (f32)( radialSegments ); tcoord.Y = endTCoordY; vertexArray.push_back( video::S3DVertex( pos, normal, endColor, tcoord ) ); boundingBox.addInternalPoint(pos); // Add indices if ( i != radialVertices-1 ) { s32 i2 = (i+1)%radialVertices; // Place the indices indexArray.push_back ( vertexIndex + i ); indexArray.push_back ( vertexIndex + radialVertices + i ); indexArray.push_back ( vertexIndex + i2 ); indexArray.push_back ( vertexIndex + radialVertices + i ); indexArray.push_back ( vertexIndex + radialVertices + i2 ); indexArray.push_back ( vertexIndex + i2 ); } } }
CSampleSceneNode(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id ,core::vector3d<float>P[] ,core::vector3d<float>Ups[] ,short ncontrolpts) : scene::ISceneNode(parent, mgr, id) { Material.Wireframe = true; Material.Lighting = false; std::vector<core::vector3d<float> >p; core::vector3d<float> basetri[3] = {{-0.5,0,0},{0.5,0,0},{0.25,-0.25,0}}; core::vector3d<float> rottri[2]; core::vector3d<float> A,B,C; float ABdot,BCdot,ABmag,BCmag; float cosABang,cosBCang,ABang,BCang,angtotal; //calculate angle of rotation { A=P[1]-P[0]; B=P[2]-P[1]; C=P[3]-P[2]; ABdot=A.dotProduct(B); BCdot=B.dotProduct(C); ABmag=A.getLength()*B.getLength(); BCmag=B.getLength()*C.getLength(); cosABang=ABdot/ABmag; cosBCang=BCdot/BCmag; ABang=acos(cosABang); BCang=acos(cosBCang); angtotal=ABang+BCang; } //set up the interpolation of the spline const float pi=3.1415927; float angdegrees=angtotal*180/pi; float npoints=angdegrees/12; nverts=(s16)(npoints+0.5); float tstep=1/std::max((float)nverts,1.0f); core::vector3d<float> curpt; core::vector3d<float> curup; //print some info before setting the interppolation points std::cout<<"total curve angle: "<<angtotal<<std::endl; std::cout<<"; steps: "<<nverts<<std::endl; //interpolate the spline p.clear(); for(float t=0.0;t<1.0+tstep;t+=tstep) { float scale[4]= { pow(1.0f-t,3) ,3*pow(1.0f-t,2)*t ,3*(1.0f-t)*pow(t,2) ,pow(t,3) }; curup= scale[0]*Ups[0] //pow(1-t,3)*P[0] + scale[1]*Ups[1] //3*pow(1-t,2)*t*P[1] + scale[2]*Ups[2] //3*(1-t)*pow(t,2)*P[2] + scale[3]*Ups[3]; //pow(t,3)*P[3] curpt= scale[0]*P[0] //pow(1-t,3)*P[0] + scale[1]*P[1] //3*pow(1-t,2)*t*P[1] + scale[2]*P[2] //3*(1-t)*pow(t,2)*P[2] + scale[3]*P[3]; //pow(t,3)*P[3] //=(1-$A11)^3*B$4 + 3*(1-$A11)^2*$A11*B$5 //+ 3*(1-$A11)*$A11^2*B$6 + $A11^3*B$7 p.push_back(curpt); } for(int i=0;i<p.size();i++) { std::cout<<"interpolation - pt "<<i<<" - "; std::cout<<"("<<p[i].X<<","<<p[i].Y<<","<<p[i].Z<<")"<<std::endl; Vertices[i] = video::S3DVertex(p[i].X,p[i].Y,p[i].Z, 1,1,0, video::SColor(255,0,0,255), 0, 1); } /* The Irrlicht Engine needs to know the bounding box of a scene node. It will use it for automatic culling and other things. Hence, we need to create a bounding box from the 4 vertices we use. If you do not want the engine to use the box for automatic culling, and/or don't want to create the box, you could also call irr::scene::ISceneNode::setAutomaticCulling() with irr::scene::EAC_OFF. */ Box.reset(Vertices[0].Pos); for (s32 i=1; i<nverts; ++i) Box.addInternalPoint(Vertices[i].Pos); }