Skip to main content
gamedev.net
🔒 Locked

Sprite Mapping

Started by wooord Apr 28, 2001 at 12:40 PM 6 replies 350+ views
Original Post
wooord
wooord
I have a couple of different sprites, each different obe represented by a class. Each one basically uses the same code to initialize a vertex and index buffer, transform, and draw. I am using pixel corrdinates in a 800x700 window. If I were to create one of each different sprite at the same x and y coordinates, all but one of the sprites will appear at the expected location. The other one will appear at a more exagerated x coordinate. I''ve tested this by directly putting the x coordinate in the vertex buffer so it is not a number problem. Any Ideas? Here''s the only possibility I can think of - For drawing each sprite, I declare a new D3DXMATRIX, use D3DXMatrixTranlation and then SetTransform transforming the tranlated matrix to the world matrix. Do all the sprites need to somehow share the D3DXMATRIX for the world matrix or can it be independent like I am doing?
Prairie
Prairie
Are you sure that you''re resetting the World ID before each individual sprite translation? Is it always the same sprite that is offset? And if so, is it either the first or last rendered?

-Prairie
wooord
wooord
How do you reset World ID? DXDXMatrixIdentity?

Yes, it''s always the same sprite. It''s normally last, but i changed the order and it didn''t make a difference.
Prairie
Prairie
Yeah, that's the function I mean. When you say "but i changed the order and it didn't make a difference." do you mean the same sprite was off-set, or still the last?

As a test try the following:
  
D3DXMATRIX matID;
D3DXMatrixIdentity(&matID);

for(int x = 0; x< numbersprites; x++)
{
//matID does not get touched by anything else

g_pd3dDevice->SetTransform( D3DTS_WORLD, &matID );
Sprite[x]->Render(); // or what ever you call for it

g_pd3dDevice->SetTransform( D3DTS_WORLD, &matID );
}


Let me know what happens
Prairie

Edited by - Prairie on April 28, 2001 4:24:49 PM
wooord
wooord
Thanks for your help so far.

I changed my world matrix to be a global variable so all sprite classes reference the same one. I also called

D3DXMatrixIdentity(&worldMatrix);
SetTransform( D3DTS_WORLD, &worldMatrix );

before rendering each frame.

The one sprite is still not positioned properly. I once again changed it to be the first sprite to be rendered and still no luck.

Each sprite has it''s own vertex buffer, index buffer, and call to DrawIndexedPrimitive. Can that be the problem? I might change that for performance reasons anyway. Each frame has about 10 - 15 sprites.
Prairie
Prairie
I think I see where the problem is coming from. Your sprite class should have an identity matrix that is initialized as D3DXMatrixIdentity(&matID). You should apply your rotations and translations per sprite on THAT sprites matrix.

Then in your render routine in the class,
  
D3DXMATRIX Matrix;
D3DXMatrixIdentity(&Matrix);
//transformed sprite

SetTransform( D3DTS_WORLD, &matID );
//insert geometry rendering call here


SetTransform( D3DTS_WORLD, &Matrix );


by setting the world back to default at end of rendering you assure that when the next sprite is rendered that the world matrix is set properly.

If you are having more problems let me know, i''m happy to help. I could take a look at your class (and the rendering function of your main loop) if you need.

good luck;
Prairie

wooord
wooord
I just figured it out..

The constructor for the sprite takes a x coordinate parameter (xOffset). The xOffset is immediately applied to the vertices.

In order to move the sprite, I increment or decrement xOffset based on user input then translate the matrix using xOffset. See the problem? .. I''m using xOffset twice to position the sprite, which ends up doubling it.

Thanks for your help.
Prairie
Prairie
Congrats;
It''s always a good feeling to solve a problem on your own.

-Prairie

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.