C++ (Cpp) triangle3df Example

Introduction

The c++ (cpp) triangle3df example is extracted from the most popular open source projects, you can refer to the following example for usage.

Programming language: C++ (Cpp)

Class/type: triangle3df

Example#1File: decalscenenode.cppProject: tecan/IrrlichtDemos

void DecalSceneNode::Setup(triangle3df tri,
vector3df intersection){

SColor color(255,255,255,255);

pointA=tri.pointA;
pointB=tri.pointB;
pointC=tri.pointC;

posA=intersection.X;
posB=intersection.Y;
posC=intersection.Z;

trinormal=tri.getNormal();
trinormal=trinormal.normalize();

line3d<f32> line1(pointA, pointB);
vector3df v1 = line1.getVector().normalize();
vector3df v2 = line1.getClosestPoint( pointC );
line3d<f32> line2(v2,pointC);
vector3df v3 = line2.getVector().normalize();

vector3df squarepA=(v1*-basesize)+trinormal*1+(v3*-basesize);
vector3df squarepB=squarepA+(v1*basesize*2);
vector3df squarepC=squarepA+(v1*basesize*2)+(v3*basesize*2);
vector3df squarepD=squarepA+(v3*basesize*2);

squarepA=squarepA+vector3df(posA,posB,posC);
squarepB=squarepB+vector3df(posA,posB,posC);
squarepC=squarepC+vector3df(posA,posB,posC);
squarepD=squarepD+vector3df(posA,posB,posC);

Vertices[0] = S3DVertex(squarepA.X,squarepA.Y,squarepA.Z, 1,0,0,color,1,0);
Vertices[1] = S3DVertex(squarepB.X,squarepB.Y,squarepB.Z, 1,0,0,color,1,1);
Vertices[2] = S3DVertex(squarepC.X,squarepC.Y,squarepC.Z, 1,0,0,color,0,1);
Vertices[3] = S3DVertex(squarepD.X,squarepD.Y,squarepD.Z, 1,0,0,color,0,0);

Box.reset(Vertices[0].Pos);
for (s32 i=1; i<4; ++i)
{
}
}

Example#2File: CNullDriver.cppProject: ChangerR/dream

//! Draws a 3d triangle.
void CNullDriver::draw3DTriangle(const triangle3df& triangle, SColor color)
{
S3DVertex vertices[3];
vertices[0].Pos=triangle.pointA;
vertices[0].Color=color;
vertices[0].Normal=triangle.getNormal().normalize();
vertices[0].TCoords.set(0.f,0.f);
vertices[1].Pos=triangle.pointB;
vertices[1].Color=color;
vertices[1].Normal=vertices[0].Normal;
vertices[1].TCoords.set(0.5f,1.f);
vertices[2].Pos=triangle.pointC;
vertices[2].Color=color;
vertices[2].Normal=vertices[0].Normal;
vertices[2].TCoords.set(1.f,0.f);
const u16 indexList[] = {0,1,2};
drawVertexPrimitiveList(vertices, 3, indexList, 1, EVT_STANDARD, EPT_TRIANGLES, EIT_16BIT);
}