how to translate camera on Y axis by angle
SkyEric opened this issue · 5 comments
Hi. The Camera class has a method Camera#translate(dX,dY)
If you want to rotate the camera around y axis, just call Camera#translate() method with dY=0 and dX=x. That means there is no movement vector up or down but "x" to the right or left.
/**
* Translation is the movement that makes the Earth around the Sun.
* So in this context, translating the camera means moving the camera around the Zero (0,0,0)
*
* This implementation makes uses of 3D Vectors Algebra.
*
* The idea behind this implementation is to translate the 2D user vectors (the line in the
* screen) with the 3D equivalents.
*
* In order to to that, we need to calculate the Right and Arriba vectors so we have a match
* for user 2D vector.
*
* @param dX the X component of the user 2D vector, that is, a value between [-1,1]
* @param dY the Y component of the user 2D vector, that is, a value between [-1,1]
*/
public synchronized void translateCamera(float dX, float dY) {
if (getDelegate() != null){
getDelegate().translateCamera(dX, dY);
}
}
How does it relate to 0 to 180 degrees on the Y-axis? Let's say I want to rotate 30 degrees about the Y-axis, what do I do? The interval [-1, 1] does not evenly divide 360 degrees by percentage?
Originally posted by @SkyEric in #83 (comment)
Hello @SkyEric
I guess you can try the following method to get your euler translation by angle.
Regards
float degrees = 30;
float xRot = 0f, yRot = degrees, zRot = 0f;
float radians = Math.toRadians(degrees);
float[] buffer = new float[16];
Math3DUtils.createRotationMatrixAroundVector(buffer,` 0, radians, xRot, yRot, zRot);
float[] newBuffer = new float[12];
Math3DUtils.multiplyMMV(newBuffer, 0, buffer, 0, coordinates, 0);
pos[0] = newBuffer[0];
pos[1] = newBuffer[1];
pos[2] = newBuffer[2];
up[0] = newBuffer[8];
up[1] = newBuffer[8 + 1];
up[2] = newBuffer[8 + 2];
Hello @SkyEric
I guess you can try the following method to get your euler translation by angle.
Regards
float degrees = 30; float xRot = 0f, yRot = degrees, zRot = 0f; float radians = Math.toRadians(degrees); float[] buffer = new float[16]; Math3DUtils.createRotationMatrixAroundVector(buffer,` 0, radians, xRot, yRot, zRot); float[] newBuffer = new float[12]; Math3DUtils.multiplyMMV(newBuffer, 0, buffer, 0, coordinates, 0); pos[0] = newBuffer[0]; pos[1] = newBuffer[1]; pos[2] = newBuffer[2]; up[0] = newBuffer[8]; up[1] = newBuffer[8 + 1]; up[2] = newBuffer[8 + 2];
Tried it but it didn't work. How is coordinates defined?
Here is my definition:
final float[] coordinates = new float[12];
coordinates[0] = pos[0];
coordinates[1] = pos[1];
coordinates[2] = pos[2];
coordinates[3] = 1;
coordinates[4] = getxView();
coordinates[5] = getyView();
coordinates[6] = view[2];
coordinates[7] = 1;
coordinates[8] = getxUp();
coordinates[9] = getyUp();
coordinates[10] = getzUp();
coordinates[11] = 1;
in addition. Is there any problem with the initial value of xRot、yRot、zRot?
@andresoviedo
.hello @SkyEric
That is correct
Coordinates is a buffer containing all 3 camera coordinates.
Those coordinates must be transformed using the transformation matrix given by createRotationMatrix.
Yes. There may be an issue in the pseudo code..please try declaring each variable independently.
Regards
Hello @SkyEric
Thank you for your feedback
i think I now understand your need
I am guessing we are talking about AR
And in this case indeed angle & orientation are keys
I did a poc a while ago and I think I implemented that already
you might want to see this code
i think it's all you need
private void setupOrientationListener()
https://github.com/the3deers/android-3D-model-viewer/blob/master/app/src/main/java/org/andresoviedo/app/model3D/view/ModelActivity.java#L204
public void onOrientationChanged(int orientation)
https://github.com/the3deers/android-3D-model-viewer/blob/master/engine/src/main/java/org/andresoviedo/android_3d_model_engine/services/SceneLoader.java#L969
public void setOrientation(int angle)
https://github.com/the3deers/android-3D-model-viewer/blob/master/engine/src/main/java/org/andresoviedo/android_3d_model_engine/model/Camera.java#L289
Regards
Thank you for your reply.
I have seen this part of the logic before. But it is rotating around the Z axis. This doesn't do what I want, I want to rotate around the Y axis.
@andresoviedo