How do you implement the rotation of the shape in place and the movement in a rotated state in OpenGL?
How do you implement the rotation of the shape in place and the movement in a rotated state?
I want to move the rotated shape towards the x and y axes of the screen I see.
I have already made the shape move in the direction of the x-axis and y-axis when I press the key.
But I can't move the way I want to. It's weird.
How do I set up the code to move the way I want to?
I'll put the code up for now.
glTranslatef(2.5 + puzX1, 2 + puzY1, 0);
glRotatef(100, 0.0, 0.0, 1.0);
glRotatef(puzang1, 0.0, 0.0, 1.0);
glTranslatef(-2.5+puzX1, -2+puzY1, 0);
I wrote the code to make it spin in place.
The code at the top and bottom of the code is a code that moves to the center of the shape and then returns it to its place.
What should I add?
Which part should be modified?
I am not good at English.
i'm so sorry
Can you help me?
opengl rotation move translate coordinate-transformation
add a comment |
How do you implement the rotation of the shape in place and the movement in a rotated state?
I want to move the rotated shape towards the x and y axes of the screen I see.
I have already made the shape move in the direction of the x-axis and y-axis when I press the key.
But I can't move the way I want to. It's weird.
How do I set up the code to move the way I want to?
I'll put the code up for now.
glTranslatef(2.5 + puzX1, 2 + puzY1, 0);
glRotatef(100, 0.0, 0.0, 1.0);
glRotatef(puzang1, 0.0, 0.0, 1.0);
glTranslatef(-2.5+puzX1, -2+puzY1, 0);
I wrote the code to make it spin in place.
The code at the top and bottom of the code is a code that moves to the center of the shape and then returns it to its place.
What should I add?
Which part should be modified?
I am not good at English.
i'm so sorry
Can you help me?
opengl rotation move translate coordinate-transformation
add a comment |
How do you implement the rotation of the shape in place and the movement in a rotated state?
I want to move the rotated shape towards the x and y axes of the screen I see.
I have already made the shape move in the direction of the x-axis and y-axis when I press the key.
But I can't move the way I want to. It's weird.
How do I set up the code to move the way I want to?
I'll put the code up for now.
glTranslatef(2.5 + puzX1, 2 + puzY1, 0);
glRotatef(100, 0.0, 0.0, 1.0);
glRotatef(puzang1, 0.0, 0.0, 1.0);
glTranslatef(-2.5+puzX1, -2+puzY1, 0);
I wrote the code to make it spin in place.
The code at the top and bottom of the code is a code that moves to the center of the shape and then returns it to its place.
What should I add?
Which part should be modified?
I am not good at English.
i'm so sorry
Can you help me?
opengl rotation move translate coordinate-transformation
How do you implement the rotation of the shape in place and the movement in a rotated state?
I want to move the rotated shape towards the x and y axes of the screen I see.
I have already made the shape move in the direction of the x-axis and y-axis when I press the key.
But I can't move the way I want to. It's weird.
How do I set up the code to move the way I want to?
I'll put the code up for now.
glTranslatef(2.5 + puzX1, 2 + puzY1, 0);
glRotatef(100, 0.0, 0.0, 1.0);
glRotatef(puzang1, 0.0, 0.0, 1.0);
glTranslatef(-2.5+puzX1, -2+puzY1, 0);
I wrote the code to make it spin in place.
The code at the top and bottom of the code is a code that moves to the center of the shape and then returns it to its place.
What should I add?
Which part should be modified?
I am not good at English.
i'm so sorry
Can you help me?
opengl rotation move translate coordinate-transformation
opengl rotation move translate coordinate-transformation
edited Nov 30 '18 at 6:14
Rabbid76
42.3k123353
42.3k123353
asked Nov 23 '18 at 7:51
정나영정나영
134
134
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Note, that drawing by glBegin
/glEnd
sequences, the fixed function pipeline matrix stack, is deprecated since decades.
Read about Fixed Function Pipeline and see Vertex Specification and Shader for a state of the art way of rendering.
How do you implement the rotation of the shape in place?
If the shade should rotate on its local axis, then you have to do the rotation before the translation. In the code this means the rotation instruction has to be after the translation instruction:
glTranslatef(2.5 + puzX1, 2 + puzY1, 0);
glRotatef(puzang1, 0.0, 0.0, 1.0);
glRotatef(100, 0.0, 0.0, 1.0);
See also OpenGL translation before and after a rotation
Explanation:
Translation: See the documentation of glTranslate
:
glTranslate
produces a translation byx y z
. The current matrix (seeglMatrixMode
) is multiplied by this translation matrix, with the product replacing the current matrix.
Rotation: See the documentation of glRotate
:
glRotate
produces a rotation of angle degrees around the vectorx y z
. The current matrix (seeglMatrixMode
) is multiplied by a rotation matrix with the product replacing the current matrix.
The translation matrix looks like this:
Matrix4x4 translate;
translate[0] : ( 1, 0, 0, 0 )
translate[1] : ( 0, 1, 0, 0 )
translate[2] : ( 0, 0, 1, 0 )
translate[3] : ( tx, ty, tz, 1 )
And the rotation matrix around Z-Axis looks like this:
Matrix4x4 rotate;
float angle;
rotate[0] : ( cos(angle), sin(angle), 0, 0 )
rotate[1] : ( -sin(angle), cos(angle), 0, 0 )
rotate[2] : ( 0, 0, 1, 0 )
rotate[3] : ( 0, 0, 0, 1 )
The result of translate * rotate
is this:
glTranslate( ..... );
glRotate( ..... );
model[0] : ( cos(angle), sin(angle), 0, 0 )
model[1] : ( -sin(angle), cos(angle), 0, 0 )
model[2] : ( 0, 1, 0, 0 )
model[3] : ( tx, ty, tz, 1 )
The result of rotate * translate
is:
glRotate( ..... );
glTranslate( ..... );
model[0] : ( cos(angle), sin(angle), 0, 0 )
model[1] : ( -sin(angle), cos(angle), 0, 0 )
model[2] : ( 0, 0, 1, 0 )
model[3] : ( cos(angle)*tx - sin(angle)*tx, sin(angle)*ty + cos(angle)*ty, tz, 1 )
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%2f53442596%2fhow-do-you-implement-the-rotation-of-the-shape-in-place-and-the-movement-in-a-ro%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
Note, that drawing by glBegin
/glEnd
sequences, the fixed function pipeline matrix stack, is deprecated since decades.
Read about Fixed Function Pipeline and see Vertex Specification and Shader for a state of the art way of rendering.
How do you implement the rotation of the shape in place?
If the shade should rotate on its local axis, then you have to do the rotation before the translation. In the code this means the rotation instruction has to be after the translation instruction:
glTranslatef(2.5 + puzX1, 2 + puzY1, 0);
glRotatef(puzang1, 0.0, 0.0, 1.0);
glRotatef(100, 0.0, 0.0, 1.0);
See also OpenGL translation before and after a rotation
Explanation:
Translation: See the documentation of glTranslate
:
glTranslate
produces a translation byx y z
. The current matrix (seeglMatrixMode
) is multiplied by this translation matrix, with the product replacing the current matrix.
Rotation: See the documentation of glRotate
:
glRotate
produces a rotation of angle degrees around the vectorx y z
. The current matrix (seeglMatrixMode
) is multiplied by a rotation matrix with the product replacing the current matrix.
The translation matrix looks like this:
Matrix4x4 translate;
translate[0] : ( 1, 0, 0, 0 )
translate[1] : ( 0, 1, 0, 0 )
translate[2] : ( 0, 0, 1, 0 )
translate[3] : ( tx, ty, tz, 1 )
And the rotation matrix around Z-Axis looks like this:
Matrix4x4 rotate;
float angle;
rotate[0] : ( cos(angle), sin(angle), 0, 0 )
rotate[1] : ( -sin(angle), cos(angle), 0, 0 )
rotate[2] : ( 0, 0, 1, 0 )
rotate[3] : ( 0, 0, 0, 1 )
The result of translate * rotate
is this:
glTranslate( ..... );
glRotate( ..... );
model[0] : ( cos(angle), sin(angle), 0, 0 )
model[1] : ( -sin(angle), cos(angle), 0, 0 )
model[2] : ( 0, 1, 0, 0 )
model[3] : ( tx, ty, tz, 1 )
The result of rotate * translate
is:
glRotate( ..... );
glTranslate( ..... );
model[0] : ( cos(angle), sin(angle), 0, 0 )
model[1] : ( -sin(angle), cos(angle), 0, 0 )
model[2] : ( 0, 0, 1, 0 )
model[3] : ( cos(angle)*tx - sin(angle)*tx, sin(angle)*ty + cos(angle)*ty, tz, 1 )
add a comment |
Note, that drawing by glBegin
/glEnd
sequences, the fixed function pipeline matrix stack, is deprecated since decades.
Read about Fixed Function Pipeline and see Vertex Specification and Shader for a state of the art way of rendering.
How do you implement the rotation of the shape in place?
If the shade should rotate on its local axis, then you have to do the rotation before the translation. In the code this means the rotation instruction has to be after the translation instruction:
glTranslatef(2.5 + puzX1, 2 + puzY1, 0);
glRotatef(puzang1, 0.0, 0.0, 1.0);
glRotatef(100, 0.0, 0.0, 1.0);
See also OpenGL translation before and after a rotation
Explanation:
Translation: See the documentation of glTranslate
:
glTranslate
produces a translation byx y z
. The current matrix (seeglMatrixMode
) is multiplied by this translation matrix, with the product replacing the current matrix.
Rotation: See the documentation of glRotate
:
glRotate
produces a rotation of angle degrees around the vectorx y z
. The current matrix (seeglMatrixMode
) is multiplied by a rotation matrix with the product replacing the current matrix.
The translation matrix looks like this:
Matrix4x4 translate;
translate[0] : ( 1, 0, 0, 0 )
translate[1] : ( 0, 1, 0, 0 )
translate[2] : ( 0, 0, 1, 0 )
translate[3] : ( tx, ty, tz, 1 )
And the rotation matrix around Z-Axis looks like this:
Matrix4x4 rotate;
float angle;
rotate[0] : ( cos(angle), sin(angle), 0, 0 )
rotate[1] : ( -sin(angle), cos(angle), 0, 0 )
rotate[2] : ( 0, 0, 1, 0 )
rotate[3] : ( 0, 0, 0, 1 )
The result of translate * rotate
is this:
glTranslate( ..... );
glRotate( ..... );
model[0] : ( cos(angle), sin(angle), 0, 0 )
model[1] : ( -sin(angle), cos(angle), 0, 0 )
model[2] : ( 0, 1, 0, 0 )
model[3] : ( tx, ty, tz, 1 )
The result of rotate * translate
is:
glRotate( ..... );
glTranslate( ..... );
model[0] : ( cos(angle), sin(angle), 0, 0 )
model[1] : ( -sin(angle), cos(angle), 0, 0 )
model[2] : ( 0, 0, 1, 0 )
model[3] : ( cos(angle)*tx - sin(angle)*tx, sin(angle)*ty + cos(angle)*ty, tz, 1 )
add a comment |
Note, that drawing by glBegin
/glEnd
sequences, the fixed function pipeline matrix stack, is deprecated since decades.
Read about Fixed Function Pipeline and see Vertex Specification and Shader for a state of the art way of rendering.
How do you implement the rotation of the shape in place?
If the shade should rotate on its local axis, then you have to do the rotation before the translation. In the code this means the rotation instruction has to be after the translation instruction:
glTranslatef(2.5 + puzX1, 2 + puzY1, 0);
glRotatef(puzang1, 0.0, 0.0, 1.0);
glRotatef(100, 0.0, 0.0, 1.0);
See also OpenGL translation before and after a rotation
Explanation:
Translation: See the documentation of glTranslate
:
glTranslate
produces a translation byx y z
. The current matrix (seeglMatrixMode
) is multiplied by this translation matrix, with the product replacing the current matrix.
Rotation: See the documentation of glRotate
:
glRotate
produces a rotation of angle degrees around the vectorx y z
. The current matrix (seeglMatrixMode
) is multiplied by a rotation matrix with the product replacing the current matrix.
The translation matrix looks like this:
Matrix4x4 translate;
translate[0] : ( 1, 0, 0, 0 )
translate[1] : ( 0, 1, 0, 0 )
translate[2] : ( 0, 0, 1, 0 )
translate[3] : ( tx, ty, tz, 1 )
And the rotation matrix around Z-Axis looks like this:
Matrix4x4 rotate;
float angle;
rotate[0] : ( cos(angle), sin(angle), 0, 0 )
rotate[1] : ( -sin(angle), cos(angle), 0, 0 )
rotate[2] : ( 0, 0, 1, 0 )
rotate[3] : ( 0, 0, 0, 1 )
The result of translate * rotate
is this:
glTranslate( ..... );
glRotate( ..... );
model[0] : ( cos(angle), sin(angle), 0, 0 )
model[1] : ( -sin(angle), cos(angle), 0, 0 )
model[2] : ( 0, 1, 0, 0 )
model[3] : ( tx, ty, tz, 1 )
The result of rotate * translate
is:
glRotate( ..... );
glTranslate( ..... );
model[0] : ( cos(angle), sin(angle), 0, 0 )
model[1] : ( -sin(angle), cos(angle), 0, 0 )
model[2] : ( 0, 0, 1, 0 )
model[3] : ( cos(angle)*tx - sin(angle)*tx, sin(angle)*ty + cos(angle)*ty, tz, 1 )
Note, that drawing by glBegin
/glEnd
sequences, the fixed function pipeline matrix stack, is deprecated since decades.
Read about Fixed Function Pipeline and see Vertex Specification and Shader for a state of the art way of rendering.
How do you implement the rotation of the shape in place?
If the shade should rotate on its local axis, then you have to do the rotation before the translation. In the code this means the rotation instruction has to be after the translation instruction:
glTranslatef(2.5 + puzX1, 2 + puzY1, 0);
glRotatef(puzang1, 0.0, 0.0, 1.0);
glRotatef(100, 0.0, 0.0, 1.0);
See also OpenGL translation before and after a rotation
Explanation:
Translation: See the documentation of glTranslate
:
glTranslate
produces a translation byx y z
. The current matrix (seeglMatrixMode
) is multiplied by this translation matrix, with the product replacing the current matrix.
Rotation: See the documentation of glRotate
:
glRotate
produces a rotation of angle degrees around the vectorx y z
. The current matrix (seeglMatrixMode
) is multiplied by a rotation matrix with the product replacing the current matrix.
The translation matrix looks like this:
Matrix4x4 translate;
translate[0] : ( 1, 0, 0, 0 )
translate[1] : ( 0, 1, 0, 0 )
translate[2] : ( 0, 0, 1, 0 )
translate[3] : ( tx, ty, tz, 1 )
And the rotation matrix around Z-Axis looks like this:
Matrix4x4 rotate;
float angle;
rotate[0] : ( cos(angle), sin(angle), 0, 0 )
rotate[1] : ( -sin(angle), cos(angle), 0, 0 )
rotate[2] : ( 0, 0, 1, 0 )
rotate[3] : ( 0, 0, 0, 1 )
The result of translate * rotate
is this:
glTranslate( ..... );
glRotate( ..... );
model[0] : ( cos(angle), sin(angle), 0, 0 )
model[1] : ( -sin(angle), cos(angle), 0, 0 )
model[2] : ( 0, 1, 0, 0 )
model[3] : ( tx, ty, tz, 1 )
The result of rotate * translate
is:
glRotate( ..... );
glTranslate( ..... );
model[0] : ( cos(angle), sin(angle), 0, 0 )
model[1] : ( -sin(angle), cos(angle), 0, 0 )
model[2] : ( 0, 0, 1, 0 )
model[3] : ( cos(angle)*tx - sin(angle)*tx, sin(angle)*ty + cos(angle)*ty, tz, 1 )
edited Nov 23 '18 at 8:38
answered Nov 23 '18 at 8:09
Rabbid76Rabbid76
42.3k123353
42.3k123353
add a comment |
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%2f53442596%2fhow-do-you-implement-the-rotation-of-the-shape-in-place-and-the-movement-in-a-ro%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