Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 20:29 03 May 2026 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : PicoMiteVGA DEMO

     Page 12 of 12    
Author Message
javavi

Guru

Joined: 01/10/2023
Location: Ukraine
Posts: 551
Posted: 04:49pm 26 Apr 2026
Copy link to clipboard 
Print this post

Rotating 2D sphere
with and without cache tracing

'Option TraceCache On 32

Const NumPoints = 500
Const Radius = 190
Const Dist = 500
Const X0 = MM.HRES\2
Const Y0 = MM.VRES\2

Dim x(NumPoints), y(NumPoints), z(NumPoints)
Dim angleX, angleY

For i=1 To NumPoints
phi=2*Pi*Rnd
theta=ACos(2*Rnd-1)
x(i)=Radius*Sin(theta)*Cos(phi)
y(i)=Radius*Sin(theta)*Sin(phi)
z(i)=Radius*Cos(theta)
Next

Colour RGB(Cyan)

Do
Inc angleX,.02
Inc angleY,.03
CLS : Print Timer: Timer =0

For i=1 To NumPoints
 ny=y(i)*Cos(angleX)-z(i)*Sin(angleX)
 nz=y(i)*Sin(angleX)+z(i)*Cos(angleX)
 nx=x(i)*Sin(angleY)+nz*Cos(angleY)

 finalZ=-x(i)*Sin(angleY)+nz*Cos(angleY)
 proj=dist/(dist-finalZ)
 Pixel X0+nx*proj,Y0+ny*proj
Next
Loop While Inkey$=""
 
javavi

Guru

Joined: 01/10/2023
Location: Ukraine
Posts: 551
Posted: 10:45am 02 May 2026
Copy link to clipboard 
Print this post

Rotating 2D sphere with Option TraceCache
Option TraceCache On 32
CLS
Dim N=600, R=200
Dim X(N), Y(N), Z(N)

For i=1 To N
TH=Pi*Rnd
PH=2*Pi*Rnd
X(i)=R*Sin(TH)*Cos(PH)
Y(i)=R*Sin(TH)*Sin(PH)
Z(i)=R*Cos(TH)
Next

AY=0.05: CY=Cos(AY): SY=Sin(AY)
AX=0.03: CX=Cos(AX): SX=Sin(AX)
OX=MM.HRES\2: OY=MM.VRES\2

Do
Timer =0
For i=1 To N
 If Z(i)>0 Then Pixel OX+X(i),OY+Y(i),0
 XT=X(i)*CY-Z(i)*SY:ZT=X(i)*SY+Z(i)*CY
 X(i)=XT:Z(i)=ZT
 YT=Y(i)*CX-Z(i)*SX:ZT=Y(i)*SX+Z(i)*CX
 Y(i)=YT: Z(i)=ZT
 If Z(i)>0 Then Pixel OX+X(i),OY+Y(i)
Next
Print @(0,0)Timer;
Loop While Inkey$=""
 
     Page 12 of 12    
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2026