English 中文(简体)
Direct3D Sprite->SetTransform usage?
原标题:

I draw textures using the D3DXSprite.
I want to transform them(rotate, scale etc..) so I use the SetTransfrom method.
Should I, store the old transformation -> set a new one -> draw -> set the old one? I have a sprite class whice take care of the Draw and the Update methods. I mean something like this:

D3DXMatrix oldMatrix;
sprite->GetTransfrom(&oldMatrix);

D3DXMatrix newMatrix;
D3DXMatrixScaling(&newMatrix, 2.0f, 2.0f, 0.0f);

sprite->SetTransform(&newMatrix);
sprite->Draw(...);

sprite->SetTransform(&oldMatrix);

Good/Bad?

最佳回答

What would be bad is to retrieve the oldMatrix and use it for computing a newMatrix (precision issues). It s better to recompute a fresh matrix at each new draw.

What you probably want to store for each of your sprites is a position, rotation and scale factor.

问题回答

TBH drawing 2 tris (Im assuming thats what your sprite is made of) changing a transform and drawing is HIGHLY inefficient.

You are far far better off manually transforming the 4 verts into 1 big dynamic vertex buffer and rendering everything in a oner. Same goes for the textures applied to the sprites. Keeping them in one big texture will save you many state changes and allow you to do your rendering far far faster overall.

Edit: Making multiple DrawPrimitive/DrawIndexedPrimitive calls is very slow. For each matrix you set you need to make a seperate draw call. The way to avoid this is to apply your matrix to each of the 4 vertices yourself and then copy them into a vertex buffer already transformed. This means you can make one draw call with with an identity world matrix set.

It is quite probable, in hindsight, that ID3DXSprite abstracts this away from you as you are unable to set the corners. Performance would truly suck if it didn t abstract this away from you.

It is very unlikely, however, that it abstracts away the texture problem. Thus it would be best to store all the frame of a sprite in one texture (and possibly all the frames of multiple sprites in one texture). So in this case you are best off passing one IDirect3DTexture and setting pSrcRect to the sub rect of which ever frame you are in rather than using seperate textures. The fewer texture you use the better performance will be.





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签