Jump to content
• Advertisement

# matrices rotate textured quad?

This topic is 3896 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

Hello I'm trying to rotate one sprite... but looks strange... Code: procedure RotateWorldZ(const Angle: Single); var matRotation: TD3DMatrix; begin D3DXMatrixRotationZ(matRotation, Angle); D3DXMatrixMultiply(g_matWorld, g_MatWorld, matRotation); end; my sprite uses D3DFVF_XYZRHW... some suggestions how to fix? Greetings

#### Share this post

##### Share on other sites
Advertisement
Quote:
 Original post by lordzeroHelloI'm trying to rotate one sprite... but looks strange...Code:procedure RotateWorldZ(const Angle: Single);var matRotation: TD3DMatrix; begin D3DXMatrixRotationZ(matRotation, Angle); D3DXMatrixMultiply(g_matWorld, g_MatWorld, matRotation); end;my sprite uses D3DFVF_XYZRHW...some suggestions how to fix?Greetings
D3DFVF_XYZRHW means "Hi there D3D, I'm specifying vertices in screen space. That means I want you to completely ignore any matrices I set". Wghich is exactly what it's doing.

If you want to use the transforms, you'll need to use D3DFVF_XYZ with an orthogonal projection matrix (probably, assuming you're doing 2D stuff), and set up your view matrix accordingly.

#### Share this post

##### Share on other sites
Quote:
Original post by Evil Steve
Quote:
 Original post by lordzeroHelloI'm trying to rotate one sprite... but looks strange...Code:procedure RotateWorldZ(const Angle: Single);var matRotation: TD3DMatrix; begin D3DXMatrixRotationZ(matRotation, Angle); D3DXMatrixMultiply(g_matWorld, g_MatWorld, matRotation); end;my sprite uses D3DFVF_XYZRHW...some suggestions how to fix?Greetings
D3DFVF_XYZRHW means "Hi there D3D, I'm specifying vertices in screen space. That means I want you to completely ignore any matrices I set". Wghich is exactly what it's doing.

If you want to use the transforms, you'll need to use D3DFVF_XYZ with an orthogonal projection matrix (probably, assuming you're doing 2D stuff), and set up your view matrix accordingly.

hi steve

using orthogonal camera and D3DFVF_XYZ i get the same problem....

how to fix this? you have suggestion?

how to correct rotate? using the center of quad to totate with a 3x3 matrix?

greets

#### Share this post

##### Share on other sites
Quote:
 Original post by lordzerousing orthogonal camera and D3DFVF_XYZ i get the same problem....how to fix this? you have suggestion?how to correct rotate? using the center of quad to totate with a 3x3 matrix?
The correct way is the way you're doing it. If that's not working we'll have to see some code. Although I'm not familiar with Pascal or Delphi or whatever language that is.

#### Share this post

##### Share on other sites
Quote:
Original post by Evil Steve
Quote:
 Original post by lordzerousing orthogonal camera and D3DFVF_XYZ i get the same problem....how to fix this? you have suggestion?how to correct rotate? using the center of quad to totate with a 3x3 matrix?
The correct way is the way you're doing it. If that's not working we'll have to see some code. Although I'm not familiar with Pascal or Delphi or whatever language that is.

Delphi...

procedure TDXImage.SetTextureIndex(const Value: Integer);
begin
//------------------------------------------------------------------------------

FTextureIndex := Value;
// Self.Texture.Pattern
Self.Height := Self.FTexture.Pattern[Value].Height;
Self.Width := Self.FTexture.Pattern[Value].Width;

Self.pTexture := Self.FTexture.Texture[Value];

_X := (X-(Device.WindowRect.Right/2));
_Y := -(Y-(Device.WindowRect.Bottom/2));

//Crop coordinates into a 2x2 space (the total D3D window)
_X := (_X * (2/Device.WindowRect.Right));
_Y := (_Y * (2/Device.WindowRect.Bottom));

//calculate width and height
_width := Width * (2/Device.WindowRect.Right);
_height := -height * (2/Device.WindowRect.Bottom); //flip Y axis }

Vertices[0].X := _X;
Vertices[0].Y := _Y;
Vertices[0].Z := 0;
Vertices[0].Color := $FFFFFFFF; Vertices[0].tU := 0; Vertices[0].tV := 0; Vertices[1].X := _X + _Width; Vertices[1].Y := _Y; Vertices[1].Z := 0; Vertices[1].Color :=$FFFFFFFF;
Vertices[1].tU := 1;
Vertices[1].tV := 0;

