Here my Block code:
Code: Select all
#include "block.hpp"
#include <stdio.h>
Block::Block ( ): ISceneNode(0,0,0)
{
type = 0;
size = 0.0;
color = SColor(0,0,0,0);
setVisible(false);
material.Lighting = false;
}
Block::Block ( int type, float size, SColor c, ISceneNode * parent, ISceneManager * smgr, s32 id ): ISceneNode(parent, smgr, id)
{
init(type, size, c, vector3df(), parent, smgr, id);
}
void Block::init (int type, float size, SColor c, vector3df p, ISceneNode * parent, ISceneManager * smgr, s32 id )
{
this->type = type;
this->size = size;
color = c;
setVisible(false);
initVertex();
setPosition(p);
setParent(parent);
setSceneManager(smgr);
}
void Block::initVertex ( )
{
vector3df p, q;
vector3df n;
// vertices' position
float v[24][3] =
{
// face 0
{size/2.0f, size/2.0f, size/2.0f}, // vertice 0
{size/2.0f, size/2.0f, -size/2.0f}, // vertice 1
{-size/2.0f, size/2.0f, -size/2.0f}, // vertice 2
{-size/2.0f, size/2.0f, size/2.0f}, // vertice 3
// face 1
{size/2.0f, -size/2.0f, size/2.0f}, // vertice 4 (4)
{size/2.0f, -size/2.0f, -size/2.0f}, // vertice 5 (5)
{size/2.0f, size/2.0f, -size/2.0f}, // vertice 1 (6)
{size/2.0f, size/2.0f, size/2.0f}, // vertice 0 (7)
// face 2
{size/2.0f, size/2.0f, -size/2.0f}, // vertice 1 (8)
{size/2.0f, -size/2.0f, -size/2.0f}, // vertice 5 (9)
{-size/2.0f, -size/2.0f, -size/2.0f}, // vertice 6 (10)
{-size/2.0f, size/2.0f, -size/2.0f}, // vertice 2 (11)
// face 3
{-size/2.0f, size/2.0f, size/2.0f}, // vertice 3 (12)
{-size/2.0f, size/2.0f, -size/2.0f}, // vertice 2 (13)
{-size/2.0f, -size/2.0f, -size/2.0f}, // vertice 6 (14)
{-size/2.0f, -size/2.0f, size/2.0f}, // vertice 7 (15)
// face 4
{size/2.0f, -size/2.0f, size/2.0f}, // vertice 4 (16)
{size/2.0f, size/2.0f, size/2.0f}, // vertice 0 (17)
{-size/2.0f, size/2.0f, size/2.0f}, // vertice 3 (18)
{-size/2.0f, -size/2.0f, size/2.0f}, // vertice 7 (19)
// face 5
{size/2.0f, -size/2.0f, -size/2.0f}, // vertice 5 (20)
{size/2.0f, -size/2.0f, size/2.0f}, // vertice 4 (21)
{-size/2.0f, -size/2.0f, size/2.0f}, // vertice 7 (22)
{-size/2.0f, -size/2.0f, -size/2.0f}, // vertice 6 (23)
};
// coordenadas da textura
float coord[4][2] =
{
{0,0},
{1,0},
{1,1},
{0,1},
};
for (int i = 0; i < 24; i++)
{
p.X = v[i][0];
p.Y = v[i][1];
p.Z = v[i][2];
q = p;
n = p.normalize();
vertex[i] = S3DVertex(q, n, color, vector2d<f32>(coord[i % 4][0],coord[i % 4][1]));
}
box.reset(vertex[0].Pos);
for (int i = 0; i < 24; i++)
box.addInternalPoint(vertex[i].Pos);
}
int Block::getType ( )
{
return type;
}
void Block::setType ( int t )
{
type = t;
}
void Block::setVertexPosition ( vector3df p, int i )
{
if (i < 0 || i >= 8)
return;
printf("Rever função\n");
vector3df q = p, r = vertex[i].Pos;
q.normalize();
vertex[i].Pos = p;
vertex[i].Normal = q;
if (r.X != p.X || r.Y != p.Y || r.Z != p.Z)
change = true;
box.reset(vertex[0].Pos);
for (int i = 0; i < 8; i++)
box.addInternalPoint(vertex[i].Pos);
}
void Block::setColor ( SColor c, int i )
{
int j;
if (i < 0 || i >= 8)
{
for (j = 0; j < 8; j++)
vertex[j].Color = c;
}
else
{
vertex[i].Color = c;
}
}
const aabbox3d<f32> & Block::getBoundingBox ( ) const
{
return box;
}
void Block::OnRegisterSceneNode ( )
{
if (IsVisible)
SceneManager->registerNodeForRendering(this);
ISceneNode::OnRegisterSceneNode();
}
void Block::render ( )
{
const u16 indices[] =
{
0,1,2, 2,3,0, // face 0
4,5,6, 6,7,4, // face 1
8,9,10, 10,11,8, // face 2
12,13,14, 14,15,12, // face 3
16,17,18, 18,19,16, // face 4
20,21,22, 22,23,20, // face 5
};
IVideoDriver * driver = SceneManager->getVideoDriver();
driver->setMaterial(material);
driver->setTransform(ETS_WORLD, AbsoluteTransformation);
driver->drawVertexPrimitiveList(&vertex[0], 24, &indices[0], 12);
}
u32 Block::getMaterialCount ( )
{
return 1;
}
SMaterial& Block::getMaterial ( u32 i )
{
return material;
}
I searched the forum and I read about anti/clockwise vertex and I don't make idea about this
I know draw polygons in opengl and I don't can understand how this works in irrlicht.
EDIT: YES!!! Now I can draw the block, but still have the question above.