Custom Scene Node

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
EzikialBasix
Posts: 4
Joined: Wed May 24, 2006 7:23 pm

Custom Scene Node

Post by EzikialBasix »

Hey yall,

I just started using Irrlicht a few weeks ago, and I'm impressed with it's simplistic power.

Anyways, my problem is creating a sky-dome and having access to vertex color data. I tried loading a 3DS file into irrlicht, but I couldn't figure out if I was able to change vertex color on those.

Next I tried making my own dome shape using a custom scene node. I'm not very experienced in creating objects from code. My dome wont even appear because I don't know how to calculate the indices? :(

Code: Select all

void ESphere::CreateSky(int nSubdivide, float fVertSweep, float fRadius, float fHeightScale, irr::core::vector3df &vPosition,
		irr::video::SColor &cDayColor, irr::video::SColor &cNightColor)
{
	// Find how many vertices are in the dome
	m_nVerts = 1 + 4 * nSubdivide * nSubdivide;

	// Assign the previoud number to the array of vertices
	m_Verts = new irr::video::S3DVertex[ m_nVerts ];

	// Adjust radius based on vertical sweep
	float fRadAngle = (90 - fVertSweep) / 180 * PI;
	fRadius /= cos (fRadAngle);

	// Compute Z Adjustments
	float fZAdj = fRadius * sin(fRadAngle);

	// Create the very top vertex
	m_Verts[0].Pos.X = 0;
	m_Verts[0].Pos.Y = 0;
	m_Verts[0].Pos.Z = ((fRadius - fZAdj) * fHeightScale);
	m_Verts[0].Pos += vPosition;

	// Calculate one angular section of the dome
	float fHorzSweep = 90.0 / nSubdivide;

	fVertSweep /= nSubdivide;

	int nVertex = 1;
	for (int i = 0; i < nSubdivide; i++)
	{

		//
		// Compute the vertex that will be rotated around to make a ring
		//

		irr::core::vector3df vPoint(0, 0, fRadius);
		irr::core::matrix4 m;

		m.setTranslation(irr::core::vector3df(0, fVertSweep * (i + 1), 0));
		//Multiply wtf?
		//m. (vPoint, vPoint);
		vPoint.Z = (vPoint.Z - fZAdj) * fHeightScale;

		//
		// Loop through the ring creating the points
		//

		for (int j = 0; j < nSubdivide * 4; j++)
		{

			//
			// Map the point
			//

			m.setTranslation(irr::core::vector3df(fHorzSweep * j, 0, 0));
			//m .PreMultiply (vPoint, m_pVertex [nVertex] .vVertex);
			m_Verts[nVertex].Pos += vPosition;
			nVertex++;
		}
	}
}
I'm learning from code from GameTutorials.com if it looks familiar. Please help. All I need is a dome where I can dynamically change vertices colors on the fly.


Thanks for your input/help in advance.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Code: Select all

  // load the mesh from file
  IAnimatedMesh* sky = SceneManager->getMesh("media/skydome.3ds");

  // change the vertex colors of the static sky mesh to solid grey
  SceneManager->getMeshManipulator()->setVertexColors(sky->getMesh(0), video::SColor(255, 128, 128, 128));
If you want to set different colors for the vertices, you might want to have a look at the CMeshManipulator::setVertexColors() implementation. It will show you everything you need to know to manipulate the vertex colors.

Travis
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

If you want to create a dome you should probably start with creating a correct mesh first, and later on turn it into a skydome. So first step should be correct calculation of vertex positions and indices. Use a mesh buffer for that purpose instead of a C array. Then add the mesh buffer to a mesh and finally add the mesh to a scene node. This scene node can be rendered with Irrlicht techniques such that you don't have to bother with setting up render methods.
I think that vertex positions can be calculated without matrix manipulations. Check this one out (only the central position calculation) http://www.ogre3d.org/wiki/index.php/ManualSphereMeshes
EzikialBasix
Posts: 4
Joined: Wed May 24, 2006 7:23 pm

Post by EzikialBasix »

does CMeshManipulator::setVertexColors() allow to change vertex colors based on height? Thats really what I need to do.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

No. Read the documentation, or at the very least read my post. Let me repeat myself... If you need to set different colors for the vertices, you might want to look at the CMeshManipulator::setVertexColors() implementation.

It is not difficult to calculate a vertex color based on its position in a skydome mesh. If you want a realistic looking skydome, you will make it brighter closer to the sun, not just at the top of the dome.

Travis
Post Reply