I need some help with DirectDraw. I am trying to make a game where you fly a spaceship around. Is their any function anywhere in DirectDraw/2D DirectX stuff that rotates a bmp?
Printable View
I need some help with DirectDraw. I am trying to make a game where you fly a spaceship around. Is their any function anywhere in DirectDraw/2D DirectX stuff that rotates a bmp?
No you need to find a function that rotates the image for you :D :D
Normally you have all the angles of the ship in a bitmap and blit that part of the bitmap
Know any program that can generate all those angles?
make ur own program
use it as a tool.
use getpixel, setpixel and basic trigonometry
if u want this wrk to be done by some software, god save u
In Direct3D/Graphics, you can assign a texture to a quad and user-rotate the quad (if you're in non-Z mode). It's quite simple, I did it when I was first playing around with it. If you decide to switch to 3D, I can give you some code to get you on your way.
Are you using a 2D DirectDraw engine or are you doing that sort of stuff in your code? If your using a 2d engine and it doesn't let you rotate it'll be quite resourse hungry to do it seprate.
Although if your doing DirectDraw stuff yourself you'll need to create Direct3D surfaces instead of normal directdraw surfaces, for ones that need to be rotated. You can uses Direct3D surfaces practically as if they normal 2D surfaces. Direct3D surfaces can only be in sizes like: 16*16, 32*32, 64*64,ect... Really fast with rotating tho.
If you were using a 2D engine you could try my one coz it lets you use Direct3D surfaces, My Engine: http://www.electroman.co.uk/Electro2DE7.htm
OK.....look at PLANETSOURCECODE.COM try searching for GTA clone or something....it is an example on how to rotate a sprite in DDraw....I have tested it, but it is only half the speed of using a sprite with the rotation....but it is probably fast enough for small rotations...
Paint Shop Pro would work just fine.Quote:
Originally posted by VBD
Know any program that can generate all those angles?
BTW here is the code for the module to rotate the sprite in VB using DDraw....
VB Code:
Option Explicit Public Const PI As Double = 3.14159265358979 Public carwidth As Integer, carheight As Integer Public Sub RotateSurface(ByRef surfSource As DirectDrawSurface7, surfDestination As DirectDrawSurface7, lngAngle As Long, XDest As Long, Ydest As Long) Dim ddsdOrigine As DDSURFACEDESC2, ddsdDestination As DDSURFACEDESC2 Dim iX As Long, iY As Long Dim iXDest As Long, iYDest As Long Dim rEmpty As RECT, rEmpty2 As RECT Dim sngA As Single, SinA As Single, CosA As Single Dim dblRMax As Long Dim lngXO As Long, lngYO As Long Dim lngColor As Long Dim lWidth As Long, lHeight As Long sngA = lngAngle * PI / 180 SinA = Sin(sngA) CosA = Cos(sngA) surfSource.GetSurfaceDesc ddsdOrigine lWidth = ddsdOrigine.lWidth lHeight = ddsdOrigine.lHeight dblRMax = Sqr(lWidth ^ 2 + lHeight ^ 2) surfSource.Lock rEmpty, ddsdOrigine, DDLOCK_WAIT, 0 surfDestination.GetSurfaceDesc ddsdDestination surfDestination.Lock rEmpty2, ddsdDestination, DDLOCK_WAIT, 0 XDest = XDest + lWidth / 2 Ydest = Ydest + lHeight / 2 For iX = -dblRMax To dblRMax For iY = -dblRMax To dblRMax lngXO = lWidth / 2 - (iX * CosA + iY * SinA) lngYO = lHeight / 2 - (iX * SinA - iY * CosA) If lngXO >= 0 Then If lngYO >= 0 Then If lngXO < lWidth Then If lngYO < lHeight Then lngColor = surfSource.GetLockedPixel(lngXO, lngYO) If lngColor <> 0 Then surfDestination.SetLockedPixel XDest + iX, Ydest + iY, lngColor End If End If End If End If End If Next iY Next iX surfSource.Unlock rEmpty surfDestination.Unlock rEmpty2 carwidth = lWidth / 2 - (iX * CosA + iY * SinA) carheight = lHeight / 2 - (iX * SinA - iY * CosA) End Sub
It's not my code, so don't give the credit to me...