I am experimenting with a simple planet atmosphere FX without textures. I have a sphere and a ring of triangles surrounding the sphere, the ring always points to the cam. It looks nice when you're far away from the planet but doesn't work when you get closer. I am looking for some kind of formula which resizes/repositions the ring according to the viewer's perspective along the sphere. I tried some experiments with SQR,EXP and so on but wasn't successful. And even if I got close to an acceptable result it didn't worked anymore when I resized the sphere from 1.0 to 2.0 or other values.
Here is a demo code to visualize the problem:
Any suggestions?
Here is a demo code to visualize the problem:
Graphics3D 1024,768,32,2 ; Variables mousespeed#=0.1 cameraspeed#=0.05 camerasmoothness#=10 scale#=1.0 ; Camera cam=CreateCamera() PositionEntity cam,0,0,-5 CameraRange cam,0.1,100 ; Planet planet=CreateSphere(32) ScaleEntity planet,scale,scale,scale EntityColor planet,0,255,0 EntityFX planet,1 ; Glow ring=CreateRing(1*scale,1.5*scale,30,1,255,255,255,32,32,32,0) EntityFX ring,1+2+32 ; Timer timer=CreateTimer(60) MoveMouse GraphicsWidth()/2,GraphicsHeight()/2 While Not KeyHit(1) ; SPACE = Wireframe If KeyHit(57) Then wf=1-wf : WireFrame wf ; Mousecam mx#=CurveValue(MouseXSpeed()*mousespeed,mx,camerasmoothness) my#=CurveValue(MouseYSpeed()*mousespeed,my,camerasmoothness) MoveMouse GraphicsWidth()/2,GraphicsHeight()/2 pitch#=EntityPitch(cam) yaw#=EntityYaw(cam) pitch=pitch+my yaw=yaw-mx If pitch>89 Then pitch=89 If pitch<-89 Then pitch=-89 RotateEntity cam,0,yaw,0 TurnEntity cam,pitch,0,0 ; Movement cx#=(KeyDown(205)-KeyDown(203))*cameraspeed cz#=(KeyDown(200)-KeyDown(208))*cameraspeed MoveEntity cam,cx,0,cz ; Ring points always to camera PointEntity ring,cam TurnEntity ring,-90,0,0 RenderWorld WaitTimer timer Flip Wend End ; Smoothcam Function CurveValue#(newvalue#,oldvalue#,increments ) If increments>1 oldvalue#=oldvalue#-(oldvalue#-newvalue#)/increments If increments<=1 oldvalue=newvalue Return oldvalue# End Function ; Create Single Surface Ring Function CreateRing(radius1#=1.0,radius2#=2.0,segments%=360,fx%=0,r1%=255,g1%=255,b1%=255,r2%=0,g2%=0,b2%=0,a#=1.0) Local a1#,a2#,a3#,a4#,angle% Local mesh=CreateMesh() Local surf=CreateSurface(mesh) ; Limit segments If segments>360 Then segments=360 ; Create ring For angle=1 To segments a1=angle*360.0/segments a2=angle*360.0/segments +360.0/segments a3=angle*360.0/segments +180.0/segments a4=angle*360.0/segments -180.0/segments ; Calc vertex points v0=AddVertex(surf,radius1*Cos(a1),0,radius1*Sin(a1),0,0) v1=AddVertex(surf,radius1*Cos(a2),0,radius1*Sin(a2),0,0) v2=AddVertex(surf,radius2*Cos(a3),0,radius2*Sin(a3),1,1) v3=AddVertex(surf,radius2*Cos(a4),0,radius2*Sin(a4),1,1) ; Color VertexColor surf,v0,r1,g1,b1,1 VertexColor surf,v1,r1,g1,b1,1 VertexColor surf,v2,r2,g2,b2,a VertexColor surf,v3,r2,g2,b2,a ; Create Triangles AddTriangle surf,v2,v1,v0 AddTriangle surf,v0,v3,v2 Next If fx>0 Then EntityFX mesh,fx Return mesh End Function
Any suggestions?



