rotation matrix is not getting applied correctly to a vector
i am trying to learn transformation in OpenGL & I am using glm for math calculation. I have a vector& I want to apply some rotation to that vector.but i get output as vec3(0,0,0)
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/ext/matrix_float4x4.hpp> // mat4x4
#include <glm/ext/matrix_transform.hpp> // translate, rotate, scale, identity
#include <glm/gtx/string_cast.hpp>
#include<iostream>
int main(){
//define a 4x4 model matrix
glm::mat4 model;
//define a vector
glm::vec4 Position = glm::vec4(glm::vec3(0.4,0.2,0.2), 1.0);
//create a model matrix with rotation of 45 degrees around z aixs
model = glm::rotate(model, 45.0f, glm::vec3(0.0f, 0.0f, 1.0f));
//print the final vector position after rotation is applied
std::cout<< glm::to_string(model*Position) <<std::endl;
return 0;
}
opengl glm-math
add a comment |
i am trying to learn transformation in OpenGL & I am using glm for math calculation. I have a vector& I want to apply some rotation to that vector.but i get output as vec3(0,0,0)
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/ext/matrix_float4x4.hpp> // mat4x4
#include <glm/ext/matrix_transform.hpp> // translate, rotate, scale, identity
#include <glm/gtx/string_cast.hpp>
#include<iostream>
int main(){
//define a 4x4 model matrix
glm::mat4 model;
//define a vector
glm::vec4 Position = glm::vec4(glm::vec3(0.4,0.2,0.2), 1.0);
//create a model matrix with rotation of 45 degrees around z aixs
model = glm::rotate(model, 45.0f, glm::vec3(0.0f, 0.0f, 1.0f));
//print the final vector position after rotation is applied
std::cout<< glm::to_string(model*Position) <<std::endl;
return 0;
}
opengl glm-math
Possible duplicate of Why is the sprite not rendering in OpenGL?
– Rabbid76
Nov 19 '18 at 18:24
add a comment |
i am trying to learn transformation in OpenGL & I am using glm for math calculation. I have a vector& I want to apply some rotation to that vector.but i get output as vec3(0,0,0)
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/ext/matrix_float4x4.hpp> // mat4x4
#include <glm/ext/matrix_transform.hpp> // translate, rotate, scale, identity
#include <glm/gtx/string_cast.hpp>
#include<iostream>
int main(){
//define a 4x4 model matrix
glm::mat4 model;
//define a vector
glm::vec4 Position = glm::vec4(glm::vec3(0.4,0.2,0.2), 1.0);
//create a model matrix with rotation of 45 degrees around z aixs
model = glm::rotate(model, 45.0f, glm::vec3(0.0f, 0.0f, 1.0f));
//print the final vector position after rotation is applied
std::cout<< glm::to_string(model*Position) <<std::endl;
return 0;
}
opengl glm-math
i am trying to learn transformation in OpenGL & I am using glm for math calculation. I have a vector& I want to apply some rotation to that vector.but i get output as vec3(0,0,0)
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/ext/matrix_float4x4.hpp> // mat4x4
#include <glm/ext/matrix_transform.hpp> // translate, rotate, scale, identity
#include <glm/gtx/string_cast.hpp>
#include<iostream>
int main(){
//define a 4x4 model matrix
glm::mat4 model;
//define a vector
glm::vec4 Position = glm::vec4(glm::vec3(0.4,0.2,0.2), 1.0);
//create a model matrix with rotation of 45 degrees around z aixs
model = glm::rotate(model, 45.0f, glm::vec3(0.0f, 0.0f, 1.0f));
//print the final vector position after rotation is applied
std::cout<< glm::to_string(model*Position) <<std::endl;
return 0;
}
opengl glm-math
opengl glm-math
edited Nov 19 '18 at 18:44
Nicol Bolas
285k33472645
285k33472645
asked Nov 19 '18 at 18:14
anekixanekix
929620
929620
Possible duplicate of Why is the sprite not rendering in OpenGL?
– Rabbid76
Nov 19 '18 at 18:24
add a comment |
Possible duplicate of Why is the sprite not rendering in OpenGL?
– Rabbid76
Nov 19 '18 at 18:24
Possible duplicate of Why is the sprite not rendering in OpenGL?
– Rabbid76
Nov 19 '18 at 18:24
Possible duplicate of Why is the sprite not rendering in OpenGL?
– Rabbid76
Nov 19 '18 at 18:24
add a comment |
1 Answer
1
active
oldest
votes
You did not initialize your model matrix.
Should be:
glm::mat4 model = glm::mat4(1.0f);
to initialize it to identity matrix.
thanks i missed that :)
– anekix
Nov 19 '18 at 18:26
but why initialize to an identity matrix?
– anekix
Nov 19 '18 at 18:29
You can initialize it to whatever you want. But if you want the model matrix to only contain the rotation you have to use identity, rotation multiplied by identity is rotation.
– Rhu Mage
Nov 19 '18 at 18:52
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%2f53380445%2frotation-matrix-is-not-getting-applied-correctly-to-a-vector%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
You did not initialize your model matrix.
Should be:
glm::mat4 model = glm::mat4(1.0f);
to initialize it to identity matrix.
thanks i missed that :)
– anekix
Nov 19 '18 at 18:26
but why initialize to an identity matrix?
– anekix
Nov 19 '18 at 18:29
You can initialize it to whatever you want. But if you want the model matrix to only contain the rotation you have to use identity, rotation multiplied by identity is rotation.
– Rhu Mage
Nov 19 '18 at 18:52
add a comment |
You did not initialize your model matrix.
Should be:
glm::mat4 model = glm::mat4(1.0f);
to initialize it to identity matrix.
thanks i missed that :)
– anekix
Nov 19 '18 at 18:26
but why initialize to an identity matrix?
– anekix
Nov 19 '18 at 18:29
You can initialize it to whatever you want. But if you want the model matrix to only contain the rotation you have to use identity, rotation multiplied by identity is rotation.
– Rhu Mage
Nov 19 '18 at 18:52
add a comment |
You did not initialize your model matrix.
Should be:
glm::mat4 model = glm::mat4(1.0f);
to initialize it to identity matrix.
You did not initialize your model matrix.
Should be:
glm::mat4 model = glm::mat4(1.0f);
to initialize it to identity matrix.
answered Nov 19 '18 at 18:20
Rhu MageRhu Mage
160113
160113
thanks i missed that :)
– anekix
Nov 19 '18 at 18:26
but why initialize to an identity matrix?
– anekix
Nov 19 '18 at 18:29
You can initialize it to whatever you want. But if you want the model matrix to only contain the rotation you have to use identity, rotation multiplied by identity is rotation.
– Rhu Mage
Nov 19 '18 at 18:52
add a comment |
thanks i missed that :)
– anekix
Nov 19 '18 at 18:26
but why initialize to an identity matrix?
– anekix
Nov 19 '18 at 18:29
You can initialize it to whatever you want. But if you want the model matrix to only contain the rotation you have to use identity, rotation multiplied by identity is rotation.
– Rhu Mage
Nov 19 '18 at 18:52
thanks i missed that :)
– anekix
Nov 19 '18 at 18:26
thanks i missed that :)
– anekix
Nov 19 '18 at 18:26
but why initialize to an identity matrix?
– anekix
Nov 19 '18 at 18:29
but why initialize to an identity matrix?
– anekix
Nov 19 '18 at 18:29
You can initialize it to whatever you want. But if you want the model matrix to only contain the rotation you have to use identity, rotation multiplied by identity is rotation.
– Rhu Mage
Nov 19 '18 at 18:52
You can initialize it to whatever you want. But if you want the model matrix to only contain the rotation you have to use identity, rotation multiplied by identity is rotation.
– Rhu Mage
Nov 19 '18 at 18:52
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%2f53380445%2frotation-matrix-is-not-getting-applied-correctly-to-a-vector%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
Possible duplicate of Why is the sprite not rendering in OpenGL?
– Rabbid76
Nov 19 '18 at 18:24