I'm working on a drive simulation project.I'm using opengl on VS2010 IDE.

There is a vector glm::vec3 'dir' for object 'car_param'(not important) which I want to rotate using glm\glx rotate function.

glm::rotate(car_param->dir,0.5f,glm::vec3(0,1,0));

It is being successfully compiled but when running it has no effect. I tried to test it with:

cout<<car_param->dir.x<<"\t"<<car_param->dir.y<<"\t"<<car_param->dir.z<<"\n";

just after the rotate but it is stucked on (0,0,-1) which was the initial value.

有帮助吗?

解决方案

Look at the signature of rotate():

template< typename T >
detail::tvec3< T > rotate( detail::tvec3< T > const &v, T const &angle, detail::tvec3< T > const &normal )

Note that v is passed in as a const reference.

rotate() returns a rotated vector. It doesn't (can't!) rotate v in-place.

Try this:

car_param->dir = glm::rotate(car_param->dir,0.5f,glm::vec3(0,1,0));
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top