Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Vector visibility - Z axis solution
2007-12-04 07:52
LHS

Registered: Dec 2002
Posts: 66
Vector visibility - Z axis solution

Hi all,

I am coding a classical demo part - filled vector. I have a routine for vertex transformation (rotation) and a routine for EOR surface filling.

If I have f.e. a simple opaque cube (all angles are 90dgrs), what is the best technique to check which surface I may show and which I mustn't? I have f.e. 4 vertexes of a side (X, Y and Z coordinates in signed variable), how can I calculate, if is this surface (of the cube) visible or invisible? I think the same technique can be used for a glanz cube which surface is inner or outer.

Thanks,

LHS
 
... 19 posts hidden. Click here to view all posts....
 
2007-12-04 15:39
JackAsser

Registered: Jun 2002
Posts: 2014
Quote: Assuming a cube that is world axis aligned the normals for the faces are the world axises defined by your rotation matrix, neat huh? =D

Otherwise to recalculate a face normal you simply take the cross product for two vectors in the plane of the desired face, then normalize it. This you NEVER want to do on the c64.


Ok, I can give you a really thourough explanation of this, but please first give me your constraints. What kind of object do you have, how does it move, can the camera move etc. Do you have perspective? Etc... Then I can help you finding the most optimal way for backface culling.
2007-12-04 15:54
Oswald

Registered: Apr 2002
Posts: 5094
I have 4 points (p1-p4) of a plane (with X, Y and Z coordinates). How can I use these coordinates for the "Z-normal compare"?

"4) If you're using the values of the rotation matrix directly to derive surface normals, all you can do is cubes. For other surfaces you need to rotate the normals first and use their rotated Z-values in the compare."


btw, you need some extra trickery to rotate an extra coordinate faster than 2 muls. most probably reusing rotation matrix, and a very symmetric object.
2007-12-04 20:27
LHS

Registered: Dec 2002
Posts: 66
Thanks you for your helps and I am sorry for my incomprehension.

I have read a book with tens pages about 3D transformation with a lot of theory and complex formulas. And then I have read a book with a few pages with 3D simple interpretation like: "you need 3 coordinates X-Y-Z, for rotation around centre use these formulas, huh now we have rotated object, but what must we do with Z axis? - here you are simple formulas for paralel or perspective projection, the variables in formula mean... etc.".
I am not profesional programer and I prefer the second (simple) way of comment. Unfortunately the book includes only wireframe models.

Well, I would like code objects like in this demos (screenshots):
Filled Vectors
Vector Overdose

I have a cube - vertexes with X, Y and Z units, f.e. like this:
p0 20, 20, 20
p1 20,-20,20
p2 -20,-20,20
p3 -20, 20, 20
p4 20, 20, -20
p5 20,-20,-20
p6 -20,-20,-20
p7 -20, 20, -20

I have formulas for transformation(rotation) like this:
newX = someX*sin + someY*cos
newY =...
newZ=... etc etc.

Then I have all 8 vertexes rotated aroud axis X, Y and Z, f.e.
p1 30, 10, -10
p2 ... etc.

I will use paralel projection (discard Z axis, but I have the Z values in memory). All vertexes are every time in visible space.

Now I have a routine for EOR line-drawing and EOR plane filling. The routine takes 4 vertexes. Before I need calculate, if is the plane visible.
Is there a formula how can I check visibility? f.e.

if p0.z + p1.z + p2.z + p3.z > 0
then plane is visible
else plane is invisible

or something like this?
2007-12-04 20:45
JackAsser

Registered: Jun 2002
Posts: 2014
Ok, my explanations will require you to know the basics of linear algebra, something I won't teach you. ;D

How ever, with parallel projection (i.e. without perspective), to backface cull you simply only need to check the rotation angles to directly know if a face is visible or not. Consider the front face, if you rotate around the x-axis 90 degrees or more it'll be invisible. I mean, u KNOW which faces that are visible or not directly. (assuming cube, assuming paralell projection)
2007-12-04 20:55
Oswald

