andreww
07-02-2002, 05:22 AM
i want to be able to spin an image what ever degree i enter
with only one image
with only one image
is there a way to rotate an image with directx?andreww 07-02-2002, 05:22 AM i want to be able to spin an image what ever degree i enter with only one image lebb 07-02-2002, 06:54 AM Absolutely. Just use D3DXMatrixRotationX(YourMatrix, AngleInRadians) That will handle rotation around the x-axis; for the other axes, use D3DXMatrixRotationY or D3DXMatrixRotationZ. There should be quite a few examples in this forum, if you need more details. DrunkenHyena 07-02-2002, 09:34 PM G'day! If you're using DirectDraw then you're out of luck. I think some hardware supports 90 degree rotations, but arbitrary rotations are completely unsupported with DirectDraw. Which means either doing it manually or (maybe) using GDI. If it's something you're doing a lot of, GDI will not be fast enough. Most games just store different orientations. Doing it manually would probably require assembly to get it fast enough. So my recommendation (assuming DirectDraw) is to use a paint program and pre-rotate your art. Of course, if you're using D3D, then it's trivial. Stay Casual, Ken JimCamel 07-04-2002, 07:58 AM Originally posted by DrunkenHyena Which means either doing it manually or (maybe) using GDI. If it's something you're doing a lot of, GDI will not be fast enough. Most games just store different orientations. Doing it manually would probably require assembly to get it fast enough. Hi. I'd have to beg to differ with you DrukenHyena, I found some code a while ago which someone wrote and modified it to use DirectX, it's all written in VB, and it runs pretty fast. Public Const pi As Double = 3.141592654 '--------Function RotateSurface----- 'RotateSurface , takes a surface to rotate, the surface to draw the rotation on, the angle to rotate on, 'the x and y destination to draw on, an optional transparency value 'and optionally it can return the width and height of the surface Public Function RotateSurface(ByRef surfSource As DirectDrawSurface7, surfDestination As DirectDrawSurface7,_ lngAngle As Long, XDest As Long, Ydest As Long, Optional rgbTransparency As Long = -1, Optional ByRef Width As Long, _ Optional ByRef height As Long) Dim ddsdOriginal 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 ddsdOriginal lWidth = ddsdOriginal.lWidth lHeight = ddsdOriginal.lHeight dblRMax = Sqr(lWidth ^ 2 + lHeight ^ 2) surfSource.Lock rEmpty, ddsdOriginal, 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 rgbTransparency = -1 Or lngColor <> rgbTransparency 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 Width = lWidth / 2 - (iX * CosA + iY * SinA) height = lHeight / 2 - (iX * SinA - iY * CosA) End Function Sorry about the length of the code, hope it's useful though. If you have any trouble using it, drop me an email and I'll see if I can help. Jim DrunkenHyena 07-04-2002, 02:34 PM G'day! I guess it depends on how it's being used and how we define 'fast enough'. This approach is heavily CPU-bound. You will get no HW-accelleration at all. Pixel-writing to a video memory surface is very slow, which you can work-around by using a system memory surface for all rendering and then blt that to the back-buffer. All these criticisms aside, if you're using it on a relatively small number of objects and have a half-decent CPU to run on, it's not going to be an issue. I just don't see this method being very fast in the general case. Stay Casual, Ken |
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum