Untitled
unknown
c_cpp
2 years ago
1.3 kB
54
Indexable
void GraphicsDrawTriangle(MeshVertex* verts, float* matrix)
{
if (verts)
{
// Convert generic vertex format to Glide format first
Vertex v[3];
memset(&v, 0, sizeof(v));
for (int i = 0; i < 3; i++)
{
v[i].X = verts[i].Position.X;
v[i].Y = verts[i].Position.Y;
v[i].Z = verts[i].Position.Z;
v[i].tmuvtx[0].U = verts[i].UV.X * 255.0f;
v[i].tmuvtx[0].V = verts[i].UV.Y * 255.0f;
}
Vertex v1, v2, v3;
if (!GraphicsConvertToWindowSpace(&v[0], &v1, matrix))
return;
if (!GraphicsConvertToWindowSpace(&v[1], &v2, matrix))
return;
if (!GraphicsConvertToWindowSpace(&v[2], &v3, matrix))
return;
grDrawTriangle(&v1, &v2, &v3);
}
}
void GraphicsDrawMeshEx(Mesh* mesh, Material* material, float* matrix)
{
if (mesh && mesh->NumVertices > 0)
{
// Setup render state
GraphicsSetupTextureStage(material);
for (int i = 0; i < mesh->NumVertices / 3; i++)
{
GraphicsDrawTriangle(&mesh->Vertices[i * 3], matrix);
}
}
}
...
float matrix[16];
MatrixIdentity((float*)&matrix);
MatrixRotationAngle((float*)&matrix, 0, rot, 0);
MatrixTranslation((float*)&matrix, rot, 0, 15);
MatrixPerspective((float*)&matrix, 90 * 0.0174533f, 640.0f / 480, 1, 100);
GraphicsDrawMeshEx(mesh, &mat, (float*)&matrix);Editor is loading...
Leave a Comment