I am trying to create text that spins around in a 3d cylinder pattern. I can seem to figure out the math that is involved. I would appreciate if anybody is interested in helping me figure out the math. or a better way of doing it.
The code follows:
The code follows:
Strict ' functionject; threeD ROTATING CUBE Date; Unknown Date ' Author; Joshua Dickerson ' Origin; FidoNet QUIK_BAS Echo ' modified for bmax by Jesse Perez '=========================================================================== Framework BRL.GLMax2D AppTitle = "cube" Graphics 640,480,16 Local array:Tnode[]=texttable("Hello World!") Local threeDobject:TthreeDobject = New TthreeDobject.create() threeDobject.nodelist=ListFromArray(array) While Not KeyDown(KEY_ESCAPE) Cls threeDobject.AngleAxisz = (threeDobject.AngleAxisz + 1) Mod 360 threeDobject.AngleAxisx = 180'(threeDobject.AngleAxisx +1) Mod 360 threeDobject.AngleAxisy =0 '(threeDobject.AngleAxisy +1) Mod 360 threeDobject.draw() Flip() Wend End Type Tnode Field threeDx# Field threeDy# Field threeDz# Field color Global twoDx# Global twoDy# End Type Function setfont:Int(name$=Null,size=8) If Name If size<8 size = 8 If size>40 size = 40 Local font:timagefont =LoadImageFont( name,size) If font SetImageFont(font);Return 1 EndIf Return 0 EndFunction Function texttable:tnode[](text$) Local Twidth#=TextWidth(text) Local Theight#=TextHeight(text) Local tlength=Len(text) Local array:tnode[twidth*Theight] Local image:timage=CreateImage(Twidth,theight,1,DYNAMICIMAGE) Local map:tpixmap Local radius#=50.0 Local circumference# = Pi*radius Local fg# = twidth/circumference Local sgh# = theight/circumference Local ang# = circumference/360.0 Local sg# = fg/ang Cls Local c = 0 DrawText text,0,0 GrabImage image,0,0 map = LockImage(image) Cls For Local y = 0 To PixmapHeight(map)-1 For Local x=0 To PixmapWidth(map)-1 Local color = $ff&ReadPixel(map,x,y) If color array[c]=New tnode Local xd# =(x-twidth/2)*sg Local yd# =(y-theight/2)*sg array[c].threeDx = (Cos(xd) * Cos((xd)) * radius) array[c].threeDy = (Cos(yd) * Sin((yd)) * radius) array[c].threeDz = -Sin(xd) * radius array[c].color=color c=c+1 EndIf Next Next array=array[..c-1] Return array EndFunction Type TthreeDobject Global D#,Z# Global AngleAxisz#, AngleAxisx#, AngleAxisy#, mZ# Global sinAngleAxisz#,cosAngleAxisz#, cosAngleAxisx#, sinAngleAxisx#, sinAngleAxisy#, cosAngleAxisy# Global nodeList:Tlist Function create:TthreeDobject(IsInHardDrive=0,filename:tstream=Null) Local nodes SetOrigin 320, 240 SetColor 255,0,0 Local threeDobject:TthreeDobject = New TthreeDobject threeDobject.D# = 400 'View point And rotation values threeDobject.mZ# = -100 'shift from z axis away from viewpoint threeDobject.AngleAxisz# = 0 'spin along y axis; angle of z threeDobject.AngleAxisx# = 0 'spin along z axiz; angle of x threeDobject.AngleAxisy# = 0 'spin along x axis; angle of y Return threeDobject End Function Function Calc3d(point:tnode) Local Xa# = cosAngleAxisz * point.threeDx - sinAngleAxisz * point.threeDz Local Ya# = cosAngleAxisx * point.threeDy - sinAngleAxisx * Xa Local Za# = sinAngleAxisz * point.threeDx + cosAngleAxisz * point.threeDz Z = cosAngleAxisy * Za - sinAngleAxisy * Ya + mZ point.twoDx = (cosAngleAxisx * Xa + sinAngleAxisx * point.threeDy ) * D / Z; point.twoDy = (sinAngleAxisy * Za + cosAngleAxisy * Ya) * D / Z; End Function Method Draw() sinAngleAxisz = Sin(AngleAxisz) cosAngleAxisz = Cos(AngleAxisz) sinAngleAxisx = Sin(AngleAxisx) cosAngleAxisx = Cos(AngleAxisx) sinAngleAxisy = Sin(AngleAxisy) cosAngleAxisy = Cos(AngleAxisy) For Local node:tnode = EachIn nodeList Calc3d(node) If Z < 0 Then Plot node.twoDx,node.twoDy',node.twoDx2,node.twoDy2 'get start and end points before drawing. Next End Method End Type