Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 12:04 18 Dec 2025 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 : CMM2 DRAW3D Function - Is it obsolete?

Author Message
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 1075
Posted: 09:47pm 07 Dec 2025
Copy link to clipboard 
Print this post

I am working on the CMM2 code. I have found the DRAW3D Function in the code. It is not mentioned in the CMM2 3D Engine PDF and a search on TBS found only this thread that reference to it. I extracted the example program and it is below.
The DRAW3D function errors on the current released Version 5.07.01 and also on all the latest betas I tried.
Is the DRAW3D function obsolete, can I removed it.

Example using DRAW3D Function


option explicit
option default float
dim integer viewplane = 500
const camera = 1
dim q(4)
dim yaw=rad(1),pitch=rad(2),roll=rad(0.5)
dim integer nv=9, nf=9 ' cube has 9 vertices and 9 faces
'array to hold vertices
dim v(2,nv-1)=(-1,1,-1, 1,1,-1, 1,-1,-1, -1,-1,-1, -1,1,1, 1,1,1, 1,-1,1, -1,-1,1, 0,0,0)
math scale v(),200,v()
' array to hold number of vertices for each face
dim integer fc(nf-1) =(4,4,4,4,4,3,3,3,3)
dim integer cindex(9)=(rgb(red),rgb(blue),rgb(green),rgb(magenta),rgb(yellow),rgb(cyan),rgb(white),rgb(brown),rgb(gray),0)
dim integer fcol(nf-1)=(9,9,9,9,9,9,9,9,9)
dim integer bcol(nf-1)=(0,1,2,3,4,5,6,7,8)
'array to hold vertices for each face
dim integer fv(math(sum fc())-1)=(1,5,6,2, 1,0,4,5, 0,3,7,4, 5,4,7,6, 2,6,7,3, 0,1,8, 1,2,8, 3,8,2 , 3,0,8)
draw3d create 1, nv, nf, camera, v(), fc(), fv(),cindex(),fcol(),bcol()
dim integer c
page write 1
draw3d camera 1,viewplane, mm.hres\2, mm.vres\2
do
for c=0 to 720
timer=0
math q_create roll,1,1,1,q()
draw3d show 1,mm.hres\2,mm.vres\2,1000
' math q_euler yaw,pitch,roll,q()
draw3d rotate q(),1
print @(0,0)draw3d(XMIN 1),@(64)draw3d(xmax 1),@(128)draw3d(ymin 1),@(192)draw3d(ymax 1)
' inc yaw,rad(1)
' inc pitch,rad(2)
inc roll,rad(0.5)
page copy 1 to 0,b
next
loop
draw3d close all


F4 H7FotSF4xGT
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10709
Posted: 12:26pm 08 Dec 2025
Copy link to clipboard 
Print this post

It should be there and should work. The bug is in allcommands,h where the definitions is for it to return an int and it actually returns a float

{ "DRAW3D(",    T_FUN | T_INT, 0, fun_3D,    },


should be

{ "DRAW3D(",    T_FUN | T_NBR, 0, fun_3D,    },


In the example it is used to demonstrate how it could be used to define an area to be erased before re-drawing
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 1075
Posted: 09:56pm 08 Dec 2025
Copy link to clipboard 
Print this post

Peter,
Thanks that fixed it.
DRAW3D Function corrected and now works as expected.

I will add this to the manual.

The DRAW3D function can be used to determine the boundaries of a 3D object and could be used to define an area to be erased before re-drawing.

DRAW3D(XMIN n)'returns the leftmost x coordinate of a box bounding the render of 3d object n on the screen
DRAW3D(XMAX n)'returns the rightmost x coordinate of a box bounding the render of 3d object n on the screen
DRAW3D(YMIN n)'returns the upper y coordinate of a box bounding the render of 3d object n on the screen
DRAW3D(YMAX n)'returns the lower y coordinate of a box bounding the render of 3d object n on the screen
DRAW3D(DISTANCE n)'Returns distance to the box bounding the object n
DRAW3D(X n)'returns the x coordinate in the world current used to display 3D object n
DRAW3D(Y n)'returns the y coordinate in the world current used to display 3D object n
DRAW3D(Z n)'returns the y coordinate in the world current used to display 3D object n
Edited 2025-12-09 08:22 by disco4now
F4 H7FotSF4xGT
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1154
Posted: 06:40pm 09 Dec 2025
Copy link to clipboard 
Print this post

Is there any chance that this could be expanded to report the screen coordinates of the vertices (or more likely, a given vertex) of the render of a given 3d object?

For example,
DRAW3D(X n,v)
would return the x-coord of vertex number v of object number n. Coordinates beyond screen limits would still be valid.

Towards the end of the function void display3d(  ...params...  ) in Draw.c, each face is drawn using DrawPolygon(n, xcoord, ycoord, sortindex), so these coordinates are known, at least for a period of time. A way to access them would allow, for example, interacting with rendered objects. (I'm pondering a program to interactively draw/generate 3D objects.)
Visit Vegipete's *Mite Library for cool programs.
 
PeteCotton

Guru

Joined: 13/08/2020
Location: Canada
Posts: 582
Posted: 11:52pm 10 Dec 2025
Copy link to clipboard 
Print this post

  disco4now said  I am working on the CMM2 code. I have found the DRAW3D Function in the code. It is not mentioned in the CMM2 3D Engine PDF


I have been looking for a function like this. I thought about asking for it to be written - but didn't want to bother anyone. Thank you!

*I have 3D ships on the screen and want to print a distance value underneath each 3D object - but didn't have an easy way to translate a 3D point/object on to the 2D screen. This should work perfectly.
 
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 2025