In DG8, is it possible to use the matrix with transformed vertices (like for doing 2D). If not, how would one go about rotation?
Printable View
In DG8, is it possible to use the matrix with transformed vertices (like for doing 2D). If not, how would one go about rotation?
Sorry I only use DX8 for 3D mainly, then rotation is easy. My only 2d experience of it is very simply drawing 2d shapes on the screen. Also 2d text using RECTs.
I guess this wont help but if any of the above sounds of any use just say and Ill get back 2 u.
Well, I figured that the way that DirectX works - with vertices - I could do my own rotation, by simply using sine and cosine and rorating the vertices from the centrepoint, while keeping the same textture coordinates.
thats the way id do it 2 if i needed 2
Though I hope you would use texture coordinates and not the textture ones I described above :D
2D vertices will be drawn directly to the screen, with NO transformations applied by D3D. If you want rotation, you have to do it yourself =).
Sorry for not replying to this sooner... I didnt see it =(.
Z.
That's ok. But now I have my own little problem... I can't seem to make it rotate! It's an odd RECT, that's higher than wide... I don't want anybody to write anything, but some theory would help! I've got my own type of RECT that has a centre point and positive/negative X and Y values giving the locations of the sides. It's just a bit confusing :D
Okay, I got it!! Look at this rather messy code:You have to give it a bounding box or it will not rotate properly (it will stretch and skew). I figured this out with a tutorial on vector rotation from Lucky's site! (that's where the RotateVectOverZ function is from).VB Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) Static Angle As Double Dim TL As D3DVECTOR Dim TR As D3DVECTOR Dim BL As D3DVECTOR Dim BR As D3DVECTOR Select Case KeyCode Case vbKeyLeft Angle = Angle + 4.5 Case vbKeyRight Angle = Angle - 4.5 Case Else Exit Sub End Select TL.z = 0 TL.x = -0.2 TL.y = -1 TR.z = 0 TR.x = 0.2 TR.y = -1 BL.z = 0 BL.x = -0.2 BL.y = 1 BR.z = 0 BR.x = 0.2 BR.y = 1 RotateVectOverZ TL, Angle * (3.1415926 / 180) RotateVectOverZ TR, Angle * (3.1415926 / 180) RotateVectOverZ BL, Angle * (3.1415926 / 180) RotateVectOverZ BR, Angle * (3.1415926 / 180) Line1.x1 = 100 + TL.x * 50 Line1.y1 = 100 + TL.y * 50 Line1.x2 = 100 + TR.x * 50 Line1.y2 = 100 + TR.y * 50 Line2.x1 = 100 + TR.x * 50 Line2.y1 = 100 + TR.y * 50 Line2.x2 = 100 + BR.x * 50 Line2.y2 = 100 + BR.y * 50 Line3.x1 = 100 + BL.x * 50 Line3.y1 = 100 + BL.y * 50 Line3.x2 = 100 + TL.x * 50 Line3.y2 = 100 + TL.y * 50 Line4.x1 = 100 + BR.x * 50 Line4.y1 = 100 + BR.y * 50 Line4.x2 = 100 + BL.x * 50 Line4.y2 = 100 + BL.y * 50 End Sub Public Sub RotateVectOverZ(Vect As D3DVECTOR, Rads As Single) Dim TVect As D3DVECTOR TVect = Vect Vect.x = TVect.x * Cos(Rads) + TVect.y * Sin(Rads) Vect.y = TVect.y * Cos(Rads) - TVect.x * Sin(Rads) Vect.z = TVect.z End Sub
Geez, at least use the Line function to draw your box =). It would look much cleaner =).
Good work. DOnt you have VBGP? It has 2D matrix operations in there, which you would also use for this purpose.
Z.
Yeah I do, but they're just magazines on the proverbial coffee table, mostly. I don't find them useful, and I'd rather spend time looking on the net :)
And about the horrible code, that was just to see if it would work... The real implementation is in DirectX8 :)
Doing some fun nifty stuff, eh? =).
Z.
Yes, I'm actually testing some stuff out :) I know I'll have to do some 2D programming this year and want to have my own DLL with which to do it :)