Anybody got a (small) algorithm which can rotate a set of four vertices? Here is what I wish to do:
The routine only needs to know about the 4 verts. I need to be able to rotate them any angle from 0 to 360 degrees.
In case you are wondering why I don't just use 'RotateEntity' I am looking into creating a single-surface version of SpriteControl so I need to be able to rotate only a set of 4 verts within a mesh.
Here is some code to get you started. It just creates a quad and displays it on screen. I have references to the four verts - vx0/vy0 , vx1/vy1 ...
; Rotate 4 quad verts
; vertices in quad placed like so:
; 0 --------- 1
; | |
; | |
; | |
; | |
; 2 --------- 3
; set up 3d display -> gfxmode/camera/sprite pivot
Const gw=640,gh=480
Graphics3D gw,gh
SetBuffer BackBuffer()
spritecamera=CreateCamera()
spritepivot=CreatePivot(spritecamera)
aspect#=Float(gh)/Float(gw) : scale#=2.0/gw
PositionEntity spritepivot,-1,aspect,1.0
ScaleEntity spritepivot,scale,scale,scale
CameraClsColor spritecamera,190,160,20
WireFrame True
quad=CreateQuad(140,136,spritepivot)
DrawQuad quad,gw/3,gh/3
s=GetSurface(quad,1)
vx0#=VertexX(s,0) : vy0#=VertexY(s,0) ; top/left vert
vx1#=VertexX(s,1) : vy1#=VertexY(s,1) ; top/right vert
vx2#=VertexX(s,2) : vy2#=VertexY(s,2) ; bottom/left vert
vx3#=VertexX(s,3) : vy3#=VertexY(s,3) ; bottom right vert
RenderWorld
Flip
WaitKey
End
; create sprite quad
Function CreateQuad(w,h,par)
; Create quad mesh
Local sprite=CreateMesh(par)
Local s=CreateSurface(sprite)
AddVertex s,0,0,0 ,0,0 : AddVertex s,2,0,0 , 1,0
AddVertex s,0,-2,0 ,0,1 : AddVertex s,2,-2,0 , 1,1
AddTriangle s,0,1,2 : AddTriangle s,3,2,1
EntityFX sprite,1+16 : EntityOrder sprite,-100
ScaleEntity sprite,Float(w)/2,Float(h)/2,1
Return sprite
End Function
; Position 3d sprite at 2D screen coordinates
Function DrawQuad(sprite,x,y,z=0)
PositionEntity sprite,x+0.5,-y+0.5,z
End Function
|