Setting up camera for a hemicube/hemisphere

Started by
2 comments, last by spek 17 years, 8 months ago
Hi, I'm trying to generate a lightmap. For each patch that collects light, I must render the surrounding area with a hemicube or hemisphere. I know the patch position and its direction (~the normal from its parent polygon). However, I have problem with setting up the camera properly:

	// FOV
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity;
	gluPerspective(90, 1, 0.01, 1000);                  

	// Calculate target position where the camera
	// should look at. This is the center of hemicube
	// front-face
	target.x = pos.x + patch.normal.x;
	target.y = pos.y + patch.normal.y;
	target.z = pos.z + patch.normal.z;

	// Orientation
	glMatrixMode(GL_MODELVIEW);

	glLoadIdentity;
	gluLookAt(  pos.x, pos.y, pos.z
                    target.x, target.y, target.z,
		    0.0, +1.0, 0.0 );
So, this code should place and point the camera towards the hemicube front-face. But this doesn't work. And how to rotate to the left/right/up/down side? Greetings, Rick
Advertisement
in what way doesnt it work, perhaps the normals are incorrect draw them onscreen.
also u might wanna try changing pos to be pos+normal*0.1 (because it might be embedded in a triangle)
Um a hemicube hemisphere has absolutely nothing to do with a lightmap. The first step is to understand what you are trying to do.
"Um a hemicube hemisphere has absolutely nothing to do with a lightmap"
It does if you want to gather light for a radiosity lightmap. I know what I'm doing, don't worry.

The problem is that I'm not looking into the right directions. I take 5 snapshots (forward, left, right, up and down). I save them as bitmaps, just to test their content. From what I see in the shots, the camera is either facing or placed at the wrong point. In some shots I don't see nothing, while I should see something at least in one of the 5 shots.

Their is something with the parameters I use in glLookAt. I tried another way. Normally I use this code to create cubeMaps:
procedure placeCamera( const dir, pos : vector3f;                       const rotInd   : integer );const	cRot : array [0..5, 0..1] of float = (                     (   0,   0), (   0, 180),   // PX, NX                     ( -90,  90), (  90,  90),   // PY, NY                     (   0,  90), (   0, -90));  // PZ, NZbegin	glMatrixMode(GL_PROJECTION);	glLoadIdentity;	gluPerspective(90, 1, 0.01, 1000);	// Setup appropriate orientation	glMatrixMode(GL_MODELVIEW);	glLoadIdentity; 	gluLookAt(	 0,  0, 0,			+1,  0, 0,			 0, +1, 0 ); 	glRotatef(cRot[rotInd][0], 0.0, 0.0, 1.0); // Rotate around Z	glRotatef(cRot[rotInd][1], 0.0, 1.0, 0.0); // then rotate around Y	glTranslatef( -pos[0], -pos[1], -pos[2]);                  end; // placeCamera

Sorry, it's Delphi code. In this case the camera is at 0,0,0 and the world surrounding it, is shifted. The "rotInd" parameter is a number between 0 and 5, and is used for rotating to a face (left, right, forward, etc.).

Now I see stuff, but I don't know how to add rotate to the direction of the patch normal (the "dir" parameter). When rendering "forward", the camera direction is {0,0,+1}, but it should be {dir[0],dir[1],dir[2]} I guess.

Yeah, my vector math isn't that good.

Greetings,
Rick

This topic is closed to new replies.

Advertisement