Page 1 of 1

normals

Posted: Sun Jan 08, 2006 11:02 am
by Guest
Hello
While going through the create new scene node tutorial, the vertex declaration uses 3 normals per vertex. How do we arrive at these numbers 0,1,0 etc for each vertex. I have tried to create a cube scenenode for learning but my scenenode showed only a square. I changed both the array and indices. Can somebody please show how to do it.

Posted: Tue Jan 10, 2006 6:55 pm
by grassblade
Please somebody help. It was me grassblade just before registering.

Posted: Wed Jan 11, 2006 10:25 am
by bearSoft
maybe this
http://fly.cc.fer.hr/~unreal/theredbook/appendixf.html
-i'm sure i have seen something less longhaired.. hmm
But take a look on it and see if u can use it

Posted: Wed Jan 11, 2006 5:23 pm
by grassblade
Thank you for the link. I will try to study the source code of Irrlicht after reading the link.

Posted: Wed Jan 11, 2006 8:21 pm
by Klasker
Do you know what a normal is?
Vertex normals are used to determine the orientation of surfaces, in order to illuminate them correctly. If your cube node does not display correctly while lighting is turned off, it is not because of the normals.
Note that IVideoDriver::drawIndexedTriangleList wants the vertices of a triangle in clockwise order, or they will be flipped, and your cube will display inside-out.

Posted: Thu Jan 12, 2006 2:45 pm
by grassblade
OK :lol: I got it. I didn't change anything in the triangle list before.Perhaps the problem was with the vertex values given. Here is the cube node I created by modifying the tutorial. If there is any problem with the code please tell me, especially with the bounding box.Is it correct.

Code: Select all


#include <irrlicht.h>

using namespace irr;

#pragma comment(lib, "Irrlicht.lib")


class CSampleSceneNode : public scene::ISceneNode
{

	/*
	First, we declare some member variables. Some space to
	hold data for our tetraeder: The bounding box, 4 vertices, and
	the material of the tetraeder.
	*/
	core::aabbox3d<f32> Box;
	video::S3DVertex Vertices[24];
	video::SMaterial Material;


	/*
	The parameters of the constructor specify the parent of the scene node,
	a pointer to the scene manager, and an id of the scene node.
	In the constructor itself, we call the parent classes constructor,
	set some properties of the material we use to draw the scene nodem and 
	create the 4 vertices of the tetraeder we will draw later.
	*/

public:

