3D points/lines and polygon normals

Started by Musurca, April 04, 2004, 03:07:23 AM

Previous topic - Next topic

Musurca

Hey,

I just started using jPCT last week, and I'm really impressed with it. Have you ever worked with the (now defunct) Spacecrafter 3D API? jPCT seems very similar to it, albeit far more powerful.

There are a couple features, however, that I'd like to add to my project, and I wasn't sure how to go about implementing them.

3D points/lines:
I'd like to be able to draw single-pixel points or lines in world-space for particle effects and such. I could just convert 3D points to screen space and draw them directly using the Graphics structure, but then they wouldn't take the Z-buffer into account and wouldn't be occluded by other objects. If there's no clever way to do this, would you be willing to add simple point/line drawing methods to the next release?

Polygon normals:
My game uses terrain generated from image-based heightmaps, and I'm using calcMinDistance() to find an object's height from its 2D position on the grid. However, I'd also like to change the object's orientation based on the contours of the terrain. I could call calcMinDistance() a couple more times from different points on the object to recalculate the normal, but this seems wasteful. I suppose I could also misuse the pickPolygon() method and a VertexController, but the polygon in question won't necessarily be visible to the camera. Would it be possible to add a method similiar to calcMinDistance() that returns information about the polygon struck by the ray and its normal?

Thanks in advance,

Nick

EgonOlsen

No, i never had a look at the Spacecrafter API. If jPCT is similar to it, it's a just a coincidence. I tried to get a copy of the Spacecrafter API to have a look, but it's obviously not available anymore.

To your questions: Currently, there's no option to plot simple points. What is possible, is to define an object as billboarded and use simple, single triangle objects as particles (transparent and textured). However, i'm not sure how fast this would be but it think it should be fine. It's much more powerful than simple points too. Maybe you can implement your particles that way and let me know if it's ok or too slow.

Abusing the VertexController in the way you suggested won't work IMO, because it can only gives you the vertex normals and not the face normals. There's a another thread here somewhere, where i mentioned the possibility of a TriangleController to access face normals and some other properties of a polygon but i'm not sure if i really should do that.
I've just implemented the effect you want to achieve in a new example (will be included in the next release (i hope)...have a look at the news-section for a screenshot of it). In this example, i'm using calcMinDistance on all four wheels of my "car" and calculate the rotation angles using these values (Math.atan() is your friend here). When using octrees for your terrain, this should be very fast. At least i wasn't able to notice a slowdown caused by this method. This will also handle some cases better where the method using the face normals will most likely fail, so i think it's the better approach.

Hope this helps. If it doesn't, please let me know and i'll think about this topic again.

Musurca

Quote from: "EgonOlsen"i mentioned the possibility of a TriangleController to access face normals and some other properties of a polygon but i'm not sure if i really should do that.
I've just implemented the effect you want to achieve in a new example (will be included in the next release (i hope)...have a look at the news-section for a screenshot of it). In this example, i'm using calcMinDistance on all four wheels of my "car" and calculate the rotation angles using these values (Math.atan() is your friend here).

Actually, that seems like a much better solution. I don't think I'll have any trouble working out the math on my own, but would you mind posting  the source for that example if the next release isn't going to be forthcoming for a while?

If I might add my two cents, though, I think that the ability to retrieve polygon information from a mesh might be invaluable in other ways. For example, if you were bouncing a ball on a jagged surface, and you wanted to figure out the direction in which the ball would rebound after impact, you'd definitely need to figure out the polygon normal quickly. Some sort of "TriangleController" would definitely be a welcome addition.

Anyway, thanks for the prompt reply.

EgonOlsen

Quote from: "Musurca"Some sort of "TriangleController" would definitely be a welcome addition.
Yes, it would. I'll try to add this feature if i find the time. Anyway, here's the (premature) source of my "Car"-class. It contains the basic math i'm using to place the car on the terrain. It's not documented and still unfinished but maybe it helps somehow: http://www.jpct.net/stuff/Car.java

EgonOlsen

Quote from: "Musurca"For example, if you were bouncing a ball on a jagged surface, and you wanted to figure out the direction in which the ball would rebound after impact, you'd definitely need to figure out the polygon normal quickly.
FYI: The new version (1.00+) offers a way to get this information (normals and vertices of single polygons in world space) via an object's "PolygonManager".