In my opinion CTestSceneNode has two bugs. One in the texture mapping and one in the lightning.
This is a TestSceneNode with some texture and a light shining on it:
Ugly, isn't it?
The texture mapping looks like this:
It's destorted on most sides. Well, this is already an improvement by Dr Bragianos.
Before it looked like this (commented out in the source):
Here 4 sides are not distorted, but 2 are extremly distorted.
The distortion is less noticeable in the first version, but it's still a compromise.
I think it should look like this:
Some sides are still mirrored. But it doesn't matter if there is not text on the texture.
To achieve this I added just 4 vertices with proper uv coords to the existing 8 and reordered the triangles (which are still 12).
This fixed the texture mapping.
The lightning looks like this:
It's ugly because the normal vectors of the vertices are all messed up.
I fixed them so it looks like this:
And if you put it all together then it could look as beautyful as this:
I think now it has deserved the title CubeSceneNode
I'll post the source in a minute...
Improved CTestSceneNode (texture mapping/lightning)
Changes have to be made to CTestSceneNode.cpp and CTestSceneNode.h.
(This is for Irrlich 0.6)
CTestSceneNode.cpp:
change:to:
again CTestSceneNode.cpp:
change:to
again CTestSceneNode.cpp:
change:to
now CTestSceneNode.h:
change:to
That's it. (I hope)
Regards,
jox
(This is for Irrlich 0.6)
CTestSceneNode.cpp:
change:
Code: Select all
u16 u[36] = { 0,2,1, 0,3,2, 1,5,4, 1,2,5, 4,6,7, 4,5,6,
7,3,0, 7,6,3, 3,5,2, 3,6,5, 0,1,4, 0,4,7};
Code: Select all
u16 u[36] = { 0,2,1, 0,3,2, 1,5,4, 1,2,5, 4,6,7, 4,5,6,
7,3,0, 7,6,3, 9,5,2, 9,8,5, 0,11,10, 0,10,7};
change:
Code: Select all
// nicer texture mapping sent in by Dr Andros C Bragianos
Vertices[0] = video::S3DVertex(0,0,0, 1,0,0, video::SColor(255,255,255,255), 0, 0);
Vertices[1] = video::S3DVertex(1,0,0, 0,1,0, video::SColor(255,255,255,255), 1, 0);
Vertices[2] = video::S3DVertex(1,1,0, 0,0,1, video::SColor(255,255,255,255), 1, 1);
Vertices[3] = video::S3DVertex(0,1,0, 1,1,0, video::SColor(255,255,255,255), 0, 1);
/*Vertices[0] = video::S3DVertex(0,0,0, 1,0,0, video::SColor(255,255,255,255), 0, 1);
Vertices[1] = video::S3DVertex(1,0,0, 0,1,0, video::SColor(255,255,255,255), 1, 1);
Vertices[2] = video::S3DVertex(1,1,0, 0,0,1, video::SColor(255,255,255,255), 1, 0);
Vertices[3] = video::S3DVertex(0,1,0, 1,1,0, video::SColor(255,255,255,255), 0, 0);*/
Vertices[4] = video::S3DVertex(1,0,1, 0,1,1, video::SColor(255,255,255,255), 0, 1);
Vertices[5] = video::S3DVertex(1,1,1, 1,0,1, video::SColor(255,255,255,255), 0, 0);
Vertices[6] = video::S3DVertex(0,1,1, 1,1,1, video::SColor(255,255,255,255), 1, 0);
Vertices[7] = video::S3DVertex(0,0,1, 0,0,1, video::SColor(255,255,255,255), 1, 1);
Box.reset(0,0,0);
for (i=0; i<8; ++i)
Code: Select all
Vertices[0] = video::S3DVertex(0,0,0, -1,-1,-1, video::SColor(255,255,255,255), 0, 1);
Vertices[1] = video::S3DVertex(1,0,0, 1,-1,-1, video::SColor(255,255,255,255), 1, 1);
Vertices[2] = video::S3DVertex(1,1,0, 1, 1,-1, video::SColor(255,255,255,255), 1, 0);
Vertices[3] = video::S3DVertex(0,1,0, -1, 1,-1, video::SColor(255,255,255,255), 0, 0);
Vertices[4] = video::S3DVertex(1,0,1, 1,-1, 1, video::SColor(255,255,255,255), 0, 1);
Vertices[5] = video::S3DVertex(1,1,1, 1, 1, 1, video::SColor(255,255,255,255), 0, 0);
Vertices[6] = video::S3DVertex(0,1,1, -1, 1, 1, video::SColor(255,255,255,255), 1, 0);
Vertices[7] = video::S3DVertex(0,0,1, -1,-1, 1, video::SColor(255,255,255,255), 1, 1);
Vertices[8] = video::S3DVertex(0,1,1, -1, 1, 1, video::SColor(255,255,255,255), 0, 1);
Vertices[9] = video::S3DVertex(0,1,0, -1, 1,-1, video::SColor(255,255,255,255), 1, 1);
Vertices[10] = video::S3DVertex(1,0,1, 1,-1, 1, video::SColor(255,255,255,255), 1, 0);
Vertices[11] = video::S3DVertex(1,0,0, 1,-1,-1, video::SColor(255,255,255,255), 0, 0);
Box.reset(0,0,0);
for (i=0; i<12; ++i)
change:
Code: Select all
driver->drawIndexedTriangleList(&Vertices[0], 8, &Indices[0], 12);
Code: Select all
driver->drawIndexedTriangleList(&Vertices[0], 12, &Indices[0], 12);
change:
Code: Select all
video::S3DVertex Vertices[8];
Code: Select all
video::S3DVertex Vertices[12];
Regards,
jox
Making of...
This is how I did it.
I started with the old version (4 sides non-distorted). The red ones are the 4 new vertices 8, 9, 10 and 11 with the same coordinates as 6, 3, 4 and 1. They build the top and bottom sides of the cube with vertices 2, 5, 0 and 7.
The green ones are obsolete. With them 4 sides would have been mirrored. With the red ones only two.
I know, it's just a TestSceneNode. But it was a challenge!
jox
I started with the old version (4 sides non-distorted). The red ones are the 4 new vertices 8, 9, 10 and 11 with the same coordinates as 6, 3, 4 and 1. They build the top and bottom sides of the cube with vertices 2, 5, 0 and 7.
The green ones are obsolete. With them 4 sides would have been mirrored. With the red ones only two.
I know, it's just a TestSceneNode. But it was a challenge!
jox
i did the same sort of thing a few months ago. i modified the custom scenenode to display a well formed textured cube like you did. it wasn't that much to change the code, but to figure out by hand the polygon cordinates was a pain in the neck. it took me nearly a half hour to get the polygons right.
Hehe, cool, thanks for this posting. (added in next version) Now we have a nice cube in the engine. I did not care for that wrong normals and texture coords, because it was simply a test scene node, only to see if something could be rendered. And in the beginning, it wasn't even a cube, it was a single triangle.