Noob - texturing a procedural mesh questions

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:scenegraph_for_dummies

In case it interests someone:

If I add those boxes in the initialize method of the appState, then they are incorrectly set at the origin of the vehicleNode.
Also, I need to wait for a tpf value of 2 before adding the boxes, in the update method of the appState, or they will be set at the origin.

Not saying it’s a bug, because I’m oblivious to most of what’s going under the hood.

I thought that cos2 was the equivalent of cos apart from the fact it uses radians instead of degrees?

[java]
float x, z;
float angle = FastMath.PI / 8;

x = FastMath.cos2(angle);
System.out.println(ā€œradians cos2ā€);
System.out.println("x: " + x);

float angle2 = (float)Math.toDegrees(angle);
x = FastMath.cos(angle2);
System.out.println(ā€œdegrees cosā€);
System.out.println("x: " + x);
[/java]

Outputs:
radians cos2
x: 0.9238795
degrees cos
x: -0.87330467

A’m I being an idiot?

From looking at the code I don’t know why the sin/cos2 does what they do and the javadoc isn’t helping. I think it tries to optimize something by keeping the values in a certain quadrant but that’s just guessing.
It eventually ends up in Math.sin or Math.cos anyway. All methods are in radians so that’s not it either.

http://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/core/com/jme3/math/FastMath.java

1 Like

Both methods take radians. If you ever see a serious trig function that takes raw degrees then you should be shocked. It’s always radians.

I don’t see a good reason to use the cos2/sin2/etc. versions. The math looks really dodgy to me and most game code will be keeping the angles within reasonable limits anyway.

1 Like

Thx jmaasing and pspeed… I guess my low math skillz show here :D.