Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

11991 Posts in 1587 Topics- by 3509 Members - Latest Member: lioneltenel

27. May 2012, 03:59:14 am
Xith3D CommunityXith3D InternalsDeveloper discussion (Moderators: Marvin Fröhlich, 'n ddrylliog)Primitives Quad
Pages: [1]
Print
Author Topic: Primitives Quad  (Read 2259 times)
qbproger
developers
Becoming dependent
***
Offline Offline

Posts: 217


View Profile
« on: 08. May 2008, 09:22:22 pm »

I was trying to make a quad. (http://xith.org/javadoc/xith3d/org/xith3d/scenegraph/primitives/Quad.html)

The reason for the link is the order of the points is somewhat odd.  I was thinking counter-clockwise starting with the lower-left (which seems to be what's indicated for texture coordinates).  That is not the case, the order of the points for the Quad is not (ll, lr, ur, ul) it is (ll, lr, ul, ur).  It's because it's stored in a Triangle Strip rather than a Triangle Fan.

If this is changed to a fan in the future, make sure any classes using it are changed so they are drawn correctly (Rectangle comes to mind).

I'm just posting this so if anyone else tries to use it they don't spend as much time as I did trying to get a quad to draw.
Logged

Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #1 on: 09. May 2008, 12:00:42 am »

Well, as you correctly saw, the vertices NEED to be in that order for the TriangleStripArray. So, this cannot be changed.

Even if it could be rendered as a fan, I don't really see the benefit. Yes, the vertex order would be more intuitive. But what's the actual worth? What problems did you have getting a Quad to render?

Marvin
Logged
qbproger
developers
Becoming dependent
***
Offline Offline

Posts: 217


View Profile
« Reply #2 on: 09. May 2008, 12:58:31 am »

To preface, I don't have a graphics background.  I had to lookup how a Triangle Strip and Triangle Fan stored their vertices.  Which will probably help me again in the future.

I thought the only way a Quad would be represented was the points in order counter-clockwise (or clockwise).  I originally thought it was a bug in Xith.  Then I started researching Triangle Strip and Triangle Fan.  I changed it to a Triangle Fan (briefly).  Luckily I was using a Image HUD Widget, and saw that this would cause problems elsewhere.  I opened up the Image code, and followed the hierarchy back to Rectangle, and eventually saw how it was ordering the points for the quad.  Here is when I looked up Triangle Strip and put the points in the correct order.

In the end, I spent about an hour and a half figuring this out and testing different things. :\

After I figured out the order of the points everything worked fine.  I made this post mostly to save someone else some time.

Here is where I read about the TriangleFanArray and TriangleStripArray:
http://download.java.net/media/java3d/javadoc/1.4.0/javax/media/j3d/TriangleStripArray.html
http://download.java.net/media/java3d/javadoc/1.4.0/javax/media/j3d/TriangleFanArray.html


Logged

Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #3 on: 09. May 2008, 01:40:25 am »

ok. Well. What I still don't understand is, what problems you had (or still have) with the Quad being implemented by a TriangleStripArray. Why is it even important? It should not matter at all, how the Image Widget is implemented in the backend. Why did you even check that? (Not that you shouldn't do that. But I simply don't understand, what you were trying to do.)

Is there anything, that you've changed, that needs to be changed to work correctly?

The counter-clockwise vertex order is only possible with the TriangleFanArray, because the quad is convex. This is a special case. Vertices are not ordered counter-clockwisely in general in OpenGL. Of course you can do that as a matter of taste/style, in cases, where it is possible.

Marvin
Logged
qbproger
developers
Becoming dependent
***
Offline Offline

Posts: 217


View Profile
« Reply #4 on: 09. May 2008, 02:04:19 am »

ok. Well. What I still don't understand is, what problems you had (or still have) with the Quad being implemented by a TriangleStripArray. Why is it even important? It should not matter at all, how the Image Widget is implemented in the backend. Why did you even check that? (Not that you shouldn't do that. But I simply don't understand, what you were trying to do.)

I looked at the image backend because after I changed the Quad to a TriangleFanArray the Image widget I was using looked weird.  I shouldn't have changed the Quad to use a TriangleFanArray.  That was my mistake.  My problems are all fixed now.  I understand the vertex ordering for Quads now.

Is there anything, that you've changed, that needs to be changed to work correctly?

I didn't keep any of my changes in.

The counter-clockwise vertex order is only possible with the TriangleFanArray, because the quad is convex. This is a special case. Vertices are not ordered counter-clockwisely in general in OpenGL. Of course you can do that as a matter of taste/style, in cases, where it is possible.

Marvin

At the end of the day, the whole thing basically comes down to I thought the Quad vertices would be oriented counter-clockwise and they weren't.  On this whole trip, I learned some new things about Triangle Strips and Triangle Fans. Smiley
Logged

Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #5 on: 09. May 2008, 09:47:15 am »

Well, after I slept a night over it I must say, that it might indeed fix something, if the vertices are in a counter-clockwise order. I am talking about backface-clipping, which I cannot use in the HUD because of the vertex order. So it might be good to change the Quad to a TriangleFanArray. I will check that. Thanks for the new perspective and sorry for my dumb questions Wink.

Marvin
Logged
qbproger
developers
Becoming dependent
***
Offline Offline

Posts: 217


View Profile
« Reply #6 on: 16. May 2008, 08:05:04 pm »

I just wanted to point out that now the Quad Primitive and the QuadArray in the scenegraph have different point orderings.  The QuadArray in the scenegraph I'd expect uses a TriangleStripArray as opposed to a TriangleFanArray because the entire QuadArray could be represented as one strip, and with the Fan each Quad would be a separate Fan.

I don't think this should be changed, and the documentation states the order of the points.  I just wanted to point this out.
Logged

Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #7 on: 16. May 2008, 09:39:09 pm »

I just wanted to point out that now the Quad Primitive and the QuadArray in the scenegraph have different point orderings.  The QuadArray in the scenegraph I'd expect uses a TriangleStripArray as opposed to a TriangleFanArray because the entire QuadArray could be represented as one strip, and with the Fan each Quad would be a separate Fan.

I don't think this should be changed, and the documentation states the order of the points.  I just wanted to point this out.

So do I understand you right, that just the JavaDoc is wrong? I will check it and fix it in case.

Marvin
Logged
qbproger
developers
Becoming dependent
***
Offline Offline

Posts: 217


View Profile
« Reply #8 on: 16. May 2008, 10:16:47 pm »

I didn't use the QuadArray, I just saw it in there (as har as I know it's correct).

I started out using a bunch of Quad Primitives, and then switched to a TriangleStripArray.  Frame rate went up about 10 fps.
Logged

qbproger
developers
Becoming dependent
***
Offline Offline

Posts: 217


View Profile
« Reply #9 on: 22. May 2008, 07:23:37 pm »

I tried using a QuadArray now, and it turns out the documentation is in fact wrong.

The vertex order is like this:
Code:
3---2
|   |
|   |
0---1
Logged

Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #10 on: 22. May 2008, 07:43:34 pm »

I tried using a QuadArray now, and it turns out the documentation is in fact wrong.

The vertex order is like this:
Code:
3---2
|   |
|   |
0---1

True. I have changed the documentation. Will be committed with my other changes in a few hours.

Marvin
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic