Need help with line normals
July 20, 2011 03:17AM
I was progressing nicely until I added a light and my lines started drawing incorrectly. Then I realised that I need to add normals to them but my normals are incorrect and I can't figure out the right combination I need (I search google as well but I already have the normals for the cube working perfectly but they don't work for these lines.) However the line cube draws perfectly as expected, I just need help ficing the normals

Can someone tell me which one of my normals are incorrect?

Code for the function is here: [codepad.org]

Also note that I know of the draw cube function in GRRLIB but it is too slow for my game (all that looping, division and arrays). And the code for the displaylist works, if anybody was having problems with using them.
Re: Need help with line normals
July 20, 2011 09:35AM
This is what I do - took me ages to work out and works well for me.

The normal values you are using look more like something that is meant for UV texture coordinates.

I use two types of surface lighting, one where the normal’s point away from the surface (gives hard edges), and another where the normal’s simply use the x,y,z part again (gives soft edges) . Maybe swapping to the soft edge lighting should give you results straight off, as a test step.

If you need hard edges you need to look into how to calculate a normal from say 3 x,y,z points, google "Calculate the normal of a triangle" or something like that
,
// heres what I do , RenderModelMinimalHardNorms is the method you are currently using.

void Render3D::RenderModelMinimal(HashLabel ModelName, Mtx& ModelView)
{
       //soft edges	
	GX_LoadPosMtxImm(ModelView, GX_PNMTX0);
	Mtx mat;
	guMtxInverse(ModelView,mat);
	guMtxTranspose(mat,ModelView);
	GX_LoadNrmMtxImm(ModelView, GX_PNMTX0);
	DisplayListInfo& Info( m_DispayListContainer[ModelName] );
	GX_CallDispList(Info.m_dispList,Info.m_dispSize);
}

void Render3D::RenderModelMinimalHardNorms(HashLabel ModelName, Mtx& ModelView)
{	
         //hard edges
	GX_LoadPosMtxImm(ModelView, GX_PNMTX0);
	GX_LoadNrmMtxImm(ModelView, GX_PNMTX0);
	DisplayListInfo& Info( m_DispayListContainer[ModelName] );
	GX_CallDispList(Info.m_dispList,Info.m_dispSize);
}
Re: Need help with line normals
July 20, 2011 02:11PM
That's all well and good but I just want the hard-coded numbers because i won't be changing them anytime soon. The normal numbers for quads are easy to find online but I need normals for a wireframe cube.
Re: Need help with line normals
July 21, 2011 07:53PM
I think the problem is how you draw the wireframe cube. You are drawing the edges of the cube and not the faces of the cube. See, the way you draw it each line (edge) is shared between two different faces of the cube. That makes 2 normals (actually 4, one pointing inside and one pointing outside for each face) to choose from for your vertices. What ever normal you choose, it will look wrong for one face.

Just draw the edges of each face seperatly and assign the normal of the face they are forming to the vertices.
GX_Begin(...) //Draw edges of top face GX_End();
GX_Begin(...) //Draw edges of bottom face GX_End();
...

Another solution is to disable lightning before you draw the wireframe cubes and enable it when you're done drawing the cubes. Too many state changes may have an impact on the perfomance though.
Re: Need help with line normals
July 21, 2011 07:55PM
Posted at the same time as the faces answer.

Owen - Is the soft edge no good for what your doing (you only need to re-use the same x,y,z values in the normal part)?
Don't forget to use guMtxInverse(ModelView,mat); as in the fist example.
I really don't think you will see much of a difference for lines.

To calculate normal’s from three points I post this code just in case you or anyone else needs this in the future (it's been typed in here so it may have mistakes, but it gives the general method needed !)
void CalcNormal(guVector* InVec1, guVector* InVec2, guVector* InVec3, guVector* OutVec)
{
	guVector Tempv1,Tempv2;
	guVecSub(InVec3, InVec1, &Tempv1);
	guVecSub(InVec3, InVec2, &Tempv2);
	guVecCross(&Tempv2,&Tempv1,OutVec);
	guVecNormalize(OutVec);
}



Edited 1 time(s). Last edit at 07/21/2011 08:07PM by Titmouse.
Re: Need help with line normals
July 21, 2011 10:57PM
@AlfredMantalini hmmmm. I draw all the cube faces first. then, I draw the wire frame cube + 1 scale around it. So basically they are almost separate entities. I don't even know why I need normals when I am just drawing a line in the first place. I'll try drawing the lights last and see how that looks.
Re: Need help with line normals
July 22, 2011 10:01AM
Yes as you say, if don't need lighting don't use normals. Just send GX_VA_POS & GX_VA_CLR0 and setup GX_VTXFMTn to match.
You found lighting looks odd without normals, not tried this myself, so you will still need to turn off lighting as stated above in the other post.



Edited 3 time(s). Last edit at 07/22/2011 10:05AM by Titmouse.
Re: Need help with line normals
July 22, 2011 10:35AM
Quote

You are drawing the edges of the cube and not the faces of the cube
what i wanted to say is that you have to draw each edge twice. otherwise you dont know wich normal you have to assign to the vertices of the edge. have a look at how glut does it. (Link).



Edited 2 time(s). Last edit at 07/22/2011 11:09AM by AlfredMantalini.
Sorry, only registered users may post in this forum.

Click here to login