|
-
Apr 27th, 2017, 02:02 PM
#1
[RESOLVED] transform a sprite to move with the camera
Edit,
Nm, I have this fixed. I dropped the sprites and simply drawing everything using vertexBuffers.
Hey all,
I have an app that currently uses GDI to drawing pdf page renderings (images) and it provides markup tools so the user can modify the pdf docs. This has been working great until I was handed a 5000px X 3000px image with 40-50 markups. This kind of made GDI snort cough and gag.
I've start moving that portion of the app to DirectX (because I have some (a little) experience with it). To draw the original image I have created a quad on the XY plane (z=0) and use the image to create a texture. When I draw the quad, I set the texture and draw the image. This works great. I have also implement pan and zoom which basically moves the camera around. To pan, I move the camera in a plane parallel to the XY plane. To zoom I simply change the camera's Z coordinate. This all works fine.
To place the markups in the drawing, I have created a sprite wrapper that contains the location and texture for the markup (the texture is created from an image made using GDI). When it comes time to draw the markups, I use a single sprite, call the its Draw method and pass the texture, and location. This too works but it's drawing the sprites in screen coordinates, not in world coordinates, so I believe they need to be transformed, but I don't know how.
Can some explain to me how I need to transform my sprites so they go where I need them to be?
Here is vb.net code I'm using to draw the sprite. It gets called from the game loop. I am using vb.net, but I can translate from just about any other language (c++ no so good, but I'll give it a go if need be).
VB.net Code:
Private Sub DrawSprite(ByVal _wrapper As spriteWrapper) Static mSprite As New Sprite(device) mSprite.Begin(SpriteFlags.None) Dim center As Vector3 = New Vector3(0.0F, 0.0F, 0.0F) 'the upper left corner of the sprite is 0,0 Dim position As Vector3 = New Vector3(_wrapper.Location.X, _wrapper.Location.Y, 0) mSprite.Draw(_wrapper.texture, Rectangle.Empty, center, position, Color.White) mSprite.End() End Sub
Thanks for looking!
kevin
Last edited by kebo; Apr 28th, 2017 at 09:40 AM.
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
May 1st, 2017, 06:44 PM
#2
Re: [RESOLVED] transform a sprite to move with the camera
If you are using DirectX and VB.Net, you need to make the sprites 2D polygons, and declare the vertex list as CustomVertex.TransformedColoredTextured(). Doing so will allow you to translate, rotate, or even scale the polygon. In your case it seems you want to translate. If you need a ton of code on doing this, check out my sig such as Flappy Bird, AStar Pathfinding or WoW Spell Cooldown to help you on the right path with DirectX.
Also btw I switched to C++ a loooong time ago for my DirectX needs. Its so fast :P
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|