ok everbody here goes
i tried all of the tutorials and tweeked and modified them for days (much fun) then i started on the custom scene node one
i got rid of the rotation animator and set up the camera to FPS and modifed the movement speed so that one tap of the forward key didn't jump me clear through the model
i then got bored and modefied it to show a cube (took me about 20 minutes to get it to work right)
i then got tired of that and wanted to texture it and died there
i wanted to ask some stuff to clarify what i was thinking
1. in the code
**********************
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 last to number represent the UV coordinates for each vertex, right?
2. in the code
***********************
driver->setMaterial(Material);
***********************
is Material is a pointer to a material loaded into memory (i think i figured out how to load textures )
3. if i load a texture then set it as the active texture and modify the uv coordinates in the vertices will this allow me to texture the triangles that i draw using a custom scene node
once i figure out this i will have to find some *new* way to modify the custom scene node. maybe i will work on doing a terain node. i know one is soon comming out but i would like to see if i could do it.
if you have any other suggestions of what i should try to do to help me better understand irrlicht just tell me.
texturing in a custom scene node
ok i got the texture to work somewhat
the only problem is that it only shows up on two out of the 6 sides
i think it has to do with how the uv coordinates are set up. they are set up with the vertex and some of the polygons have texture coodinates that go from 0-0 or 0-1 or 1-0
i saw this issue in regard to opengl programming and they said define more vetices
if i do this i figured that i would need 24 vertices defined for a square instead of 8
is there anyway to define the uv coordinated with regards to the polygon being drawn and not the vertices
ill try posting my code in a littlebit so you can better see what i am talking about
the only problem is that it only shows up on two out of the 6 sides
i think it has to do with how the uv coordinates are set up. they are set up with the vertex and some of the polygons have texture coodinates that go from 0-0 or 0-1 or 1-0
i saw this issue in regard to opengl programming and they said define more vetices
if i do this i figured that i would need 24 vertices defined for a square instead of 8
is there anyway to define the uv coordinated with regards to the polygon being drawn and not the vertices
ill try posting my code in a littlebit so you can better see what i am talking about
here is my code
**************************************
#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#pragma comment(lib, "Irrlicht.lib")
class CSampleSceneNode : public scene::ISceneNode
{
core::aabbox3d<f32> Box;
video::S3DVertex Vertices[8];
video::SMaterial Material;
public:
CSampleSceneNode(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id,video::ITexture* images)
: scene::ISceneNode(parent, mgr, id)
{
Material.Wireframe = false;
Material.Lighting = false;
Material.Texture1 = images ;
Vertices[0] = video::S3DVertex(5,5,5, 1,1,0, video::SColor(255,255,255,255), 0, 0);
Vertices[1] = video::S3DVertex(5,5,-5, 1,0,0, video::SColor(255,255,255,255), 0, 0);
Vertices[2] = video::S3DVertex(5,-5,5, 0,1,1, video::SColor(255,255,255,255), 0, 1);
Vertices[3] = video::S3DVertex(5,-5,-5, 0,0,1, video::SColor(255,255,255,255), 0, 1);
Vertices[4] = video::S3DVertex(-5,5,5, 0,0,1, video::SColor(255,255,255,255), 1, 0);
Vertices[5] = video::S3DVertex(-5,5,-5, 0,0,1, video::SColor(255,255,255,255), 1, 0);
Vertices[6] = video::S3DVertex(-5,-5,5, 0,0,1, video::SColor(255,255,255,255), 1, 1);
Vertices[7] = video::S3DVertex(-5,-5,-5, 0,0,1, video::SColor(255,255,255,255), 1, 1);
Box.reset(Vertices[0].Pos);
for (s32 i=1; i<8; ++i)
Box.addInternalPoint(Vertices.Pos);
}
virtual void OnPreRender()
{
if (IsVisible)
SceneManager->registerNodeForRendering(this);
ISceneNode::OnPreRender();
}
virtual void render()
{
u16 indices[] = {0,4,6, 0,6,2, 1,3,7, 1,7,5, 0,2,3, 0,3,1, 4,5,7, 4,7,6, 2,6,7, 2,7,3, 0,1,5, 0,5,4};
video::IVideoDriver* driver = SceneManager->getVideoDriver();
driver->setMaterial(Material);
driver->setTransform(video::TS_WORLD, AbsoluteTransformation);
driver->drawIndexedTriangleList(&Vertices[0], 8, &indices[0], 12);
}
virtual const core::aabbox3d<f32>& getBoundingBox() const
{
return Box;
}
virtual s32 getMaterialCount()
{
return 1;
}
virtual video::SMaterial& getMaterial(s32 i)
{
return Material;
}
};
int main()
{
// create engine and camera
IrrlichtDevice *device =
createDevice(video::DT_OPENGL, core::dimension2d<s32>(640, 480), 16, false);
device->setWindowCaption(L"Custom Scene Node Textured");
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
smgr->addCameraSceneNodeFPS(0,50,100);
video::ITexture* images = driver->getTexture("fireball.bmp");
CSampleSceneNode *myNode =
new CSampleSceneNode(smgr->getRootSceneNode(), smgr, 666,images);
myNode->drop();
// scene::ISceneNodeAnimator* anim =
// smgr->createRotationAnimator(core::vector3df(0, 0, 0.8f));
//
// myNode->addAnimator(anim);
// anim->drop();
/*
Now draw everything and finish.
*/
while(device->run())
{
driver->beginScene(true, true, video::SColor(0,100,100,100));
smgr->drawAll();
driver->endScene();
}
device->drop();
return 0;
}
***************************************
**************************************
#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#pragma comment(lib, "Irrlicht.lib")
class CSampleSceneNode : public scene::ISceneNode
{
core::aabbox3d<f32> Box;
video::S3DVertex Vertices[8];
video::SMaterial Material;
public:
CSampleSceneNode(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id,video::ITexture* images)
: scene::ISceneNode(parent, mgr, id)
{
Material.Wireframe = false;
Material.Lighting = false;
Material.Texture1 = images ;
Vertices[0] = video::S3DVertex(5,5,5, 1,1,0, video::SColor(255,255,255,255), 0, 0);
Vertices[1] = video::S3DVertex(5,5,-5, 1,0,0, video::SColor(255,255,255,255), 0, 0);
Vertices[2] = video::S3DVertex(5,-5,5, 0,1,1, video::SColor(255,255,255,255), 0, 1);
Vertices[3] = video::S3DVertex(5,-5,-5, 0,0,1, video::SColor(255,255,255,255), 0, 1);
Vertices[4] = video::S3DVertex(-5,5,5, 0,0,1, video::SColor(255,255,255,255), 1, 0);
Vertices[5] = video::S3DVertex(-5,5,-5, 0,0,1, video::SColor(255,255,255,255), 1, 0);
Vertices[6] = video::S3DVertex(-5,-5,5, 0,0,1, video::SColor(255,255,255,255), 1, 1);
Vertices[7] = video::S3DVertex(-5,-5,-5, 0,0,1, video::SColor(255,255,255,255), 1, 1);
Box.reset(Vertices[0].Pos);
for (s32 i=1; i<8; ++i)
Box.addInternalPoint(Vertices.Pos);
}
virtual void OnPreRender()
{
if (IsVisible)
SceneManager->registerNodeForRendering(this);
ISceneNode::OnPreRender();
}
virtual void render()
{
u16 indices[] = {0,4,6, 0,6,2, 1,3,7, 1,7,5, 0,2,3, 0,3,1, 4,5,7, 4,7,6, 2,6,7, 2,7,3, 0,1,5, 0,5,4};
video::IVideoDriver* driver = SceneManager->getVideoDriver();
driver->setMaterial(Material);
driver->setTransform(video::TS_WORLD, AbsoluteTransformation);
driver->drawIndexedTriangleList(&Vertices[0], 8, &indices[0], 12);
}
virtual const core::aabbox3d<f32>& getBoundingBox() const
{
return Box;
}
virtual s32 getMaterialCount()
{
return 1;
}
virtual video::SMaterial& getMaterial(s32 i)
{
return Material;
}
};
int main()
{
// create engine and camera
IrrlichtDevice *device =
createDevice(video::DT_OPENGL, core::dimension2d<s32>(640, 480), 16, false);
device->setWindowCaption(L"Custom Scene Node Textured");
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
smgr->addCameraSceneNodeFPS(0,50,100);
video::ITexture* images = driver->getTexture("fireball.bmp");
CSampleSceneNode *myNode =
new CSampleSceneNode(smgr->getRootSceneNode(), smgr, 666,images);
myNode->drop();
// scene::ISceneNodeAnimator* anim =
// smgr->createRotationAnimator(core::vector3df(0, 0, 0.8f));
//
// myNode->addAnimator(anim);
// anim->drop();
/*
Now draw everything and finish.
*/
while(device->run())
{
driver->beginScene(true, true, video::SColor(0,100,100,100));
smgr->drawAll();
driver->endScene();
}
device->drop();
return 0;
}
***************************************
I don't know if you're still working on this, but for the sake of you and anyone else running into this problem, here's my thoughts on it.
I started teaching myself OpenGL a while back using tutorials on nehe.gamedev.net and I distinctly remember (maybe incorrectly) that in the lesson involving texturing cubes we had to increase the number of vertices because the UV couldn't be mapped properly to just 8 vertices.. Basically, each face should get it's own 4 vertices. You might be able to get by with fewer, but the texture would probably end up mirrored on some of the faces.
Hope this helps, and if anyone knows anything different on this, I'd be glad to hear it.
I started teaching myself OpenGL a while back using tutorials on nehe.gamedev.net and I distinctly remember (maybe incorrectly) that in the lesson involving texturing cubes we had to increase the number of vertices because the UV couldn't be mapped properly to just 8 vertices.. Basically, each face should get it's own 4 vertices. You might be able to get by with fewer, but the texture would probably end up mirrored on some of the faces.
Hope this helps, and if anyone knows anything different on this, I'd be glad to hear it.