hi i need some help with getLocalRotation and rotation it self, i need to get the 360 degrees of each x,y,z. but when i go for getLocalRotation i finde float values (pretty big values) and what i need is (for example ) take my object and rotate it in direction of an other object soo i need to use proportion of location of both bodies to obtain the direction,the problem is i cant set the direction values in rotate and cant undestand the output of getLocalRotation, soo cant check if body has right rotation.
Youâre getting a Quaternion object, not just floats. This will have 4 floats which ⌠well forget about them (google it if you want but you donât need to understand them, only how to use them). Using that Quaternion you can do:
Quaternion q = yourThing.getLocalRotation();
float[] angles = new float[3];
q.toAngles(angles);//this stores the angles in the float array
http://javadoc.jmonkeyengine.org/com/jme3/math/Quaternion.html#toAngles-float:A-
toAngles returns this quaternion converted to Euler rotation angles (yaw,roll,pitch).
Important to note that the order of rotation matters with euler angles and in this case its yaw roll pitch, so rotation around y, then z, then x.
Just in case, donât forget they are radians not degrees.
Going to degrees is nothing but trouble here, anyway.
If you want to rotate towards some other object then just rotate towards it. You donât need to manipulate angles directly. That just leads to trouble as you rapidly learn that Quaternion will return the most compact representation and not the one you want. Plus you will have to deal with quadrants, crossing boundaries, etcâŚ
I canât give more advice than that because I donât really know what you are trying to do specifically.
Octants, if weâre 3d. I once did that to generate a vector that Iâd understand completely⌠and everything reduced to two or three ifs in the end. Once more bicycle invention oh lol.
lets say i need my space ship to rotate in right direction at appropriate speed,then tell me its rotation so i can tell it to move there(like move in direction where u are looking)
What is âright directionâ? What is âappropriate speedâ?
How do you determine these things?
Right direction is the direction i need ,and appropriate speed is the time it will take to rotate from how it is now to how i need it lets say 1.0f *tpf;
I have my ship,soo i get its coordinates,and have object or place where i need to go .
Lets say âmyLocationâ is x=0;y=0;z=0; and i need to go to âwayPointâ x=10;y=1;z=1; soo i just say :
wayPoint - my Location = rightDirection
(x=10 - x=0; y=10- y=0; z=1 - z=0;) the rest is pretty simple
(it just have to rotate to the right a bit up and not totally to the right)
,and the speed is speed i get with setters and getters from an other class,i dont want it to move instantly to where i need ,i need to make it slowly
You donât want rotations, you want a forward vector and an up vector. Look at the âmath for dummiesâ link at the top of the page.
are u shere it will make it turn around and not just move? couse my ship will have face and it needs to turn to direction and not just move to it
You can use the left and up vector to find out how much to turn and which way. The dot product is your friend here.
This sounds like pretty typical steering behavior thatâs been gone over here a bunch of times.
Just as a general rule: if you find yourself needing âdegreesâ for anything other than displaying something to the user then youâre usually doing something wrong. Even keeping angles in radians has only a very few specific use-cases and almost always in just one direction. (angle â rotation)
You make me wonder. I have such a use in aiming check (see pic below):
float sinA = diameter / ( 2 * targetDirectionVec.length() );
float angle = FastMath.asin(sinA);
Vector3f targetDirectionVecN = targetDirectionVec.normalize();
float realAngle = fwdLookVecN.angleBetween(targetDirectionVecN);
if ( FastMath.abs(realAngle) <= FastMath.abs(angle) ) return true;
return false;
How would you do it instead?
What exactly are you trying to determine? Iâm having trouble figuring it out because the blue tangent vector (and the blue circle) seem a bit arbitrary. Like, the closer the look vector and the target vector are to being parallel, the weirder the angle of the diameter line will be. So, from one step back, what are you using this true/false value for?
I can see where targetDirectionVec comes from but how are you calculating fwdLookVecN? I want to be able to provide an accurate basis for creating a different look-based vector.
Circle represents targetâs bounding sphere (so we donât need cases inside). Point outside represents where we are now to determine if weâre aimed or not. Of course all positions and rotations are known.
I really do need the answers to those questions.
Vector3f fwdLookVecN = weaponWorldRot.mult(Vector3f.UNIT_Z);
determining if my weapon is granted to open fire or no.
So you want to know if the target is within some min/max angle of the look vector? This is why I think the diameter from the target is a strange parameter⌠as then the angle gets smaller and smaller the farther away the object is. Which to me doesnât seem relevant to targeting.
Assuming you have some min/max angle in mind:
Vector3f side = weaponWorldRot.mult(Vector3f.UNIT_X);
float dot = side.dot(targetDirectionVecN);
âdotâ is then the cosine of the angle between side and targetDir⌠ie: a projection of target along side. 0 means you are looking right at it. 1 means it is 90 degrees directly to the side.
float range = FastMath.sin(maxTargetAngle); // can be a constant probably
return FastMath.abs(dot) < range;
Edit: for steering calculations, dot can be directly pumped into âhow much do I turn?â calculations.
Oh, and if you want to know if the target is in front or behind then you can initially do a dot-based check against your look vector. If dot is negative then the object is behind you.
Yep, I was determining if my weapon fires straight forward (which in your description means angle = 0) will it hit target or no. I will try your solution, it seems more general (well, as usual though). Thanks!
Note: itâs also probably faster, I guess. In modern computers I guess the trig functions like asin() arenât as expensive as they used to be⌠but a dot() project is an easy 3 multiplies and two adds. Hard to beat it considering all of its magical properties.
Yep, thatâs why I assumed itâs worth asking and even making picture. That magic isnât completely exposed in Math for Dummies, it seems⌠not to diminish the tutorialâs usefulness ofc.
well i will try to to try to try what u suggest , but i was thinking of using .getLocalRotation().getX() ,the problem is i dont know the maximal and the minimal possible values,i was thinking this would give me some idea on where my object looking soo i can tell it how mutch it should chenge it