|
Which face are we looking at? |
ngiacomelli
Member #5,114
October 2004
|
I'm using a modified version of the allegro 3d example (the bouncing cubes), to spin a single cube around, dependant upon player input. I'm running into problems when trying to figure out what face of the cube I'm currently looking at. Obviously, I need to do some kind of depth sorting, which I attempted with get_look_face(), but I'm obviously a long way off. I assumed that the sort would return the closest face first.
|
orz
Member #565
August 2000
|
For normal depth sorting you want the furthest face first, not the closest face. |
ngiacomelli
Member #5,114
October 2004
|
get_look_face just returns the id of the first face returned from the qsort. id is a bitmap offset.
|
orz
Member #565
August 2000
|
Well, I think your sort puts the furthest face first. Which is good, because that's what your rendering needs to look correct. So your get_look_face() returns the face that's farthest away. Perhaps you want it to return the last face out of the sort instead of the first? |
ngiacomelli
Member #5,114
October 2004
|
That's the method I used before posting, but I seem to have gotten my logic mixed up! D'Oh! That seems to have solved the problem! Thanks! My next question is: what's the easiest way to ensure that all faces of the cube render their bitmaps the right way up? That may sound strange. Imagine if I have text one side of a cube, and then have text on the face behind it. If I then rotate it, allowing the text on the other side to come into view, it's upside down. How can I sort that out? EDIT: Here's an ugly diagram: http://www.perforated-art.com/uglyexample.JPG
|
Ultio
Member #1,336
April 2001
|
Isn't that just a matter of texturing the faces in the proper "direction"? Clockwise/Counter clockwise? I forget. I guess it depends on how you actually construct each face. Do you create the vertices where they belong on the final result cube, or do you create six faces in the same spot and then rotate/translate them into place? --- |
ngiacomelli
Member #5,114
October 2004
|
Here is the 3d code in full. As far as I can tell, the cube is created, and then the shape translated into position:
|
nonnus29
Member #2,606
August 2002
|
Sounds like you've confused depth sorting with back face culling; you're drawing all of your poly's wether they face the camera or not. Depth sorting is only good for convex models like cubes, otherwise you get 'z fighting'; I found this out in my tank game some of you may (or may not) remember. To do backface culling dot the face normal with the camera; greater than zero is faceing, less than zero is facing away. For your texturing problem, you have to rotate and translate your texture coordinates along with the spatial coordinates. I don't see you doing that. Allegro 3d is gross. Use opengl or write your own software renderer. If you write your own you will fully understand how un-useful allegro 3d is. Edit; you should be using V3d for your verts, it has u,v texture coordinates, I don't see any texture coordinates in the code you posted. One can only guess where quad3d is getting this information from... |
|