	CSampleSceneNode(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id)
		: scene::ISceneNode(parent, mgr, id)
	{
		Material.Wireframe = false;
		Material.Lighting = false;


Vertices[0] = video::S3DVertex(-28.6792, 0.377358, -15.8491,0, 0, -1, video::SColor(255,0,0,0), 0, 0);
Vertices[1] = video::S3DVertex(3.01887, 0.377358, -15.8491,0, 0, -1, video::SColor(0,255,0,0), 0, 0);
Vertices[2] = video::S3DVertex(3.01887, 30.566, -15.8491,0, 0, -1, video::SColor(0,0,255,0), 0, 0);
Vertices[3] = video::S3DVertex( -28.6792, 30.566, -15.8491,0, 0, -1,video::SColor(255,0,0,0), 0, 0);
Vertices[4] = video::S3DVertex( -28.6792, 0.377358, 15.8491,0, 0, 1,video::SColor(0,0,255,0), 0, 0);
Vertices[5] = video::S3DVertex(-28.6792, 30.566, 15.8491,0, 0, 1, video::SColor(0,255,0,0), 0, 0);
Vertices[6] = video::S3DVertex(3.01887, 30.566, 15.8491,0, 0, 1, video::SColor(255,0,0,0), 0, 0);
Vertices[7] = video::S3DVertex( 3.01887, 0.377358, 15.8491,0, 0, 1,video::SColor(0,0,255,0), 0, 0);
Vertices[8] = video::S3DVertex(-28.6792, 0.377358, -15.8491,-1, 0, 0, video::SColor(20,0,255,0), 0, 0);
Vertices[9] = video::S3DVertex(-28.6792, 30.566, -15.8491,-1, 0, 0, video::SColor(255,0,0,0), 0, 0);
Vertices[10] = video::S3DVertex(-28.6792, 30.566, 15.8491,-1, 0, 0, video::SColor(255,255,150,0), 0, 0);
Vertices[11] = video::S3DVertex(-28.6792, 0.377358, 15.8491,-1, 0, 0,video::SColor(30,60,255,0), 0, 0);
Vertices[12] = video::S3DVertex(3.01887, 0.377358, -15.8491,1, 0, 0, video::SColor(158,0,40,0), 0, 0);
Vertices[13] = video::S3DVertex(3.01887, 0.377358, 15.8491,1, 0, 0,video::SColor(200,100,0,0), 0, 0);
Vertices[14] = video::S3DVertex(3.01887, 30.566, 15.8491,1, 0, 0, video::SColor(0,0,130,0), 0, 0);
Vertices[15] = video::S3DVertex( 3.01887, 30.566, -15.8491,1, 0, 0,video::SColor(22,0,50,0), 0, 0);
Vertices[16] = video::S3DVertex(-28.6792, 30.566, -15.8491,0, 1, 0,video::SColor(255,0,255,0), 0, 0);
Vertices[17] = video::S3DVertex(3.01887, 30.566, -15.8491,0, 1, 0, video::SColor(26,0,60,0), 0, 0);
Vertices[18] = video::S3DVertex(3.01887, 30.566, 15.8491,0, 1, 0, video::SColor(120,200,255,0), 0, 0);
Vertices[19] = video::S3DVertex(-28.6792, 30.566, 15.8491,0, 1, 0, video::SColor(255,40,0,0), 0, 0);
Vertices[20] = video::S3DVertex(-28.6792, 0.377358, -15.8491,0, -1, 0, video::SColor(230,0,255,0), 0, 0);
Vertices[21] = video::S3DVertex(-28.6792, 0.377358, 15.8491,0, -1, 0,video::SColor(255,250,24,0), 0, 0);
Vertices[22] = video::S3DVertex( 3.01887, 0.377358, 15.8491,0, -1, 0,video::SColor(255,0,0,0), 0, 0);
Vertices[23] = video::S3DVertex(3.01887, 0.377358, -15.8491,0, -1, 0,video::SColor(0,0,255,0), 0, 0);

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


	virtual void OnPreRender()
	{
		if (IsVisible)
			SceneManager->registerNodeForRendering(this);

		ISceneNode::OnPreRender();
	}


	virtual void render()
	{
		u16 indices[] = {
  0, 2, 1,
    0, 3, 2,
    4, 6, 5,
    4, 7, 6,
    8, 10, 9,
    8, 11, 10,
    12, 14, 13,
    12, 15, 14,
    16, 18, 17,
    16, 19, 18,
    20, 22, 21,
    20, 23, 22
};
		video::IVideoDriver* driver = SceneManager->getVideoDriver();

		driver->setMaterial(Material);
		driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
		driver->drawIndexedTriangleList(&Vertices[0], 24, &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;
	}	
};

/*
That's it. The Scene node is done. Now we simply have to start
the engine, create the scene node and a camera, and look at the result.
*/
int main()
{
	// create engine and camera

	IrrlichtDevice *device =
		createDevice(video::EDT_OPENGL, core::dimension2d<s32>(640, 480), 16, false);

	device->setWindowCaption(L"Custom Scene Node-Cube-Grassblade");

	video::IVideoDriver* driver = device->getVideoDriver();
	scene::ISceneManager* smgr = device->getSceneManager();

	smgr->addCameraSceneNode(0, core::vector3df(0,-40,0), core::vector3df(0,0,0));

	/*
	Create our scene node. Note that it is dropped (->drop()) instantly after 
	we create it. This is possible because the scene manager now takes
	care of it. This is not nessecary, it would also be possible to drop it
	at the end of the program.
	*/

	CSampleSceneNode *myNode = 
		new CSampleSceneNode(smgr->getRootSceneNode(), smgr, 666);

	myNode->drop();

	/*
	To animate something in this boring scene consisting only of one tetraeder,
	and to show, that you now can use your scene node like any other scene
	node in the engine, we add an animator to the scene node, which rotates
	the node a little bit.
	*/

	scene::ISceneNodeAnimator* anim = 
		smgr->createRotationAnimator(core::vector3df(0.8f, 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;
}

[\code]