Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

zak_ua

Interesting problem with ID3DXSprite

This topic is 5335 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 there! Please someone help, who knows the subject. I''m slaving over such problem: I would like to create a game of my own, which would somehow resemble GTA (1st one) but on map of my native city, with much more features and improvements (well, you know - top-down view is the basis for this, because first-pirson 3D is hard for me yet). I started with DirectDraw, but then I came that ID3DXSprite in DirectX 8 is much more powerful in alpha-blending, rotating and so on. Everything went good, while I was usind ID3DXSprite::Draw method (it takes texture, rect, angle, alpha, X and Y screen coords) - and I still use it for simple sprite drawing (people, cars, etc.). But then I have come to such: I need to draw walls of buildings in perspective (you should have seen GTA - it''s like there - I''m wondering how they had done it in DOS, without even DirectDraw, not to mention D3DX and D3D...). I started to use ID3DXSprite::DrawTransform method, and here is a question: how I should use D3DXMatrix... functions to obtain a good matrix to pass to that function? DirectX SDK help describes this question very little: we have descr of DrawTransform function and many D3DXMatrix... functions, which are described as to be used only for 3D transformations, but not for sprites. ----- Step aside about axes: I had noticed that while in 3D (left-handed) we have X to the right, Y to the top and Z away from us, for the D3DXSprites we have Y to the bottom (like in DirectDraw, like in screen coords)... Is it really so and why? There was already discussion in this forum about "are these sprites in XY-plane or in XYZ space like all 3D figures", but I didn''t understand it - this concerns usage of view matrix setup... In general: At last, are D3DXSprites for HUD and menu making or for billboards (camera-facing sprites in 3D space) ??? (someone wrote that i.e. smoke from barrel in Quake or Doom, don''t remember, is a sprite in 3D space). ----- So, I mean I use D3DXMatrixRotationY, then D3DXMatrixLookAtLH, then D3DXMatrixPerspectiveFovLH... but I get bad results. Let''s take I need the right side wall of building which is to the left from me, while I''m (I mean the "camera", if it can be called so in 2D) flying on a chopper over the street. So, I rotate the sprite that it''s like "standing vertically". Then make some D3DXMatrixLookAtLH, then D3DXMatrixPerspectiveFovLH. And the sprite makes its perspective only relative to top border of screen, while I need this to be relative to the screen center. //ID3DMATRIX pm,pmm; D3DXMatrixIdentity(pm); D3DXMatrixRotationY(pmm,0.0005); //Multiply matrices here - D3DXMatrixMultiply(pm,pm,pmm) D3DXMatrixLookAtLH(pmm, D3DXVector3(x, y, -2.0), D3DXVector3(x, y, 1.0), D3DXVector3(0.0, 1.0, 0.0)); //x and y = 0 in the beginning, then I try to move "camera" //again Multiply D3DXMatrixPerspectiveFovLH(pmm, D3DX_PI/4, 1.0, -1.0, 5.0); //again Multiply I tried to use different x and y, I also changed every parameter in those 3 D3DXVector3 calls (there we have Eye, LookAt and Up vectors), and in D3DXMatrixPerspectiveFovLH (field of view, aspect, and zn and zf (BTW it seems that these ones not influence at anything)), and in any case I had that sprite holds its perspective over top screen border (Y=0). It "leans down" too much when it is in the center of screen. In this point it should be such as it is now in the top of the screen. And in the top it should "lean up". And this is not happens. The other problem is that it''s very hard to position such sprite: because all transforms are in the matrix, I can center the sprite in the screen by setting x and y to half of width and height, and also by using D3DXMatrixTranslation - the result is the same. And also if I give translation in Z coord, I have zoom in/out plus shifting in X and Y coords (imagine: I decrease Z (like draw it nearer), it zooms in and also moves right and down - which is very undesirable) - because, you know, I need precise control over screen coords of the sprite, for the sprites edges to coincide. When I''m going from left to right and back (change "camera''s" X coord), I have a point where the sprite is viewed like "vertically standing", it becomes a line. And the problem is that I can''t control coords of this place. Moreover it slips on the "ground surface"... And you know, building walls should stay still on the ground, if they are not on wheels :-) ***** Another problem is with D3DXMatrixRotationY - if I don''t use projection matrix after it, I obtain good results in rotation (but without perspective, of course) by stating normal angle values (like pi/2, or any between 0 and pi*2). But if I use LookAtLH and PerspectiveFovLH functions later, the sprite becomes stretched all over the screen, and one half of it (one triangle) disappears... brrrrrr... horrible picture... So i need to use very small angles like 0.0005 (you can see it in the listing above). Why it happens? ***** Also, I have found good article (it is also referred in other posts in this forum) on gamasutra: http://www.gamasutra.com/features/20010629/geczy_pfv.htm: ===quotation start=== Finally, for those wishing to go one step further, and maybe even dip your toes into 3D waters, the ID3DXSprite interfaces offer an alternate version of the Draw() function, called DrawTransform(). Instead of taking scaling, rotation, and translation (positioning) information, the DrawTransform() function takes a transformation matrix, which defines the geometrical transformations for every pixel using a 4x4 matrix. Using this you gain access to effects involving the Z-axis, meaning distances closer to or farther from the viewer. A popular effect is perspective, which would give your image the impression of receding into the distance. The use of transformation matrices is far beyond the scope of this article, but for those interested you can start with "About 3-D Transformations" in the DirectX 8 SDK and go from there. Be prepared to dig out your old math textbooks. ===quotation end=== Well, it''s very bad that "the use of transformation matrices is far beyond the scope of this article"... As I said, the help articles "About 3-D Transformations" in the DirectX 8 SDK do not suit so good to sprites as they do to VIEW, WORLD and PROJECTION matrices in 3D... Maybe someone has a link to a good tutorial on D3DXSprites, especially to usage of DrawTransform (because everything else is clear enough)? I see a lack of such material on the web... So, whether anybody can help with DrawTransform? In short, the problems are: 1. The sprite has the perspective over top border of the screen, while it should be over horizontal line, going through the center of screen (it''s about Y-position). 2. It''s almost impossible to set exact X-position of the sprite (the point on the ground, where the wall "grows from") (the same to Y-position, see point 1). 3. See above between lines ----- 4. See above between lines ***** At last, I would be happy if there is some way to draw a sprite at exact X and Y, and to state for it some parameters to draw it not like rectangle, and not like diamond (parallelogram), but like trapezium - so that I obtain visibility of perspective, and i.e. some degree of "inclination"... Many thanks in advance to all replyers. And sorry for very long story... :-) Best regards, Zak.

