rotating position, need to rotate normal too?

Problems building or running the engine, queries about how to use features etc.
Post Reply
Nickak2003
Goblin
Posts: 272
Joined: Thu Jun 10, 2004 4:19 am
x 26

rotating position, need to rotate normal too?

Post by Nickak2003 »

So, I have loaded a mesh. I want to rotate the mesh, to do that I run through each vertex and rotate the position, that seems to work OK.
So now I think I also have to rotate the normal as well. Do I just rotate it by the same angle as the position?
This is what I do:

Code: Select all

	Ogre::ManualObject* tmp = mGraphics.getSceneManager()->createManualObject();

	tmp->begin(mMesh->getSubMesh(0)->getMaterialName(), Ogre::RenderOperation::OT_TRIANGLE_LIST);

	for( std::size_t v=0; v< mMeshVertices.size(); v++){

		Ogre::Vector3 position = Ogre::Vector3(mMeshVertices[v].x, mMeshVertices[v].y, mMeshVertices[v].z);
		Ogre::Vector3 normal = Ogre::Vector3(mMeshVertices[v].nx, mMeshVertices[v].ny, mMeshVertices[v].nz);
		Ogre::Vector2 tex = Ogre::Vector2(mMeshVertices[v].u, mMeshVertices[v].v);

		Ogre::Quaternion quat;
		quat.FromAngleAxis( Ogre::Radian(Ogre::Degree(degrees)), Ogre::Vector3(0,0,1) );

		//rotate the position!
		float scale = 1;

		Ogre::Vector3 translatedPos = quat * (position * scale);
		position = translatedPos;

		Ogre::Vector3 translatedNorm = quat * (normal * scale);
		normal = translatedNorm;

		tmp->position(position);
		tmp->normal(normal);
		tmp->textureCoord(tex);

	}

	for (std::size_t i = 0; i < mMeshIndices.size(); i++) {
		tmp->index(mMeshIndices[i]);
	}
Is this correct? because the generated mesh doesnt seem to be visible with the New Instance Manager; v1.10
Nickak2003
Goblin
Posts: 272
Joined: Thu Jun 10, 2004 4:19 am
x 26

Re: rotating position, need to rotate normal too?

Post by Nickak2003 »

Figured it out, needs separateverrex buffers
Post Reply