Jump to content
  • Advertisement
Sign in to follow this  

DirectX 10 Rotate Texture 3D

This topic is 2645 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok I know this is a simple question but none the less one that is bugging the crap out of me because I can't make it work the way I want it to. I'm doing an exercise in the book Introduction to 3D Game Programming with DirectX 10 and the exercise calls for rotating the texture that is on this cube as a function of time.
Here is some of the code:

This is the update method where I update the 2D Vector createOffset based on the DeltaTime that comes in from another class that uses the High Frequency Performance Timer to keep track of game time.

void CrateApp::updateScene(float dt)

// Update angles based on input to orbit camera around scene.
if(GetAsyncKeyState('A') & 0x8000) mTheta -= 2.0f*dt;
if(GetAsyncKeyState('D') & 0x8000) mTheta += 2.0f*dt;
if(GetAsyncKeyState('W') & 0x8000) mPhi -= 2.0f*dt;
if(GetAsyncKeyState('S') & 0x8000) mPhi += 2.0f*dt;
if(GetAsyncKeyState('Z') & 0x8000) mRadius -= 15.0f*dt;
if(GetAsyncKeyState('X') & 0x8000) mRadius += 15.0f*dt;

// Restrict the angle mPhi.
if( mPhi < 0.1f ) mPhi = 0.1f;
if( mPhi > PI-0.1f) mPhi = PI-0.1f;

// Convert Spherical to Cartesian coordinates: mPhi measured from +y
// and mTheta measured counterclockwise from -z.
mEyePos.x = mRadius*sinf(mPhi)*sinf(mTheta);
mEyePos.z = -mRadius*sinf(mPhi)*cosf(mTheta);
mEyePos.y = mRadius*cosf(mPhi);

crateOffset.x += 10 * dt;

// Build the view matrix.
D3DXVECTOR3 target(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
D3DXMatrixLookAtLH(&mView, &mEyePos, &target, &up);

And here is the draw method that updates the texture matrix texMtx with a rotation based on the crateOffset variable.

void CrateApp::drawScene()

// Restore default states, input layout and primitive topology
// because mFont->DrawText changes them. Note that we can
// restore the default states by passing null.
md3dDevice->OMSetDepthStencilState(0, 0);
float blendFactors[] = {0.0f, 0.0f, 0.0f, 0.0f};
md3dDevice->OMSetBlendState(0, blendFactors, 0xffffffff);

// set constants
mfxEyePosVar->SetRawValue(&mEyePos, 0, sizeof(D3DXVECTOR3));
mfxLightVar->SetRawValue(&mParallelLight, 0, sizeof(Light));
mWVP = mCrateWorld*mView*mProj;

// Don't transform texture coordinates, so just use identity transformation.
D3DXMatrixRotationX(&texMtx, crateOffset.x );

mTech->GetDesc( &techDesc );
for(UINT p = 0; p < techDesc.Passes; ++p)
mTech->GetPassByIndex( p )->Apply(0);


// We specify DT_NOCLIP, so we do not care about width/height of the rect.
RECT R = {5, 5, 0, 0};
mFont->DrawText(0, mFrameStats.c_str(), -1, &R, DT_NOCLIP, BLACK);

mSwapChain->Present(0, 0);

When I do this I get a scene like this: [attachment=5479:ScreenShot.jpg]

I know its something simple that I'm doing wrong but I just cant figure it out. Please help.

Share this post

Link to post
Share on other sites
D3DXMatrixRotationX rotates around the x-axis, so in texture space this is u, which will result in just shrinking the v (down to degeneracy). You want to rotate around z and maybe also around the center (0.5, 0.5).

Share this post

Link to post
Share on other sites
I tried that as well and I get a similar reaction. Aka it rotates it in another way and not in the way I want it to. The texture is a fireball and I'm trying to make it rotate. I should also probably bring up the fact that in the shader I combine 2 textures multiplying the samples together.

Share this post

Link to post
Share on other sites
You should look into the [font="Consolas, Courier, monospace"]D3DXMatrixRotationAxis function here: [/font]http://msdn.microsof...357(VS.85).aspx

Essentially you can calculate the rotation matrix based on an arbitrary axis like so:
D3DXMatrixRotationAxis( &texMtx, &D3DXVECTOR3( 0.0f, 0.0f, 1.0f ), mRotationAngle );

Play around with that a bit and see if you can solve your problem that way

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!