Share this post


Link to post
Share on other sites
Advertisement
Don''t quote me, but I''m sure the just used a regular graphic. Just make the graphic so that it looks like its in perspective and then draw it regularly.

/*
I use DirectX 9 and C++ (Microsoft Visual C++ 6.0 Professional edition)
*/

Share this post


Link to post
Share on other sites
quote:
Original post by Programmer16
Don't quote me, but I'm sure the just used a regular graphic. Just make the graphic so that it looks like its in perspective and then draw it regularly.


2Programmer16:
Thanks for the reply and sorry that I qoute you ;-), but I doubt it's really so. You see, the change of perspective is so smooth thay I suspect run-time redrawing of those walls in GTA. If they had used multi-frame graphics (as we generally do for sprite animation), it would take too much disk space to store (well, archiving can be done), but what is more important - much video or usual RAM to store those textures during run-time.

In another topic on this forum somebody asked how sprite rotating can be done. Some guy had advised to prepare rotated sprites beforehand. Well, it's almost the same that you propose. But then for each angle of rotation I need to do hundreds of frames of sprite animation. But we all know there is no need in this: ID3DXSprite::Draw can rotate sprites very good, so I need to make animation frames only for one angle of rotation.

The same with perspective. It would take dozens of excess Megabytes to store prerendered views of each wall from top in perspective from different angles of view (from top), and it's much work to prepare this, and what is the worst - the animation will be not smooth.

