Issue while implementing camera rotation along X and Z axis
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I'm implementing a camera which responds to change of mouse position. It's a more question of maths than of coding but I'd like to know how to use it as well.
I have a Camera object which rotates along the Y-axis when the mouse changes its X-position. This works as intended and I can rotate around the cube I'm drawing just fine. Now I would like to implement looking up and down triggered by mouse change vertically but the X and Z-axis are relative to the camera object so I can't just rotate along the X-axis but have to combine the X and Z-axis to do this in a fluid motion.
public class Camera {
public float moveSpeed = 0.05f;
private Vector3f position, rotation;
private float oldMouseX, oldMouseY, newMouseX, newMouseY, mouseSensitivity;
public Camera () {
position = new Vector3f(0f, 0f, 0f);
rotation = new Vector3f(0f, 0f, 0f);
mouseSensitivity = 0.1f;
oldMouseX = 0.0f;
oldMouseY = 0.0f;
newMouseX = 0.0f;
newMouseY = 0.0f;
}
public Camera (Vector3f pos, Vector3f rot) {
this.position = pos;
this.rotation = rot;
mouseSensitivity = 0.1f;
oldMouseX = 0.0f;
oldMouseY = 0.0f;
newMouseX = 0.0f;
newMouseY = 0.0f;
}
public void setCursor (int x, int y) {
oldMouseX = x;
oldMouseY = y;
newMouseX = x;
newMouseY = y;
}
public Matrix4f getViewMatrix () {
Matrix4f rotateX = new Matrix4f().rotate(rotation.x * (float)Math.PI / 180f, new Vector3f(1f, 0f, 0f));
Matrix4f rotateY = new Matrix4f().rotate(rotation.y * (float)Math.PI / 180f, new Vector3f(0f, 1f, 0f));
Matrix4f rotateZ = new Matrix4f().rotate(rotation.z * (float)Math.PI / 180f, new Vector3f(0f, 0f, 1f));
Matrix4f rotation = MatrixMath.mul(rotateX, MatrixMath.mul(rotateZ, rotateY));
Vector3f negPosition = new Vector3f(-position.x, -position.y, -position.z);
Matrix4f translation = new Matrix4f().translate(negPosition);
return MatrixMath.mul(translation, rotation);
}
public Vector3f getPosition() {
return position;
}
public Vector3f getRotation() {
return rotation;
}
public void update (Window window) {
if (window.isKeyDown(GLFW.GLFW_KEY_W)) {
position.x += Math.sin(Math.PI * rotation.y / 180) * -moveSpeed;
position.z += Math.cos(Math.PI * rotation.y / 180) * moveSpeed;
}
if (window.isKeyDown(GLFW.GLFW_KEY_S)) {
position.x -= Math.sin(Math.PI * rotation.y / 180) * -moveSpeed;
position.z -= Math.cos(Math.PI * rotation.y / 180) * moveSpeed;
}
if (window.isKeyDown(GLFW.GLFW_KEY_D)) {
position.x += Math.sin(Math.PI * (rotation.y - 90) / 180) * -moveSpeed;
position.z += Math.cos(Math.PI * (rotation.y - 90) / 180) * moveSpeed;
}
if (window.isKeyDown(GLFW.GLFW_KEY_A)) {
position.x -= Math.sin(Math.PI * (rotation.y - 90) / 180) * -moveSpeed;
position.z -= Math.cos(Math.PI * (rotation.y - 90) / 180) * moveSpeed;
}
if (window.isKeyDown(GLFW.GLFW_KEY_SPACE)) {
addPosition(0f, moveSpeed, 0f);
}
if (window.isKeyDown(GLFW.GLFW_KEY_LEFT_SHIFT)) {
addPosition(0f, -moveSpeed, 0f);
}
newMouseX = (float)window.getMouseX();
newMouseY = (float)window.getMouseY();
float dx = newMouseX - oldMouseX;
float dy = newMouseY - oldMouseY;
if (window.isMouseButtonDown(GLFW.GLFW_MOUSE_BUTTON_LEFT)) {
rotation.y += dx * mouseSensitivity;
}
//unPos = unPos.rotateAxis(dy * mouseSensitivity, (float)Math.cos(Math.PI * rotation.y / 180), 0f, (float)Math.sin(Math.PI * rotation.y / 180));
// rotation.x += (float)Math.cos(rotation.y * Math.PI / 180) * (dy * mouseSensitivity);
// rotation.z += (float)Math.sin(rotation.y * Math.PI / 180) * (dy * mouseSensitivity);
oldMouseX = newMouseX;
oldMouseY = newMouseY;
}
}
I don't think it's necessary to show you my Window class as the functions are quite self-explanitory. As you can see the part at the bottom that I commented out was my approach to solving the problem and at first it seemed to work but the rotating was slightly off.
I expect fluid up and down motion(that is, relative to the camera) but receive a weird rolling motion.
Any help is greatly appreciated!
java lwjgl
add a comment |
I'm implementing a camera which responds to change of mouse position. It's a more question of maths than of coding but I'd like to know how to use it as well.
I have a Camera object which rotates along the Y-axis when the mouse changes its X-position. This works as intended and I can rotate around the cube I'm drawing just fine. Now I would like to implement looking up and down triggered by mouse change vertically but the X and Z-axis are relative to the camera object so I can't just rotate along the X-axis but have to combine the X and Z-axis to do this in a fluid motion.
public class Camera {
public float moveSpeed = 0.05f;
private Vector3f position, rotation;
private float oldMouseX, oldMouseY, newMouseX, newMouseY, mouseSensitivity;
public Camera () {
position = new Vector3f(0f, 0f, 0f);
rotation = new Vector3f(0f, 0f, 0f);
mouseSensitivity = 0.1f;
oldMouseX = 0.0f;
oldMouseY = 0.0f;
newMouseX = 0.0f;
newMouseY = 0.0f;
}
public Camera (Vector3f pos, Vector3f rot) {
this.position = pos;
this.rotation = rot;
mouseSensitivity = 0.1f;
oldMouseX = 0.0f;
oldMouseY = 0.0f;
newMouseX = 0.0f;
newMouseY = 0.0f;
}
public void setCursor (int x, int y) {
oldMouseX = x;
oldMouseY = y;
newMouseX = x;
newMouseY = y;
}
public Matrix4f getViewMatrix () {
Matrix4f rotateX = new Matrix4f().rotate(rotation.x * (float)Math.PI / 180f, new Vector3f(1f, 0f, 0f));
Matrix4f rotateY = new Matrix4f().rotate(rotation.y * (float)Math.PI / 180f, new Vector3f(0f, 1f, 0f));
Matrix4f rotateZ = new Matrix4f().rotate(rotation.z * (float)Math.PI / 180f, new Vector3f(0f, 0f, 1f));
Matrix4f rotation = MatrixMath.mul(rotateX, MatrixMath.mul(rotateZ, rotateY));
Vector3f negPosition = new Vector3f(-position.x, -position.y, -position.z);
Matrix4f translation = new Matrix4f().translate(negPosition);
return MatrixMath.mul(translation, rotation);
}
public Vector3f getPosition() {
return position;
}
public Vector3f getRotation() {
return rotation;
}
public void update (Window window) {
if (window.isKeyDown(GLFW.GLFW_KEY_W)) {
position.x += Math.sin(Math.PI * rotation.y / 180) * -moveSpeed;
position.z += Math.cos(Math.PI * rotation.y / 180) * moveSpeed;
}
if (window.isKeyDown(GLFW.GLFW_KEY_S)) {
position.x -= Math.sin(Math.PI * rotation.y / 180) * -moveSpeed;
position.z -= Math.cos(Math.PI * rotation.y / 180) * moveSpeed;
}
if (window.isKeyDown(GLFW.GLFW_KEY_D)) {
position.x += Math.sin(Math.PI * (rotation.y - 90) / 180) * -moveSpeed;
position.z += Math.cos(Math.PI * (rotation.y - 90) / 180) * moveSpeed;
}
if (window.isKeyDown(GLFW.GLFW_KEY_A)) {
position.x -= Math.sin(Math.PI * (rotation.y - 90) / 180) * -moveSpeed;
position.z -= Math.cos(Math.PI * (rotation.y - 90) / 180) * moveSpeed;
}
if (window.isKeyDown(GLFW.GLFW_KEY_SPACE)) {
addPosition(0f, moveSpeed, 0f);
}
if (window.isKeyDown(GLFW.GLFW_KEY_LEFT_SHIFT)) {
addPosition(0f, -moveSpeed, 0f);
}
newMouseX = (float)window.getMouseX();
newMouseY = (float)window.getMouseY();
float dx = newMouseX - oldMouseX;
float dy = newMouseY - oldMouseY;
if (window.isMouseButtonDown(GLFW.GLFW_MOUSE_BUTTON_LEFT)) {
rotation.y += dx * mouseSensitivity;
}
//unPos = unPos.rotateAxis(dy * mouseSensitivity, (float)Math.cos(Math.PI * rotation.y / 180), 0f, (float)Math.sin(Math.PI * rotation.y / 180));
// rotation.x += (float)Math.cos(rotation.y * Math.PI / 180) * (dy * mouseSensitivity);
// rotation.z += (float)Math.sin(rotation.y * Math.PI / 180) * (dy * mouseSensitivity);
oldMouseX = newMouseX;
oldMouseY = newMouseY;
}
}
I don't think it's necessary to show you my Window class as the functions are quite self-explanitory. As you can see the part at the bottom that I commented out was my approach to solving the problem and at first it seemed to work but the rotating was slightly off.
I expect fluid up and down motion(that is, relative to the camera) but receive a weird rolling motion.
Any help is greatly appreciated!
java lwjgl
Your problem is probably based aroundthe X and Z-axis are relative to the camera object
. If you fixed the X, Y and Z axis in space, you could just track how far the mouse has moved from 0, 0 and apply the transformation from a static point.
– Jason
Jan 3 at 3:53
rotate around x first and then y
– Alex
Jan 3 at 12:45
@alex I've tried that but the rotation still goes around the absolute X-axis and not the relative one. The Y-axis works great though
– J. Lengel
Jan 3 at 14:07
@Jason I also have absolute X, Y and Z-axes in model but I don't know how to transfer the relative rotation of the camera onto the absolute X, and Z-axes
– J. Lengel
Jan 3 at 14:09
add a comment |
I'm implementing a camera which responds to change of mouse position. It's a more question of maths than of coding but I'd like to know how to use it as well.
I have a Camera object which rotates along the Y-axis when the mouse changes its X-position. This works as intended and I can rotate around the cube I'm drawing just fine. Now I would like to implement looking up and down triggered by mouse change vertically but the X and Z-axis are relative to the camera object so I can't just rotate along the X-axis but have to combine the X and Z-axis to do this in a fluid motion.
public class Camera {
public float moveSpeed = 0.05f;
private Vector3f position, rotation;
private float oldMouseX, oldMouseY, newMouseX, newMouseY, mouseSensitivity;
public Camera () {
position = new Vector3f(0f, 0f, 0f);
rotation = new Vector3f(0f, 0f, 0f);
mouseSensitivity = 0.1f;
oldMouseX = 0.0f;
oldMouseY = 0.0f;
newMouseX = 0.0f;
newMouseY = 0.0f;
}
public Camera (Vector3f pos, Vector3f rot) {
this.position = pos;
this.rotation = rot;
mouseSensitivity = 0.1f;
oldMouseX = 0.0f;
oldMouseY = 0.0f;
newMouseX = 0.0f;
newMouseY = 0.0f;
}
public void setCursor (int x, int y) {
oldMouseX = x;
oldMouseY = y;
newMouseX = x;
newMouseY = y;
}
public Matrix4f getViewMatrix () {
Matrix4f rotateX = new Matrix4f().rotate(rotation.x * (float)Math.PI / 180f, new Vector3f(1f, 0f, 0f));
Matrix4f rotateY = new Matrix4f().rotate(rotation.y * (float)Math.PI / 180f, new Vector3f(0f, 1f, 0f));
Matrix4f rotateZ = new Matrix4f().rotate(rotation.z * (float)Math.PI / 180f, new Vector3f(0f, 0f, 1f));
Matrix4f rotation = MatrixMath.mul(rotateX, MatrixMath.mul(rotateZ, rotateY));
Vector3f negPosition = new Vector3f(-position.x, -position.y, -position.z);
Matrix4f translation = new Matrix4f().translate(negPosition);
return MatrixMath.mul(translation, rotation);
}
public Vector3f getPosition() {
return position;
}
public Vector3f getRotation() {
return rotation;
}
public void update (Window window) {
if (window.isKeyDown(GLFW.GLFW_KEY_W)) {
position.x += Math.sin(Math.PI * rotation.y / 180) * -moveSpeed;
position.z += Math.cos(Math.PI * rotation.y / 180) * moveSpeed;
}
if (window.isKeyDown(GLFW.GLFW_KEY_S)) {
position.x -= Math.sin(Math.PI * rotation.y / 180) * -moveSpeed;
position.z -= Math.cos(Math.PI * rotation.y / 180) * moveSpeed;
}
if (window.isKeyDown(GLFW.GLFW_KEY_D)) {
position.x += Math.sin(Math.PI * (rotation.y - 90) / 180) * -moveSpeed;
position.z += Math.cos(Math.PI * (rotation.y - 90) / 180) * moveSpeed;
}
if (window.isKeyDown(GLFW.GLFW_KEY_A)) {
position.x -= Math.sin(Math.PI * (rotation.y - 90) / 180) * -moveSpeed;
position.z -= Math.cos(Math.PI * (rotation.y - 90) / 180) * moveSpeed;
}
if (window.isKeyDown(GLFW.GLFW_KEY_SPACE)) {
addPosition(0f, moveSpeed, 0f);
}
if (window.isKeyDown(GLFW.GLFW_KEY_LEFT_SHIFT)) {
addPosition(0f, -moveSpeed, 0f);
}
newMouseX = (float)window.getMouseX();
newMouseY = (float)window.getMouseY();
float dx = newMouseX - oldMouseX;
float dy = newMouseY - oldMouseY;
if (window.isMouseButtonDown(GLFW.GLFW_MOUSE_BUTTON_LEFT)) {
rotation.y += dx * mouseSensitivity;
}
//unPos = unPos.rotateAxis(dy * mouseSensitivity, (float)Math.cos(Math.PI * rotation.y / 180), 0f, (float)Math.sin(Math.PI * rotation.y / 180));
// rotation.x += (float)Math.cos(rotation.y * Math.PI / 180) * (dy * mouseSensitivity);
// rotation.z += (float)Math.sin(rotation.y * Math.PI / 180) * (dy * mouseSensitivity);
oldMouseX = newMouseX;
oldMouseY = newMouseY;
}
}
I don't think it's necessary to show you my Window class as the functions are quite self-explanitory. As you can see the part at the bottom that I commented out was my approach to solving the problem and at first it seemed to work but the rotating was slightly off.
I expect fluid up and down motion(that is, relative to the camera) but receive a weird rolling motion.
Any help is greatly appreciated!
java lwjgl
I'm implementing a camera which responds to change of mouse position. It's a more question of maths than of coding but I'd like to know how to use it as well.
I have a Camera object which rotates along the Y-axis when the mouse changes its X-position. This works as intended and I can rotate around the cube I'm drawing just fine. Now I would like to implement looking up and down triggered by mouse change vertically but the X and Z-axis are relative to the camera object so I can't just rotate along the X-axis but have to combine the X and Z-axis to do this in a fluid motion.
public class Camera {
public float moveSpeed = 0.05f;
private Vector3f position, rotation;
private float oldMouseX, oldMouseY, newMouseX, newMouseY, mouseSensitivity;
public Camera () {
position = new Vector3f(0f, 0f, 0f);
rotation = new Vector3f(0f, 0f, 0f);
mouseSensitivity = 0.1f;
oldMouseX = 0.0f;
oldMouseY = 0.0f;
newMouseX = 0.0f;
newMouseY = 0.0f;
}
public Camera (Vector3f pos, Vector3f rot) {
this.position = pos;
this.rotation = rot;
mouseSensitivity = 0.1f;
oldMouseX = 0.0f;
oldMouseY = 0.0f;
newMouseX = 0.0f;
newMouseY = 0.0f;
}
public void setCursor (int x, int y) {
oldMouseX = x;
oldMouseY = y;
newMouseX = x;
newMouseY = y;
}
public Matrix4f getViewMatrix () {
Matrix4f rotateX = new Matrix4f().rotate(rotation.x * (float)Math.PI / 180f, new Vector3f(1f, 0f, 0f));
Matrix4f rotateY = new Matrix4f().rotate(rotation.y * (float)Math.PI / 180f, new Vector3f(0f, 1f, 0f));
Matrix4f rotateZ = new Matrix4f().rotate(rotation.z * (float)Math.PI / 180f, new Vector3f(0f, 0f, 1f));
Matrix4f rotation = MatrixMath.mul(rotateX, MatrixMath.mul(rotateZ, rotateY));
Vector3f negPosition = new Vector3f(-position.x, -position.y, -position.z);
Matrix4f translation = new Matrix4f().translate(negPosition);
return MatrixMath.mul(translation, rotation);
}
public Vector3f getPosition() {
return position;
}
public Vector3f getRotation() {
return rotation;
}
public void update (Window window) {
if (window.isKeyDown(GLFW.GLFW_KEY_W)) {
position.x += Math.sin(Math.PI * rotation.y / 180) * -moveSpeed;
position.z += Math.cos(Math.PI * rotation.y / 180) * moveSpeed;
}
if (window.isKeyDown(GLFW.GLFW_KEY_S)) {
position.x -= Math.sin(Math.PI * rotation.y / 180) * -moveSpeed;
position.z -= Math.cos(Math.PI * rotation.y / 180) * moveSpeed;
}
if (window.isKeyDown(GLFW.GLFW_KEY_D)) {
position.x += Math.sin(Math.PI * (rotation.y - 90) / 180) * -moveSpeed;
position.z += Math.cos(Math.PI * (rotation.y - 90) / 180) * moveSpeed;
}
if (window.isKeyDown(GLFW.GLFW_KEY_A)) {
position.x -= Math.sin(Math.PI * (rotation.y - 90) / 180) * -moveSpeed;
position.z -= Math.cos(Math.PI * (rotation.y - 90) / 180) * moveSpeed;
}
if (window.isKeyDown(GLFW.GLFW_KEY_SPACE)) {
addPosition(0f, moveSpeed, 0f);
}
if (window.isKeyDown(GLFW.GLFW_KEY_LEFT_SHIFT)) {
addPosition(0f, -moveSpeed, 0f);
}
newMouseX = (float)window.getMouseX();
newMouseY = (float)window.getMouseY();
float dx = newMouseX - oldMouseX;
float dy = newMouseY - oldMouseY;
if (window.isMouseButtonDown(GLFW.GLFW_MOUSE_BUTTON_LEFT)) {
rotation.y += dx * mouseSensitivity;
}
//unPos = unPos.rotateAxis(dy * mouseSensitivity, (float)Math.cos(Math.PI * rotation.y / 180), 0f, (float)Math.sin(Math.PI * rotation.y / 180));
// rotation.x += (float)Math.cos(rotation.y * Math.PI / 180) * (dy * mouseSensitivity);
// rotation.z += (float)Math.sin(rotation.y * Math.PI / 180) * (dy * mouseSensitivity);
oldMouseX = newMouseX;
oldMouseY = newMouseY;
}
}
I don't think it's necessary to show you my Window class as the functions are quite self-explanitory. As you can see the part at the bottom that I commented out was my approach to solving the problem and at first it seemed to work but the rotating was slightly off.
I expect fluid up and down motion(that is, relative to the camera) but receive a weird rolling motion.
Any help is greatly appreciated!
java lwjgl
java lwjgl
asked Jan 3 at 3:42
J. LengelJ. Lengel
11010
11010
Your problem is probably based aroundthe X and Z-axis are relative to the camera object
. If you fixed the X, Y and Z axis in space, you could just track how far the mouse has moved from 0, 0 and apply the transformation from a static point.
– Jason
Jan 3 at 3:53
rotate around x first and then y
– Alex
Jan 3 at 12:45
@alex I've tried that but the rotation still goes around the absolute X-axis and not the relative one. The Y-axis works great though
– J. Lengel
Jan 3 at 14:07
@Jason I also have absolute X, Y and Z-axes in model but I don't know how to transfer the relative rotation of the camera onto the absolute X, and Z-axes
– J. Lengel
Jan 3 at 14:09
add a comment |
Your problem is probably based aroundthe X and Z-axis are relative to the camera object
. If you fixed the X, Y and Z axis in space, you could just track how far the mouse has moved from 0, 0 and apply the transformation from a static point.
– Jason
Jan 3 at 3:53
rotate around x first and then y
– Alex
Jan 3 at 12:45
@alex I've tried that but the rotation still goes around the absolute X-axis and not the relative one. The Y-axis works great though
– J. Lengel
Jan 3 at 14:07
@Jason I also have absolute X, Y and Z-axes in model but I don't know how to transfer the relative rotation of the camera onto the absolute X, and Z-axes
– J. Lengel
Jan 3 at 14:09
Your problem is probably based around
the X and Z-axis are relative to the camera object
. If you fixed the X, Y and Z axis in space, you could just track how far the mouse has moved from 0, 0 and apply the transformation from a static point.– Jason
Jan 3 at 3:53
Your problem is probably based around
the X and Z-axis are relative to the camera object
. If you fixed the X, Y and Z axis in space, you could just track how far the mouse has moved from 0, 0 and apply the transformation from a static point.– Jason
Jan 3 at 3:53
rotate around x first and then y
– Alex
Jan 3 at 12:45
rotate around x first and then y
– Alex
Jan 3 at 12:45
@alex I've tried that but the rotation still goes around the absolute X-axis and not the relative one. The Y-axis works great though
– J. Lengel
Jan 3 at 14:07
@alex I've tried that but the rotation still goes around the absolute X-axis and not the relative one. The Y-axis works great though
– J. Lengel
Jan 3 at 14:07
@Jason I also have absolute X, Y and Z-axes in model but I don't know how to transfer the relative rotation of the camera onto the absolute X, and Z-axes
– J. Lengel
Jan 3 at 14:09
@Jason I also have absolute X, Y and Z-axes in model but I don't know how to transfer the relative rotation of the camera onto the absolute X, and Z-axes
– J. Lengel
Jan 3 at 14:09
add a comment |
1 Answer
1
active
oldest
votes
I fixed my problem. It's strange but I have to multiply the Y-rotation matrix by the X-rotation matrix. That doesn't make sense to me but it works. Thanks for your help!
You should use a look at camera instead it's much easier and much more useful.
– zin
Jan 20 at 11:37
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54016063%2fissue-while-implementing-camera-rotation-along-x-and-z-axis%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I fixed my problem. It's strange but I have to multiply the Y-rotation matrix by the X-rotation matrix. That doesn't make sense to me but it works. Thanks for your help!
You should use a look at camera instead it's much easier and much more useful.
– zin
Jan 20 at 11:37
add a comment |
I fixed my problem. It's strange but I have to multiply the Y-rotation matrix by the X-rotation matrix. That doesn't make sense to me but it works. Thanks for your help!
You should use a look at camera instead it's much easier and much more useful.
– zin
Jan 20 at 11:37
add a comment |
I fixed my problem. It's strange but I have to multiply the Y-rotation matrix by the X-rotation matrix. That doesn't make sense to me but it works. Thanks for your help!
I fixed my problem. It's strange but I have to multiply the Y-rotation matrix by the X-rotation matrix. That doesn't make sense to me but it works. Thanks for your help!
answered Jan 3 at 14:15
J. LengelJ. Lengel
11010
11010
You should use a look at camera instead it's much easier and much more useful.
– zin
Jan 20 at 11:37
add a comment |
You should use a look at camera instead it's much easier and much more useful.
– zin
Jan 20 at 11:37
You should use a look at camera instead it's much easier and much more useful.
– zin
Jan 20 at 11:37
You should use a look at camera instead it's much easier and much more useful.
– zin
Jan 20 at 11:37
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54016063%2fissue-while-implementing-camera-rotation-along-x-and-z-axis%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Your problem is probably based around
the X and Z-axis are relative to the camera object
. If you fixed the X, Y and Z axis in space, you could just track how far the mouse has moved from 0, 0 and apply the transformation from a static point.– Jason
Jan 3 at 3:53
rotate around x first and then y
– Alex
Jan 3 at 12:45
@alex I've tried that but the rotation still goes around the absolute X-axis and not the relative one. The Y-axis works great though
– J. Lengel
Jan 3 at 14:07
@Jason I also have absolute X, Y and Z-axes in model but I don't know how to transfer the relative rotation of the camera onto the absolute X, and Z-axes
– J. Lengel
Jan 3 at 14:09