What funky maths do I need to successfully rotate a quad?
In the example below I'm using Sin/Cos to rotate 4 vertices by around 360 degrees.
As you press SPACE in the example you'll see the quad snap into a larger version then shrink and grow as it rotates.
How do I prevent this from happening?
For reference the quad is constructed/displayed like this:
In the example below I'm using Sin/Cos to rotate 4 vertices by around 360 degrees.
As you press SPACE in the example you'll see the quad snap into a larger version then shrink and grow as it rotates.
How do I prevent this from happening?
For reference the quad is constructed/displayed like this:
-1 +1 +1 +1 2--------3 | | | | | | 0--------1 -1 -1 +1 -1
; Quad (rotating) Graphics3D 640,480,0,2 SetBuffer BackBuffer() HidePointer cam=CreateCamera() MoveEntity cam,0,0,-6.5 MoveMouse 320,240 ; container for quads quad=CreateMesh() surf=CreateSurface(quad) EntityFX quad,1+2+32 ; texture for quads ;tex=LoadTexture("testimage.png") ;EntityTexture quad,tex ;For d=1 To 500 ; q=AddQuad(surf,Rnd(-10,10),Rnd(-10,10),Rnd(25)) ; QuadColor surf,q,Rand(255),Rand(255),Rand(255) , Rnd(1.0) ;Next mainquad=AddQuad(surf,0,0) ; ================================================== Repeat If KeyHit(17) ;[W] w=Not w WireFrame w EndIf If KeyDown(57) ; [SPACE] rotang#=rotang#+1.5 RotateQuad surf,mainquad,rotang EndIf mx#=mx#+Float(MouseXSpeed())/16.0 my#=my#-Float(MouseYSpeed())/16.0 MoveMouse 320,240 PositionQuad surf,mainquad,mx,my,0 RenderWorld Color 100,100,100 Text 20,40,"[MOUSE] = move main quad" Text 20,60,"[SPACE] = rotate main quad" Text 20,80,"[W] = Wireframe" Text 80,130,"Angle# = "+rotang ; reference box Color 200,0,0 Rect 320,140,100,100,0 Flip Until KeyHit(1) End ; ================================================== Function AddQuad%(s%,x#,y#,z#=0) Local o%,v% v=AddVertex(s,x-1,y-1,z ,0.0,1.0) AddVertex s,x+1,y-1,z , 1.0,1.0 AddVertex s,x-1,y+1,z , 0.0,0.0 AddVertex s,x+1,y+1,z , 1.0,0.0 AddTriangle s,v+0,v+2,v+1 AddTriangle s,v+1,v+2,v+3 For o=0 To 3 VertexNormal s,v+0,0,0,-1 Next Return v End Function Function QuadColor(s%,i%,r%,g%,b%,a#=1.0) Local o% For o=0 To 3 VertexColor s,i+o,r,g,b,a Next End Function Function PositionQuad(s%,i%,x#,y#,z#=0.0) Local dx#,dy#,dz# , o% dx=x-VertexX(s,i) dy=y-VertexY(s,i) dz=z-VertexZ(s,i) For o=0 To 3 VertexCoords s,i+o,VertexX(s,i+o)+dx,VertexY(s,i+o)+dy,VertexZ(s,i+o)+dz Next End Function Function RotateQuad(s,i,ang#) x#=VertexX(s,i+0)+1 : y#=VertexY(s,i+0)+1 VertexCoords s,i+0,(x-0.5)-Sin(ang+45),(y-0.5)-Cos(ang+45),VertexZ(s,i+0) VertexCoords s,i+1,(x+0.5)+Cos(ang+45),(y-0.5)-Sin(ang+45),VertexZ(s,i+1) VertexCoords s,i+2,(x-0.5)-Cos(ang+45),(y+0.5)+Sin(ang+45),VertexZ(s,i+2) VertexCoords s,i+3,(x+0.5)+Sin(ang+45),(y+0.5)+Cos(ang+45),VertexZ(s,i+3) End Function