min3D framework. Object rotation & movement - java

I am trying to code a cessna flying around the world using the accelerometer with the min3D framework for android but the rotation is a bit weird.
I'm using this to apply the accelerometer rotation to the object:
cessna.rotation().x = rotX;
cessna.rotation().z = rotZ;
This works fine. I haven't figured out yet how to move in the direction of rotation (I think I have to use trigonometry).
I rotated the object with
cessna.rotation().y++;
just to test what will happen. At 180° the rotation around the x axis is mirrored. So the nose of the plane turns down instead of up.
I think I rotate the Objects around the world axis and not around the local axis from the object. How can I do this? I didn't find any documentation about the min3D framework in the internet :/ .
Thank you if you can help me.
(sorry for the bad English)

If you want to rotate around object local axis. Do this
(in pseudo code - you'll need to find similar functions in min3d)
Translate(object.pos.x,object.pos.y,object.pos.z);
object.rotation().x+=radians(45);// or whatever
if that doesn't work, try wrapping the above two lines in
pushMatrix()
...
popMatrix()
Or similar functions in min 3d to save and then restore the current camera rotation translation matrix.
Have you considered, Processing, which also comes with an Android 'output'?

Related

libGDX gravity and constant acceleration doesn't work properly

I am trying to create a simple Flappy Bird clone but in my own way ( so it's not a complete clone ).
However I am having problems applying a constant downwards acceleration to the Bird. When I create a World it says that it gets a gravity variable but that's not gravity I think ? It should say something like velocity because that is all it does. My Bird is falling downwards at a constant speed. And I believe most of you know how gravity works. When I use functions like applyForceTo I basically get the same.
I have already my own simple implementation of gravity but I wanna use libGDX to its fullest and practice with it.
I found the answer myself and the solution is pretty simple. The objects I render, the whole "System" is way too big for Box2D and its properties to make any difference on the display. Everything accelerates accordingly but you can't see it. So I scaled down every object so it had properties of a couple of pixels and adjusted the camera. Now I can get very high accelerations and velocitys.

Java WorldWind : translate whole globe

I am doing extensive use of Java WorldWind and have difficulties to implement some more feature with 3d rendering. At first, I had huge difficulties with zoom and BasicOrbitView, as zoom actually changes point of view elevation, which changes the horizon and hence is not a zoom. I solved that using FOV parameter. Decreasing this parameter performs a real zoom, as visualized object is only modified by an homothetic transformation. I explain that to let know the level of details I hide behind words such as "zoom" or "translate".
Now I have a second issue with "translate": I want to translate the whole earth along screen X and Y axis without horizon change or whatever. Objective is to combine both FOV change with translation change to zoom on some earth edges.
Zooming on some earth edge is possible using roll and pitch, at the condition that the edge is located up on your screen, which forbids to have pole north up, zooming at earth edge on equator for example (if not clear I will provide illustrations). So this attempt was unsuccessful. I worked a lot on BasicOrbitView.setOrientation method unsuccessfully.
I also tried to modify the OpenGL view matrices behind the View, trying to multiply it with a 4x4 matrix describing a translation, unsuccessfully (execution crashes during worldwind subroutines).
Have you an idea on how to implement that translation in worldwind ?

Free-flight camera with vectors - how to rotate properly?

I have this camera that is set up with vecmath.lookatMatrix(eye, center, up).
The movement works fine, forwards, backwards, right, left, these work fine.
What does not seem to work fine is the rotation.
I am not really good at math, so I assume I may be missing some logic here, but I thought the rotation would work like this:
On rotation around the Y-axis I add/sub a value to the X value of the center vector.
On rotation around the X-axis I add/sub a value to the Y value of the center vector.
For example here is rotation to the right: center = center.add(vecmath.vector(turnSpeed, 0, 0))
This actually works, but with some strange behaviour. It looks like the higher the x/y of the center vector value gets, the slower the rotation. I guess it's because through the addition/substraction to the center vector it moves too far away or something similar, I would really like to know what is actually happening.
Actually while writing this, I just realized this can't work like this, because once I have moved around and rotated a bit, and for example I'm in "mid air", the rotation would be wrong....
I really hope someone can help me here.
Rotating a vector for OpenGL should be done using matrices. Linear movement can be executed by simply adding vectors together, but for rotation it is not enough just to change one of the coordinates... if that was the case, how'd you get from (X,0,0) direction to (0,X,0)?
Here is another tutorial, which is C++, but there are Java samples too.
There is a bit of math behind all this - you seem to be familiar with vectors, and probably have a 'feel' of them, which helps.
EDIT - if you are to use matrices in OpenGL properly, you'll need to familiarize yourself with the MVP concepts. You have something to display (the model) which is placed somewhere in your world (view) at which you are looking through a camera (projection).
A working solution to working with a free-flight camera with eye, center, up vectors was posted here:
Free Flight Camera - strange rotation around X-axis

How to draw a specific object with a different projection than other objects?

So I haven't been able to find anything on this anywhere: I'm using Java3D to create an environment for my users. I'd like to put a 3D display of the X, Y, and Z axis in the corner that rotates as they rotate their view. Unfortunately, it needs to be in the corner instead of right in the center. This means that with the normal View projection (PERSPECTIVE_PROJECTION), the axis don't line up quite right and it looks really, really awkward. Using PARALLEL_PROJECTION instead fixes the awkward axis display, but then I can't view the world properly because it doesn't let me zoom anymore. Is there any way to tell the renderer to use PARALLEL_PROJECTION specifically for the axis display and PERSPECTIVE_PROJECTION on all other objects? Or is there another way around this problem I don't see?
Simply for better understanding of the Java3D concepts I recommend you to read this tutorial. It helps me very much

What is the best way to rotate cube in Opengl

I have a Rubik's cube displayed using OpenGl in a Java Eclipse application and I want to "rotate" this cube in response to mouse events.
I started with a "naive" (isn't it ?) solution as described here: OpenGL - moving camera with mouse. With such solution in addition to the problem described (my problem is maybe the same ???) when I rotate 90 degrees according X-Axis to get 'upside front' i am not to rotate anymore according initial Y-Axis to get the new front on the right. Because of the first 90 degrees rotaion I will have now to rotate according to Z to get expected behavior.
May be using gluLookAt utility method is easiest than using modeling transformation in this case ?
Would arcball make you happy ? (it should)
(I don't usually link to NeHe, but this one is independent from openGL)

Categories