Anyway, I know that somehow it could be done - because I have obtained sprites in perspective. The only question which generalizes my previous post is: how the transformation of a sprite (preparing of a transformation matrix) should be done correctly to obtain good control on sprite positioning and "inclination" through DrawTransform method ?? (I mean walls are vertical, but when you are looking from top and little aside, you see them in perspective and inclined more or less).

Anybody can help?

[edited by - zak_ua on April 11, 2004 8:33:46 AM]

Share this post


Link to post
Share on other sites
ID3DXSprite was not intended to serve as a 2D subsitute to making it look like 3D. I''m not quite sure how GTA did it, but it was probably just like Wolfenstein or Doom or the other games of the day. I suggest that you just go 3D, because you''re going to have a lot less problems creating the artwork so that it looks correct. Plus, you''re gonna have to do so many transformations that it will probably be even more complicated. So why don''t you just make a small game that resembles GTA III, instead?


Dustin Franklin
Mircrosoft DirectX MVP

Share this post


Link to post
Share on other sites
quote:
Original post by circlesoft
ID3DXSprite was not intended to serve as a 2D subsitute to making it look like 3D. I''m not quite sure how GTA did it, but it was probably just like Wolfenstein or Doom or the other games of the day.


Sure, I understand. But why then they introduced DrawTransform function? It should do what it''s supposed to do.
And do you know how they all had done this "false" 3D? I would like to do the same maybe, but anyway: here we have this DrawTransform function and it would be good to make it work correctly.

BTW, anybody knows something about D3DXSprites in DirectX 7 ? I have seen the SDK Help. The Draw and DrawTransform functions are not methods of ID3DXSprite there, but separate functions: D3DXDrawSpriteSimple and D3DXSpriteDrawSpriteTransform. And there was another function: D3DXDrawSprite3D - as I catched it, one can pass 4 points (in screen or in 3D coords, not clear for me), and the sprite will be stretched between these points anyhow. Is this what I need? And why MS didn''t implemented it in DX8? Or maybe they did in DX9?

quote:
Original post by circlesoft
I suggest that you just go 3D, because you''re going to have a lot less problems creating the artwork so that it looks correct. Plus, you''re gonna have to do so many transformations that it will probably be even more complicated. So why don''t you just make a small game that resembles GTA III, instead?


You mean that in "false 3D from top-view" I''m gonna have more headache?

2D or 3D... I think it worth separate topic in the forum... And well, I thought about going 3D of course, but my initial intention was to make it like GTA and not GTA III because I''d like to concentrate firstly on AI, gameplay features and city map, and not on graphics. I suppose I could make it like GTA, and even here I need to make reasonable efforts (not considering the resolution, of course - even now I can have up to 1600x1200 and more).
But, I see many problems on horizon for "false 3D" - one of it is very many sprite animation frames if I want advanced people animation, for every man type (like "man in black suit", "man in T-shirt", "woman in suit", "child with hat", "child without hat", you know, like first column of this huge matrix of textures, and all this multiplyed by "walking", "handshaking", "punching in face", "kicking with leg", "loading to car", "running" and so on - like first row of the matrix).
On the other side, there is plus for sprites: more FPS. Because I need much calculation power for AI (my city is much bigger than Liberty City or Vice City, but as well as New York and Miami are much bigger than they are shown in game, but I want to show my city in full size), and also I would like to hold all these hundreds thousands of people real (you know, in GTA it''s not bothering you, but in GTA III you can see - people and cars disappear in certain distance. In MAFIA also, but it''s not so noticeable like in GTA III and Vice City. And I want city life to happen independently of player - car accidents on the other side of city and so on. An approximate example of such life simulation is STALKER, if you heard about it - a great game being developed now in Ukraine).
Maybe you can bring some more arguments, and encourage me to go 3D?

But nevertheless, if anybody can help with DrawTransform, you are welcome.

Share this post


Link to post
Share on other sites

  • Advertisement
×

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!