Registered: Apr 2002
Posts: 5094
well, it depends on how you deep you want to crawl into this. honestly for me it took TEN years to CLEARLY understand most concepts used, and still learning. either you give yourslef some time and your vectors will be fast and smooth rotating (=accurate) or you go the fast way and they will be slow and jerky.

if you can understand how 2d -> 3d rotations work, and then the matrix method you are kinda there. but dont forget about signed numbers, fast multiply etc neither.

if you have a working signed multiply routine you can build your routine fast with equations you find, but it will be not the best one can come up on c64.
2007-12-04 20:59
Oswald

Registered: Apr 2002
Posts: 5094
for the fast way here are the magic formuls for rotations:

http://www.siggraph.org/education/materials/HyperGraph/modeling..

back face hiding:

((p1x-p2x)*(p1y-p3y))-((p1y-p2y)*(p1x-p3x))

read my previous posts on this.


perspective projection:

x=(x/z)*n -> build a table with z=(1/(z+d))*n, use your mul routine x=x*table(z), drop lowmost 8 bits from result.

(finding a good 'd' and 'n' are subject to trial and error)
2007-12-04 21:25
Slammer

Registered: Feb 2004
Posts: 416
The JackAsser/Graham method is neat but perhaps I was not the only one who where confused about the explanation of how it works. I guess there is something missing?

I found an alternative explanation instead:

I think you found that the point where the surface goes from hidden to visible is when the surface extended into a plane intersects the eye-point. Now you can draw a 90 degree triangle like the one on the sketch below. Then you use the small cosine relation (Cos A=Adjacent/Hypotenuse - look under Right triangle definitions in http://en.wikipedia.org/wiki/Cosine)
and find that Cos A = D/z and since Cos A is the same as the z point of the surface normal we have that normalZ=D/z when the surface goes from hidden to visible.


2007-12-04 23:03
Oswald

Registered: Apr 2002
Posts: 5094
now that explains a few things jackie forgot to mention & I was too shy to ask about :) nice one slammer.
2007-12-05 01:00
Graham
Account closed

Registered: Dec 2002
Posts: 990
The Z-compare method works for all surfaces where the midpoint stays on a sphere no matter what angles you rotate.

This applies to all surfaces of all platonic/archimedian solids.
2007-12-05 07:59
Nightlord
Account closed

Registered: Jan 2003
Posts: 131
what a nice thread this is ...

hmm i guess most of the time the z comparison for normal will be a faster method as opposed to Oswald's method that is based on the cross product of the projected 2d coordinates (i used to use a variant of the cross product method in my vectors too).

But depending on the methods you use to render poligons and do the vertex rotations and the shape you rotate, i think this might change. For instance if you are using a shape where you have to rotate additional vertices that represent the normals, then you might end up paying a higher cost for that as 9 multiplications and 9 additions in the worst case per face

Well my point is not to claim one method better over the other but i just wanted to point out something that I thought might be missed :) so just my 2c.
Previous - 1 | 2 | 3 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Andy/AEG
BANDIT/BANDIT-COOL-S..
Smasher/F4CG
Hydrogen/Glance
leonofsgr/Singular C..
Scrap/Genesis Project
Asphodel
Guests online: 102
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 The Demo Coder  (9.6)
6 Edge of Disgrace  (9.6)
7 What Is The Matrix 2  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 No Listen  (9.7)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 X-Mas Demo 2024  (9.5)
7 Dawnfall V1.1  (9.5)
8 Rainbow Connection  (9.5)
9 Onscreen 5k  (9.5)
10 Morph  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Censor Design  (9.3)
5 Triad  (9.3)
Top Logo Graphicians
1 t0m3000  (10)
2 Sander  (9.8)
3 Mermaid  (9.5)
4 Facet  (9.4)
5 Shine  (9.4)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.048 sec.