Simple rotation

Started by
3 comments, last by Digivance 11 years, 3 months ago

I'm attempting to rotate a code-defined model, however it appears to be moving instead of rotating. I've looked all over, even copy/pasting, but to no avail.

Edit- This current code shows me using a custom effect, however, I'm basing all this off my previous edits (that being, using the BasicEffect)!


			m_GraphicsDevice.BlendState = BlendState.Opaque;
			m_GraphicsDevice.DepthStencilState = DepthStencilState.Default;

			m_Effect.Parameters["View"].SetValue( m_Camera.View );
			m_Effect.Parameters["Projection"].SetValue( m_Camera.Projection );
			m_Effect.Parameters["CameraPosition"].SetValue( m_Camera.Position );
			m_Effect.Parameters["Texture1"].SetValue( m_TextureAtlas );
			
			foreach( EffectPass pass in m_Effect.CurrentTechnique.Passes )
			{
				foreach( Item item in m_World.ItemMap.Values )
				{
					if( item == null || !item.BoundingBox.Intersects( frustum ) )
						continue;

					Matrix matWorld = Matrix.CreateRotationY( fRROT );
					m_Effect.Parameters["World"].SetValue( matWorld );
					pass.Apply();

					m_GraphicsDevice.SetVertexBuffer( item.m_VertexBuffer );
					m_GraphicsDevice.Indices = item.m_IndexBuffer;

					m_GraphicsDevice.DrawIndexedPrimitives( PrimitiveType.TriangleList, 0, 0,
						item.m_VertexBuffer.VertexCount, 0, item.m_IndexBuffer.IndexCount / 3 );

I've tried using Matrix.CreateFromAxisAngle which did rotate, just not anywhere near the axis I want - even when defining just that axis.

My other attempt was Matrix.CreateRotationY(..) * Matrix.CreateTranslation(..) and still seemed to move.

Further information:

m_VertexBuffer = VertexPositionTexture

m_Effect = BasicEffect

ItemMap only contains 1 value for the time being.

I know Quanternations is better for this since it holds the rotation, but I'd like to avoid that route..

Advertisement

Are the vertices of your code-defined model centered at (0, 0, 0)?

Using CreateRotationX, CreateRotationY, & CreateRotationZ all apply rotations around the world or global axes. Meaning it causes your object to rotate only around the world/global axes, not your object's local axes. Using CreateFromAxisAngle allows you to input whatever rotation axis you want, including the models own local axes.

Dan Mayor

Professional Programmer & Hobbyist Game Developer

Seeking team for indie development opportunities, see my classifieds post

Snap. I completely forgot about that..! Time to dig around my previous edits. Thank you both!

Sometimes it just takes another set of eyes friend.

Dan Mayor

Professional Programmer & Hobbyist Game Developer

Seeking team for indie development opportunities, see my classifieds post

This topic is closed to new replies.

Advertisement