Vertices[2].X := _X;
Vertices[2].Y := _Y + _Height;
Vertices[2].Z := 0;
Vertices[2].Color := $FFFFFFFF; Vertices[2].tU := 0; Vertices[2].tV := 1; Vertices[3].X := _X + _Width; Vertices[3].Y := _Y + _Height; Vertices[3].Z := 0; Vertices[3].Color :=$FFFFFFFF;
Vertices[3].tU := 1;
Vertices[3].tV := 1;

if FAILED(
DXBase.Direct3DDevice.CreateVertexBuffer(
4 * SizeOf(TDXImageVertex),
0, D3DFVF_CUSTOMVERTEX,
D3DPOOL_MANAGED, pVB, nil)) then
Exit;

if FAILED(
pVB.Lock(0, SizeOf(Vertices), pVertices, 0)) then
Exit;

CopyMemory(pVertices, @Vertices, SizeOf(Vertices));
pVB.Unlock;

const
D3DFVF_CUSTOMVERTEX = (D3DFVF_XYZ or D3DFVF_TEX1);

//------------------------------------------------------------------------------
procedure TDXImage.Draw;
begin
//------------------------------------------------------------------------------

DXBase.Direct3DDevice.SetTexture(0, pTexture);

DXBase.Direct3DDevice.SetStreamSource(0, pVB, 0, SizeOf(TDXImageVertex));
DXBase.Direct3DDevice.SetFVF(D3DFVF_CUSTOMVERTEX);

DXBase.Direct3DDevice.DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);

//------------------------------------------------------------------------------
end;

procedure ClearWorld;
begin
D3DXMatrixIdentity(g_matWorld);
end;

procedure ApplyWorld;
begin
Direct3DDevice.SetTransform(D3DTS_WORLD, g_matWorld);
end;

procedure ScaleWorld(const X, Y, Z: Single);
var
matScale: TD3DXMatrix;
begin
D3DXMatrixScaling(matScale, X, Y, Z);
D3DXMatrixMultiply(g_matWorld, g_matWorld, matScale);
end;

procedure RotateWorldZ(const Angle: Single);
var
matRotation: TD3DMatrix;
begin
D3DXMatrixRotationZ(matRotation, Angle);
D3DXMatrixMultiply(g_matWorld, g_MatWorld, matRotation);
end;

procedure setupview();
var
matProj: TD3DMatrix;
begin

//Setup orthographic projection matrix
D3DXMatrixOrthoLH(matproj, Device.DisplayMode.Width, Device.DisplayMode.Height, 1.0, 1.0);
D3DXMatrixIdentity (matproj);
DXBase.Direct3DDevice.SetTransform (D3DTS_PROJECTION, matproj);
DXBase.Direct3DDevice.SetTransform (D3DTS_WORLD, matproj);
DXBase.Direct3DDevice.SetTransform (D3DTS_VIEW, matproj);

end;

procedure TMainForm.OnRender(Sender: TObject);
begin

setupview;

DXMatrices.ClearWorld;
DXMatrices.RotateWorldZ(gettickcount/340.0);
DXMatrices.ScaleWorld(0.2, 0.2, 0.2);
DXMatrices.ApplyWorld;

DXImage.Draw;

to test my demo and see what happens..

see this demo:
http://www.lordzero.co.nr/tmp/orthogonalcamerarotatesprite.zip

http://www.lordzero.co.nr/tmp/spritenormal.jpg ---> see this

http://www.lordzero.co.nr/tmp/spriterotation.jpg ---> strange rotation...

#### Share this post

##### Share on other sites
Your vertex format doesn't match the FVF code. I see you have a (presumably diffuse) colour in there, but it's not mentioned in the FVF code. Also, ther Debug Runtimes will shout at you about this. I'm not sure where you get your debug output in Delphi, but you can always use DebugView or similar.

#### Share this post

##### Share on other sites
Quote:
 Original post by Evil SteveYour vertex format doesn't match the FVF code. I see you have a (presumably diffuse) colour in there, but it's not mentioned in the FVF code. Also, ther Debug Runtimes will shout at you about this. I'm not sure where you get your debug output in Delphi, but you can always use DebugView or similar.

but... do u think that this can be the error of rotation?

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
Rutin
33
2. 2
3. 3
4. 4
5. 5
• Advertisement

• 13
• 9
• 9
• 9
• 9
• ### Forum Statistics

• Total Topics
633330
• Total Posts
3011388
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!