rotation matrix is not getting applied correctly to a vector
up vote
0
down vote
favorite
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 |
up vote
0
down vote
favorite
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 at 18:24
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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 at 18:44
Nicol Bolas
279k33459631
279k33459631
asked Nov 19 at 18:14
anekix
890519
890519
Possible duplicate of Why is the sprite not rendering in OpenGL?
– Rabbid76
Nov 19 at 18:24
add a comment |
Possible duplicate of Why is the sprite not rendering in OpenGL?
– Rabbid76
Nov 19 at 18:24
Possible duplicate of Why is the sprite not rendering in OpenGL?
– Rabbid76
Nov 19 at 18:24
Possible duplicate of Why is the sprite not rendering in OpenGL?
– Rabbid76
Nov 19 at 18:24
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
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 at 18:26
but why initialize to an identity matrix?
– anekix
Nov 19 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 at 18:52
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
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 at 18:26
but why initialize to an identity matrix?
– anekix
Nov 19 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 at 18:52
add a comment |
up vote
2
down vote
accepted
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 at 18:26
but why initialize to an identity matrix?
– anekix
Nov 19 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 at 18:52
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
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 at 18:20
Rhu Mage
154113
154113
thanks i missed that :)
– anekix
Nov 19 at 18:26
but why initialize to an identity matrix?
– anekix
Nov 19 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 at 18:52
add a comment |
thanks i missed that :)
– anekix
Nov 19 at 18:26
but why initialize to an identity matrix?
– anekix
Nov 19 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 at 18:52
thanks i missed that :)
– anekix
Nov 19 at 18:26
thanks i missed that :)
– anekix
Nov 19 at 18:26
but why initialize to an identity matrix?
– anekix
Nov 19 at 18:29
but why initialize to an identity matrix?
– anekix
Nov 19 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 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 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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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 at 18:24