jPCT - a 3d engine for Java => Support => Topic started by: Vitaly on July 25, 2005, 05:05:37 pm

Title: counter-clockwise order
Post by: Vitaly on July 25, 2005, 05:05:37 pm

have a problem using jPCT. I load the scene from .ase file and some objects are showing but some are invisible. I tried to understand where is the reason and I have only one version - when calling addTriangle for Object3D I have counter-clockwise order broken. Can someone suggest how to check and correct this condition?

Title: counter-clockwise order
Post by: EgonOlsen on July 25, 2005, 07:09:45 pm
Try to disable backface culling by using the setCulling()-method in Object3D. Do the objects show then? This is of course not a good solution, just a quick test if vertex ordering is really your problem.
Title: ccw order
Post by: Vitaly on July 26, 2005, 03:48:30 pm
Thanks for advise. Problem is nearly here. I tried to disable backface culling - some objects become visible, but some other - hide!!! Also I find criteria for determining ccw order:

(p1.x-p0.x)*(p2.y-p0.y) - (p2.x-p0.x)*(p1.y-p0.y)

if this is > 0 then we have ccw order. I tried to "normalize" triangles but still have problems :( It just changes what objects are hiding and showing...
More, the visibility depends on camera position and direction - some objects are visible from one camera and hidden from second...

Tried to load the same file using xith3d - all looks good... Have anyone any ideas?
Title: counter-clockwise order
Post by: EgonOlsen on July 26, 2005, 04:34:09 pm
Could be that Config.maxPolysVisible is set to low so that some polygons are being discarded. Try to increase this value (before creating a World) and see if it helps.
Title: thanks
Post by: Anonymous on July 27, 2005, 11:50:31 am
Egon, thanks a lot, the reason was that limit of visible polygons. By the way, I think it would be reasonable to print some diagnostic message - it can help to easily find the problem. Maybe you can suggest how to align camera to z-axis? In other libs it's done be specifying "vector pointing up" along with position and destination points.

Thanks one more time.
Title: counter-clockwise order
Post by: EgonOlsen on July 27, 2005, 05:14:11 pm
What exactly do you mean by "align with z-axis"? The camera is aligned with the the z-axis by default. If you want to align it with the z-axis of an (rotated) object, there is an align()-method in Camera. If you want to align it with any vector, you can do something like this:
Code: [Select]

// Look up
camera.setBack((new SimpleVector(0,-1,0)).getRotationMatrix().invert3x3());

But it's cheaper to do the rotations directly on the camera instead of aligning it afterwards. Or did i get you wrong?

About the message: You are right. I've avoided this until now, because i don't really see it as an error. But i'll add a one-time warning once you are exceeding the limit (to not spam the console with such messages).
Title: camera
Post by: Vitaly on July 28, 2005, 12:51:00 pm
It seems you mean something different. Let me explain. Camera is determined by two obvious parameters - position (look-from point) and destination (look-at point).
But there is one more important thing that I called "vector pointing up". You can see from the same position and at the same target but upside down or beding head left or right and the picture would be different. My question was how to implemet it in jPCT. All methods we discussed change at least target point and this is wrong behaviour.

Title: counter-clockwise order
Post by: EgonOlsen on July 28, 2005, 05:01:54 pm
In jPCT, the camera is defined by its position and a rotation matrix, not by "look at" and "up" vectors. If you want the camera to "tilt", just do a rotateZ(<float>) on it. This will work even if it's not aligned with the worlds z-axis.