Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
3D gouraud shaded polygons!
#1
I have never been that good at 3D, but i recently decided to give it another try. It works like this,

TYPE 3DPoint
X AS INTEGER
Y AS INTEGER
Z AS INTEGER
END TYPE

DIM SHARED Plane(99, 3) AS 3DPoint

This gives me 100 little planes that I can do whatever I want with! Each plane is made up of 4 points, and I just draw a line between them. It looks really good in wireframe, and I have some nice 3D models that I made... But wire frame isn't as good as gouraud shading!!

Now first, I want to say that I'm using DQB... I'm comfortable with DQB, and when I'm done with a program, if it isn't fast enough, then I convert it to a different lib. Here is my problem:

1) I need a way to find the center of each plane. the problem with that is sometimes they are, for lack of a better word, bent. What my ultimate goal is, is to do this:
Code:
+-------------------------+
| `.                    ,'|
|   `.                ,'  |
|     `.           _,'    |
|       `.       ,'       |
|         `.   ,'         |
|           ><'           |
|         ,'  `-.         |
|       ,'       `.       |
|    ,,'           `.     |
|  ,;'               `.   |
|.'                    `. |
+-------------------------+

I wan't to have 4 gouraud shaded triangles per plane, intersecting at the middle. but sometimes the planes are stretched into wierd shapes, so I don't know how to determine the X, Y, Z coordinates of the center of the plane.

my second problem is this:

FOR P = 0 TO PLANES - 1
DrawPlane P
NEXT

that's not the actual code, but its something like that... In wire frame, that looks fine, but when I have it filled, sometimes the polygons that are closest are filled first, depending on how the object is rotated. What would I need to do to set it so that the closest planes get drawn last?

This is a little demo of my wireframe 3D capabilities...

REMEMBER, TURN EMS ON!
http://www.geocities.com/remixer1989/zonewar3d.zip

right click -> save as


(btw, I know that I should set it so that it only as 3 points per plane, but its not compatible with the software I use to create the models so I can't)
Reply
#2
In a minute Blitz will show up and tell you everything you need to know, but I can help you with the first bit.

Quote:I don't know how to determine the X, Y, Z coordinates of the center of the plane.
If it truly is a plane, there's a number of geometric ways to find the intersection of the diagonals... but if the four points are not co-planar, then there is no center. Think about it: Depending which diagonal is used, the quad will 'pop' a different way.

Quote:that's not the actual code, but its something like that... In wire frame, that looks fine, but when I have it filled, sometimes the polygons that are closest are filled first, depending on how the object is rotated. What would I need to do to set it so that the closest planes get drawn last?
Heh. Yeah I tried to do this manually before I realized that OpenGL has a built in clipping routine. It involves calculating every poly's distance from the camera and then sorting them from back to front...

For both questions, you're going to have a rough ride if you haven't finished high school math -- both the diagonal intersection and the distances is basic trig stuff.
Reply
#3
seeing as how I'm not going to START highschool till next year, that would be a bit of a problem wouldn't it? Tongue

and yeah, i see what you mean about the popping thing....hmmm...well I know which way I want it to pop. they are alway supposed to pop away from the center.

well, now I wait for Blitz i guess, thanks wizardlife Smile
Reply
#4
To get the xyz center of any poly:

Let n be the number of sides:

centerx=(x1+x2+x3...+Xn)\n
centery=(y1+y2+y3...+Yn)\n

Guess how you get centerz? :*)


2. Sorting ;*)


4. You can make tris of any quad. If you wan't to know email me. Or wait for my 3d series in QBCM. ;*)

Here's a sample:

Go to my siteSad Seems that I can't access it right now)

And download some 3d progs.

3d torus, Mono and disco, etc. :*)
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#5
you can use distance...

Code:
'Usually the second var (x2, y2, z2) is a center point
'In your case, use 2 points that you have...

'1-------------------------2
'| `.                    ,'|
'|   `.                ,'  |
'|     `.           _,'    |
'|       `.       ,'       |
'|         `.   ,'         |
'|           ><'           |
'|         ,'  `-.         |
'|       ,'       `.       |
'|    ,,'           `.     |
'|  ,;'               `.   |
'|.'                    `. |
'3-------------------------4

'5 is the center.....(where the points meet to make a pyramid)

x = (x2 + x1)^2
y = (y2+y1)^2
z=(z2+z1)^2

Distance&=SQR(x + y + z)

Center = Distance&\2

'You could do the distance of any point to any point
'To find the center, 1&4, and 2&3 should find X&Y center, Z would
'be 1&3...i think

Hope that helps....

Alex~
Reply
#6
rel: Thanks!! that looks perfect... (I have mono and disco somewhere...very cool-I just might email you...)

Code:
Here is an example of one of my "planes" (X, Y, Z)
         1(-3,-7,3)+.__
                  |\   `--._
                  / |       ``-.._
                 /  \             ``-.__ 2(5,-5,5)
                /    |                  :--
               |     \                .'  |
               /      |            .-'    |
              /       \          .'       |
             |         |      .-'         |
             /         \    .'            |
            /           |.-'              |
           /           .\`.               |
          |         .-'    `.             |
          /       .'         `-.          |
         /     .-'              `.        |
        /    .'                   `.      |
       |  .-'                       `.    |
       /.'                            `-. |
     /+'---------------------------------`.
3(-5,5,5)                              4(5,5,5)
It's kind of...fractured between 2 and 3... alrighty well thanks!

Alex: ok, thanks for your trouble, but I truly just don't get it Tongue
Reply
#7
No problem. I made a booboo though. :*)

I should have typed Polyhedron as its in 3d, instead of polygon which is 2d. :*)
Although a plane is still 2d if you look at it perpendicularly. :*)

Thought I might correct myself as if Glenn's around. :*)

Dang!!! That guy is reaaaaly not coming back. :*(

BTW, you might have more of a shot at learning if you read the code and comments in Disco Torus instead of Mono and Disco. :*)
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#8
o well...i tried....no problem tho.......im home all the time now, and have to waste my time on sumthing (im home coz i have surgery complications.....yay :-? )

Hope your prog works out,

Alex~
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)