Well, here is slightly revised code, which enables the radius parameter of the 3d circle command.
Rem PJY - the picnic basket obsessed bear's magic 3d circle code
sync on
sync rate 60
autocam off
d3d_init
Rem PJY - make a matrix to act as a visual reference point
make matrix 1, 1000, 1000, 100, 100
position matrix 1, -500, 0, -500
Rem PJY - stick the camera somewhere useful
position camera -50, 20, -50
point camera 0, 0, 20, 0
Rem PJY - create a completely random normalised vector
null = make vector3(1)
set vector3 1, 100, 50, 30
normalize vector3 1, 1
x# = x vector3(1)
y# = y vector3(1)
z# = z vector3(1)
null = delete vector3(1)
radius# = 5
repeat
text 0, 0, "FPS : " + str$(screen fps())
text 0, 30, "radius " + str$(radius#)
Rem PJY - make the radius of the circle increase and decrease
if radius# =< 99.9 AND reverse = 0
radius# = radius# + 0.1
endif
if radius# > 99.9
reverse = 1
endif
if radius# => 0.1 AND reverse = 1
radius# = radius# - 0.1
endif
if radius# < 0.1
reverse = 0
endif
rem circle3d(r, x, y, z, nx, ny, nz)
Rem PJY - say the circle has a radius of 10
Rem PJY - that its centre point coords are x = 0, y = 50, z = 0
Rem PJY - and feed in the normalised vector
circle3d(radius#, 0, 20, 0, x#, y#, z#)
control camera using arrowkeys 0, 2, 1
sync
until spacekey() > 0
delete matrix 1
FUNCTION circle3d(radius as float, x as float, y as float, z as float, nx as float, ny as float, nz as float)
Remstart
r is the radius
x, y and z are the centre coords for the circle
nx, ny and nz are the dimensions of the vector that define the normal of
the plane on which the circle resides
remend
null = make vector3(1)
null = make vector3(2)
null = make vector3(3)
null = make matrix4(4)
Rem PJY - set vector3 1 to be the normalised vector
set vector3 1, nx, ny, nz
Rem PJY - we need to create a normalised vector that is within the plane
Rem PJY - in order to do that, lets calculate the nearest point within the
Rem PJY - plane from another point (which I will choose randomly)
set vector3 2, 0, 100, 0
distance# = dot product vector3(1, 2)
Rem PJY - to find the point in the plane we now just scale the normalised vector by the distance
multiply vector3 1, distance#
Rem PJY - and create a normalised vector to the point in the plane
Rem PJY - via a bit of vector math (muhahahahaha)
subtract vector3 2, 2, 1
Rem PJY - now create a normalised vector from the centre to the new point
set vector3 3, x vector3(2) - x, y vector3(2) - y, z vector3(2) - z
normalize vector3 3, 3
multiply vector3 3, radius
d3d_line3d x, y, z, x + x vector3(3), y + y vector3(3), z + z vector3(3), rgb(255, 0, 255), 1
Rem PJY - re-normalise the normal vector
set vector3 1, nx, ny, nz
Rem PJY - around and around we go, where we stop ...
for angle = 1 to 360
build rotation axis matrix4 4, 1, angle
rem transform normals vector3 2, 3, 4
transform coords vector3 2, 3, 4
x_circle# = x + x vector3(2)
y_circle# = y + y vector3(2)
z_circle# = z + z vector3(2)
d3d_dot3d x_circle#, y_circle#, z_circle#, 3, rgb(255, 0, 0), 1
next angle
Rem PJY - create a lovely green line to represent a somewhat longer version of the normalised vector of the circle
d3d_line3d x, y, z, x + nx, y + ny, z + nz, rgb(0, 255, 0), 1
null = delete vector3(1)
null = delete vector3(2)
null = delete vector3(3)
null = delete matrix4(4)
ENDFUNCTION
But, there is a curiosity (as always with these things). It is that the circle is drawn on a plane further away from the centre of the plane. There does seem to be something wrong with the definition of the vector from the centre of the 3d circle to the edge. It seems to be slightly more than 90 degrees to the normalised vector of the plane. I've looked at this code for a while and I can't spot any obvious mathematical error. It occurred to me that it might be a float / integer issue but I can't see any example of that either.
Possibly a bug? If so, a very very small one.
Cheer if you like bears! Cheer if you like jam sandwiches!
Quote of the week: "... I started learning DBP while I was a Satellite Network Controller for the US Army Space Command ... "