Precaculating face and vertex normals?

Started by
16 comments, last by ByteMe95 23 years, 8 months ago
I''m still a little confused as to world space and obejct space. I mean I understand exactly what the difference is and all, but I dont understand the world matrix.

Right now my Object3D class has world coordinates:
3DV WorldCoord;

And you can set it to say 50,30,-300

And then all i do is when i project my polys (not using a matrix either, just calculations) i subtract the worldcoord from the xyz of the poly and then project, so I just add in 3 subtractions for my projection.

And I''m pretty sure my lighting algorithm works fine, have you seen my demo?
If I calculate the vertex normals every frame the lighting is flawless, looks just as it should. But if i precompute and try to rotate them, then it doesn''t work. And yes my lighting is recomputed every frame.

I dont know about drawing the normals, i dont want to get into programming that for no reason. I''m thinking there is a simple answer im missing.



ByteMe95::~ByteMe95()
ByteMe95::~ByteMe95()My S(h)ite
Advertisement
if your world (scene, whatever) is dynamic then you''ll probably have to recalculate every frame. if it''s static then you could use a look-up table type system.

JoeMont001@aol.com www.polarisoft.n3.net
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
The world matrix is just a way of placing and orientating your object in the scene. You said in one of your earlier mails that you were rotating your object. Presumably you doing this by transforming your object vertices by a matrix - this matrix is your world matrix.

I thing the only way to see what is happening is to display your normals - this is fairly easy in D3D (is that what you''re using?) and a piece of code like this will definitely come in useful in the future (I''ve used this many times!)
I''m not using d3d or any API, this is all 100% software, so I''d rather not take the time to do that, unless you have some code that could do it already

And are you saying my world matrix is my transformation matrix?

Can someone clarify something for me.
How many separate matrices should one object have? Right now i just have one, and when u call a transformation it multiplies that transofmration by the current matrix
so lets say Object.Translate(2, 2, -2) fills in the matrix with a translation and then Object.Rotate(.1, .1, .1) will multiply the rotation matrix for those values by the translation matrix alread filled, giving you the final transformation matrix.

Then I loop through all vertices and multiply them by that final matrix.
Then "Object->World", I do
(Object.)x+=WorldCoord.x
y+=Worldcoord.y;
z+=worldcoord.z

then peform the projection
screen_x = x/z; //abbreviated form
screen_y = y/z;

and then i call my poly filler

So the only matrices i actually use are the transformations. I have no world matrix or camera matrix or anything like that, mostly because i dont fully understand them. :o)



ByteMe95::~ByteMe95()
ByteMe95::~ByteMe95()My S(h)ite
Yes, this transformation matrix is usually called your object''s world matrix. An individual object can only have one world matrix, but each different object in your scene can have it''s own world matrix.

The reason for calling it the world matrix is because it maps vertices from object space (i.e. relative to the object''s origin) to world space (relative to the world''s origin).

What I was suggesting earlier was that there is no need to transform all of your normals every frame. Your normals will be precalculated based on your object vertices (i.e. in object space). Instead of using your transformation matrix to transform them into world space, you could transform your light into object space and do the lighting there.

This is done by transforming your light vector and position by the inverse of the object''s world matrix. You can then do your lighting in object space, which would give the same results, but save a lot of calculation.

You may also find that the problem you have at the moment just dissapears ...
I''ll try to get the light rotating in obhject space instead of rotating the vertex normals. Are you sure this works??? Just want to be sure this is a viable answer before i go into coding it




ByteMe95::~ByteMe95()
ByteMe95::~ByteMe95()My S(h)ite
Yep - it''s the usual way of doing things.
I tried doing that rotating light thing, I actually like the idea.
IT doesnt fully work for me though. It seems to wokr for half of the rotation, and the object is nearly black the other half.
I tried using the inverse matrix too (which is reversing the columns and rows right?) for the light rotation, that didnt help but it was closer.

I have an updated exe and my most relevant code in a zip file.

3DTEST

Can someone please look at the exe and look at the code, maybe see what''s wrong? This way of doing lighting took my fps from 40 to ~65fps

I like it
:o)



ByteMe95::~ByteMe95()
ByteMe95::~ByteMe95()My S(h)ite

This topic is closed to new replies.

Advertisement