PureCAD - WIP
Posted: Tue Dec 31, 2024 4:11 pm
Hello
Ok I don't have advanced my project for PureCAD so much but I am happy to share you my current codes
(a bit old thought)
It is my WIP now, very rough and I hope in progress I will add some finished to features
Here my code so far :
Enjoy to use based on my codes in your own purpose
See you soon
PS : @marc_256 you will love this and say me what do you think of that ?

Ok I don't have advanced my project for PureCAD so much but I am happy to share you my current codes

It is my WIP now, very rough and I hope in progress I will add some finished to features

Here my code so far :
Code: Select all
; Inspired from opengl swept surface - Phil James 11/2024
; 'Lathe' function converted from: https://stackoverflow.com/questions/7904281/opengl-rotate-a-curve-about-the-y-axis
; It is different path and it look like to a simple CAD Modeling :)
;
; Name of software : PureCAD
; Version of software : 0.1
; Date of starting to development : 06/11/2024
; Date of finishing to development : 07/11/2024
; Author of this software : threedslider
EnableExplicit
InitKeyboard()
InitSprite()
InitMouse()
#Width = 1024
#Height = 768
#Slices = 48 ; how many rotations for a full revolution, it is default.
#Points = 1024
#ORTHO = 0
#PERSP = 1
#SINGLE_VIEWPORT = 1
#FOUR_VIEWPORT = 0
Enumeration
#my_GL
#button_wireframe
#button_opengl_flat
#button_opengl_flat_wireframe
#button_opengl_smooth
#button_opengl_smooth__wireframe
#button_add_vertex
#button_add_face
#button_remove_vertex
#button_remove_face
#button_clear_lathe
#button_draw_lathe
EndEnumeration
Enumeration
#myTimer_Render
EndEnumeration
Structure my_win
w.i
h.i
EndStructure
Structure Vec3
x.f
y.f
z.f
is_Select.i
id.i
EndStructure
Structure Vertex
position.Vec3
normal.Vec3
isSelect.i
EndStructure
Structure Face_tris
Array a.Vec3(0)
Array b.Vec3(0)
Array c.Vec3(0)
cmpFace.i
Array tmpFace.i(3)
id.i
EndStructure
Structure Face_quad
Array a.Vec3(0)
Array b.Vec3(0)
Array c.Vec3(0)
Array d.Vec3(0)
cmpFace.i
Array tmpFace.i(4)
id.i
EndStructure
Structure Object
EndStructure
Structure Viewport
Array _viewport.i(4)
Array proj.f(16)
Array model.f(16)
rot.Vec3
center.Vec3
zoom.f
mouse_is.i
EndStructure
Structure Viewport_system
view_solo.i
EndStructure
Structure Mouse
state.i
button.i
active.i
Left.i
Right.i
Shift.i
Ctrl.i
Alt.i
None.i
x.f
y.f
posx.f
posy.f
clicx.f
clicy.f
MouseIs.i
EndStructure
Global glist.l
Global my_w.my_win
Global view.Viewport
Global Dim viewtb.Viewport(5)
Global viewtb0.Viewport
Global viewtb1.Viewport
Global viewtb2.Viewport
Global viewtb3.Viewport
Global viewtb4.Viewport
Global vpt_sys.Viewport_system
Global Dim vt.Vec3(0)
Global Dim model.Vertex(0)
Global Dim vertices.Vec3(0)
Global f3.Face_tris
Global f4.Face_quad
Global ms.Mouse
my_w\w = 0
my_w\h = 0
f3\cmpFace = 0
ms\Left = #False
Macro Vec3_Subtract(v, w, n)
n\x = v\x - w\x
n\y = v\y - w\y
n\z = v\z - w\z
EndMacro
Macro DeleteArrayElement(ar, el)
Define.i _a
For _a=el To ArraySize(ar())-1
ar(_a) = ar(_a+1)
Next
ReDim ar(ArraySize(ar())-1)
EndMacro
Macro AddElement(ar, el, p, x)
For a=el To p Step -1
ar(a) = ar(a-1)
Next
ar(p) = x
EndMacro
Macro AddArrayElement(ar)
ReDim ar(ArraySize(ar())+1)
;ar(ArraySize(ar())) = x
EndMacro
Procedure normalize(*V.Vec3)
Define.f magnitude, inverse_magnitude
magnitude = *V\x * *V\x + *V\y * *V\y + *V\z * *V\z
If magnitude > 0
inverse_magnitude = 1.0 / Sqr(magnitude)
*V\x * inverse_magnitude
*V\y * inverse_magnitude
*V\z * inverse_magnitude
EndIf
EndProcedure
Procedure normal_face(*v1.Vec3, *v2.Vec3, *v3.Vec3, *n_out.Vec3)
Protected.Vec3 v2v1, v3v1
Vec3_Subtract(*v2, *v1, v2v1)
Vec3_Subtract(*v3, *v1, v3v1)
*n_out\x = v2v1\y * v3v1\z - v2v1\z * v3v1\y
*n_out\y = v2v1\z * v3v1\x - v2v1\x * v3v1\z
*n_out\z = v2v1\x * v3v1\y - v2v1\y * v3v1\x
normalize(*n_out)
EndProcedure
Declare setupmatrix_ortho(id.i)
Declare setupmatrix_persp(id.i)
Declare setupmodelmatrix(id.i)
Declare loadviewport(id.i)
Procedure setviewport_ortho(id.i, x.i, y.i, w.i, h.i, cx.f, cy.f, cz.f )
Shared viewtb.Viewport()
;Debug id
viewtb(id)\center\x = cx
viewtb(id)\center\y = cy
viewtb(id)\center\z = cz
viewtb(id)\_viewport(0) = x
viewtb(id)\_viewport(1) = y
viewtb(id)\_viewport(2) = w
viewtb(id)\_viewport(3) = h
setupmatrix_ortho(id)
EndProcedure
Procedure setviewport_persp(id.i, x.i, y.i, w.i, h.i, cx.f, cy.f, cz.f )
Shared viewtb.Viewport()
;Debug id
viewtb(id)\center\x = cx
viewtb(id)\center\y = cy
viewtb(id)\center\z = cz
viewtb(id)\_viewport(0) = x
viewtb(id)\_viewport(1) = y
viewtb(id)\_viewport(2) = w
viewtb(id)\_viewport(3) = h
setupmatrix_persp(id)
EndProcedure
;
; Procedure setviewport3(id.i, x.i, y.i, w.i, h.i, cx.f, cy.f, cz.f )
; Shared viewtb3.Viewport
;
; ;Debug id
;
; viewtb3(id)\center\x = cx
; viewtb3(id)\center\y = cy
; viewtb3(id)\center\z = cz
;
; viewtb3(id)\_viewport(0) = x
; viewtb3(id)\_viewport(1) = y
; viewtb3(id)\_viewport(2) = w
; viewtb3(id)\_viewport(3) = h
;
; setupmatrix(id)
;
; EndProcedure
;
; Procedure setviewport4(id.i, x.i, y.i, w.i, h.i, cx.f, cy.f, cz.f )
; Shared viewtb4.Viewport
;
; ;Debug id
;
; viewtb4(id)\center\x = cx
; viewtb4(id)\center\y = cy
; viewtb4(id)\center\z = cz
;
; viewtb4(id)\_viewport(0) = x
; viewtb4(id)\_viewport(1) = y
; viewtb4(id)\_viewport(2) = w
; viewtb4(id)\_viewport(3) = h
;
; setupmatrix(id)
;
; EndProcedure
Procedure setupmatrix_ortho(id.i)
; Shared viewtb.Viewport()
glEnable_(#GL_SCISSOR_TEST);
; Enable depth test
glEnable_(#GL_DEPTH_TEST);
glDepthFunc_(#GL_LEQUAL)
glEnable_(#GL_LINE_SMOOTH)
glEnable_(#GL_BLEND)
glBlendFunc_(#GL_SRC_ALPHA, #GL_ONE_MINUS_SRC_ALPHA)
glMatrixMode_(#GL_PROJECTION)
glLoadIdentity_()
;glOrtho_(-1, 1, -1, 1.0, 60.0, -60)
;loadviewport(id)
glOrtho_((-viewtb(id)\_viewport(2)/2) / viewtb(id)\zoom, (viewtb(id)\_viewport(2)/2) / viewtb(id)\zoom, (-viewtb(id)\_viewport(3)/2) / viewtb(id)\zoom, (viewtb(id)\_viewport(3)/2) / viewtb(id)\zoom, 100000, -100000)
glMatrixMode_(#GL_MODELVIEW)
;glCallList_(glist)
;glGetFloatv_(#GL_PROJECTION_MATRIX, viewtb(id)\proj())
;setupmodelmatrix(id)
EndProcedure
Procedure setupmatrix_persp(id.i)
; Shared viewtb.Viewport()
glEnable_(#GL_SCISSOR_TEST);
; Enable depth test
glEnable_(#GL_DEPTH_TEST);
glDepthFunc_(#GL_LEQUAL)
glEnable_(#GL_LINE_SMOOTH)
glEnable_(#GL_BLEND)
glBlendFunc_(#GL_SRC_ALPHA, #GL_ONE_MINUS_SRC_ALPHA)
glMatrixMode_(#GL_PROJECTION)
glLoadIdentity_()
;glOrtho_(-1, 1, -1, 1.0, 60.0, -60)
;loadviewport(id)
gluPerspective_(45.0, #Width/#Height, 1.0, 60.0)
glTranslatef_(0, 0, -4)
glMatrixMode_(#GL_MODELVIEW)
;glCallList_(glist)
;glGetFloatv_(#GL_PROJECTION_MATRIX, viewtb(id)\proj())
;setupmodelmatrix(id)
EndProcedure
;
Procedure setupmodelmatrix(id.i)
Shared viewtb.Viewport()
glMatrixMode_(#GL_MODELVIEW)
glLoadIdentity_()
glRotatef_(viewtb(id)\rot\x, 1,0,0)
glRotatef_(viewtb(id)\rot\y, 0,1,0)
glRotatef_(viewtb(id)\rot\z, 0,0,1)
glTranslatef_(-viewtb(id)\center\x, -viewtb(id)\center\y, -viewtb(id)\center\z)
glMatrixMode_(#GL_MODELVIEW)
; glClearColor_(0.7, 0.0, 0.0, 0) ; background color
; glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
;glCallList_(glist)
;glGetFloatv_(#GL_MODELVIEW_MATRIX, viewtb(id)\model())
EndProcedure
Procedure loadviewport(id.i)
;Shared viewtb.Viewport()
glViewport_(viewtb(id)\_viewport(0), viewtb(id)\_viewport(1), viewtb(id)\_viewport(2), viewtb(id)\_viewport(3))
;glScissor_(viewtb(id)\_viewport(0), viewtb(id)\_viewport(1), viewtb(id)\_viewport(2), viewtb(id)\_viewport(3))
glCallList_(glist)
EndProcedure
Procedure setrotview(id.i, axe.i, val.f)
Shared viewtb.Viewport()
If axe = 0
viewtb(id)\rot\x = viewtb(id)\rot\x + val
;SetupMatrix(id)
EndIf
If axe = 1
viewtb(id)\rot\y = viewtb(id)\rot\y + val
;SetupMatrix(id)
EndIf
If axe = 2
viewtb(id)\rot\z = viewtb(id)\rot\z + val
;SetupMatrix(id)
EndIf
EndProcedure
Procedure zoominview(id.i, zoom.f)
Shared viewtb.Viewport()
viewtb(id)\zoom = (viewtb(id)\zoom + zoom) * zoom
;setupmatrix(id)
EndProcedure
; Procedure zoomoutview(id.i, zoom.f)
; Shared viewtb.Viewport()
;
; viewtb(id)\zoom = (viewtb(id)\zoom + zoom) / zoom
; setupmatrix(id)
;
; EndProcedure
;
; Procedure.i iswin(id.i, x.i, y.i)
;
; Shared viewtb.Viewport()
;
; If ( x > viewtb(id)\_viewport(0) And x < viewtb(id)\_viewport(0)+viewtb(id)\_viewport(2) And y > viewtb(id)\_viewport(1) And y < viewtb(id)\_viewport(1)+viewtb(id)\_viewport(3))
; ProcedureReturn 1
; Else
; ProcedureReturn 0
; EndIf
; EndProcedure
;
; Procedure drawbord(id.i)
; Shared viewtb.Viewport()
;
; glBegin_(#GL_LINE_LOOP)
; glVertex2iv_(viewtb(id)\_viewport())
; glVertex2i_(viewtb(id)\_viewport(0)+viewtb(id)\_viewport(2)-1, viewtb(id)\_viewport(1))
; glVertex2i_(viewtb(id)\_viewport(0)+viewtb(id)\_viewport(2)-1, viewtb(id)\_viewport(1)+viewtb(id)\_viewport(3)-1)
; glVertex2i_(viewtb(id)\_viewport(0),viewtb(id)\_viewport(1)+viewtb(id)\_viewport(3)-1)
; glEnd_()
; EndProcedure
;
; Procedure setcenter(id.i, *m.Mouse)
; Shared viewtb.Viewport()
;
; Protected.f wx, wy, wz
; Protected.f _wx, _wy, _wz
; Protected.f x, y, z
;
; gluProject_(0,0,0, viewtb(id)\model(), viewtb(id)\proj(), viewtb(id)\_viewport(), @x, @y, @z)
;
; gluUnProject_ (*m\x, *m\y, z, viewtb(id)\model(), viewtb(id)\proj(),viewtb(id)\_viewport(), @wx, @wy, @wz)
;
; gluUnProject_ (*m\clicx, *m\clicy, z,viewtb(id)\model(), viewtb(id)\proj(), viewtb(id)\_viewport(), @_wx, @_wy, @_wz)
;
;
; viewtb(id)\center\x = viewtb(id)\center\x + (wx-_wx)
; viewtb(id)\center\y = viewtb(id)\center\x + (wy-_wy)
; viewtb(id)\center\z = viewtb(id)\center\x + (wz-_wz)
;
; SetupModelMatrix(id)
; EndProcedure
;
Procedure LoadOrtho()
Shared my_w.my_win
setviewport_ortho(0, 0, 0, my_w\w, my_w\h, my_w\w/2, my_w\h/2, 0)
EndProcedure
;
;
; Procedure loadviewportsystem(id.i, num.i)
; Shared viewtb.Viewport()
; Shared vpt_sys.Viewport_system
;
; If vpt_sys\view_solo = #SINGLE_VIEWPORT
; loadviewport(viewtb(id)\mouse_is)
; Else
; loadviewport(num)
; EndIf
; EndProcedure
;
Procedure loadviewportsolo(id.i)
Shared viewtb.Viewport()
LoadViewport(viewtb(id)\mouse_is)
EndProcedure
;
; Procedure Mouse_xy(x.i, y.i)
; Shared viewtb.Viewport()
; Shared vpt_sys.Viewport_system
;
; If vpt_sys\view_solo = #FOUR_VIEWPORT
;
; If IsWin(1, x, y)
; viewtb(1)\mouse_is=1
; ElseIf IsWin(2, x, y)
; viewtb(2)\mouse_is=2
; ElseIf IsWin(3, x, y)
; viewtb(3)\mouse_is=3
; ElseIf IsWin(4, x, y)
; viewtb(4)\mouse_is=4
; EndIf
;
; EndIf
; EndProcedure
;
; Procedure.i getMouse_is(id.i)
; Shared viewtb.Viewport()
; ProcedureReturn viewtb(id)\mouse_is
; EndProcedure
;
; Procedure Reshape(id.i, _w.i, _h.i)
; Shared viewtb.Viewport()
; Shared my_w.my_win
; Shared vpt_sys.Viewport_system
;
;
; my_w\w=_w
; my_w\h=_h
;
; setviewport(0, 0, 0, my_w\w, my_w\h, 0, 0, 0)
;
; If vpt_sys\view_solo = #SINGLE_VIEWPORT
;
; setviewport2(viewtb(id)\mouse_is, 0, 0, _w, _h, 0, 0, 0)
;
; Else
;
; SetViewport2(2, my_w\w/2, my_w\h/2, my_w\w/2, my_w\h/2, 0, 0, 0)
; SetViewport2(3, my_w\w/2, 0, my_w\w/2, my_w\h/2, 0, 0 ,0)
; SetViewport2(1, my_w\h/2, my_w\w/2, my_w\h/2, 0, 0, 0, 0)
; SetViewport2(4, 0, my_w\w/2, my_w\h/2, 0, 0, 0, 0)
; EndIf
; EndProcedure
;
; Procedure Solo(id.i, b.i)
; Shared viewtb.Viewport()
; Shared vpt_sys.Viewport_system
; Shared my_w.my_win
;
; vpt_sys\view_solo = b
; If vpt_sys\view_solo = #SINGLE_VIEWPORT
;
; setviewport2(viewtb(id)\mouse_is, 0, 0, my_w\w, my_w\h, 0, 0, 0)
; EndIf
;
; Reshape(id, my_w\w, my_w\h)
; EndProcedure
;
; Procedure InvSolo(id.i)
; Shared viewtb.Viewport()
; Shared vpt_sys.Viewport_system
; Shared my_w.my_win
;
; If vpt_sys\view_solo = 1
; vpt_sys\view_solo = 0
; ElseIf vpt_sys\view_solo = 0
; vpt_sys\view_solo = 1
; EndIf
;
;
; If vpt_sys\view_solo = #SINGLE_VIEWPORT
;
; setviewport2(viewtb(id)\mouse_is, 0, 0, my_w\w, my_w\h, 0, 0, 0)
; EndIf
;
; Reshape(id, my_w\w, my_w\h)
; EndProcedure
;
; Procedure setwinsolo(id.i, win.i)
; Shared viewtb.Viewport()
; Shared vpt_sys.Viewport_system
; Shared my_w.my_win
;
; vpt_sys\view_solo = #SINGLE_VIEWPORT
; viewtb(id)\mouse_is = win
; SetViewport2(win, 0, 0, my_w\w, my_w\h, 0, 0, 0)
; Reshape(id, my_w\w, my_w\h)
; EndProcedure
;
; Procedure.i GetSolo()
; Shared vpt_sys.Viewport_system
; ProcedureReturn vpt_sys\view_solo
; EndProcedure
; Procedure DrawContour()
; Shared vpt_sys.Viewport_system
; Protected.i i
; LoadViewport(0)
; If vpt_sys\view_solo = #FOUR_VIEWPORT
; For i=1 To 4
; If vpt_sys\mouse_is = i
; glColor3f_(0,0,1)
; Else
; glColor3f_(0,0,0)
; drawbord(i)
; EndIf
; Next
;
; Else
;
; glColor3f_(0,0,0)
; drawbord(vpt_sys\mouse_is)
; EndIf
;
; EndProcedure
;
; Procedure ZoomIn(z.f)
; Shared vpt_sys.Viewport_system
;
; zoominview(vpt_sys\mouse_is, z)
; EndProcedure
;
; Procedure ZoomOut(z.f)
; Shared vpt_sys.Viewport_system
;
; zoomoutview(vpt_sys\mouse_is, z)
; EndProcedure
;
;
; Procedure Rotate(axe.i, val.f)
; Shared vpt_sys.Viewport_system
;
; setrotview(vpt_sys\mouse_is, axe, val)
; EndProcedure
;
;
; Procedure ResetRotate(axe.i)
; Shared vpt_sys.Viewport_system
;
; Select axe
;
; Case 0
; setrotview(vpt_sys\mouse_is, 0, 90)
;
; Case 1
; setrotview(vpt_sys\mouse_is, 1, 0)
;
; Case 2
; setrotview(vpt_sys\mouse_is, 2, -90)
;
;
; EndSelect
; EndProcedure
;
; Procedure center(*m.Mouse)
; Shared vpt_sys.Viewport_system
; setcenter(vpt_sys\mouse_is, *m)
; EndProcedure
;
Procedure vertex_id(id.i, x.f, y.f, z.f)
Shared vt.Vec3()
vt(id)\id = id
vt(id)\x = x
vt(id)\y = y
vt(id)\z = z
EndProcedure
Procedure add_vertex(*m.Mouse, Array *v.Viewport(1))
Shared vt.Vec3()
Dim pos.f(3)
Dim tmp.f(3)
Static.i it = 0
Protected.i id
For id=1 To 4
gluProject_(0,0,0, *v(id)\model(), *v(id)\proj(), *v(id)\_viewport(), @Tmp(0), @Tmp(1), @tmp(2))
gluUnProject_(*m\x, *m\y, tmp(2), *v(id)\model(), *v(id)\proj(), *v(id)\_viewport(), @Pos(0), @Pos(1), @Pos(2))
Next
vertex_id(it, Pos(0), Pos(1), Pos(2))
Debug vt(0)\x
it = it + 1
AddArrayElement(vt)
EndProcedure
;
; Procedure translatevertex(id.i, *m.Mouse, *v.Viewport)
; Shared vt.Vec3()
;
; Protected.f wx, wy, wz
; Protected.f _wx, _wy, _wz
; Protected.f x, y, z
;
; gluProject_(0,0,0, *v\model(), *v\proj(), *v\_viewport(), @x, @y, @z)
;
; gluUnProject_ (*m\x, *m\y, z, *v\model(), *v\proj(), *v\_viewport(), @wx, @wy, @wz)
;
; gluUnProject_ (*m\clicx, *m\clicy, z, *v\model(), *v\proj(), *v\_viewport(), @_wx, @_wy, @_wz)
;
;
; If vt(id)\is_Select = 1
; vt(id)\x = vt(id)\x + (wx - _wx)
; vt(id)\y = vt(id)\y + (wy - _wy)
; vt(id)\z = vt(id)\z + (wz - _wz)
; EndIf
; EndProcedure
;
; Procedure selectvertex(*m.Mouse, *v.Viewport)
; Shared vt.Vec3()
;
; Protected.f zone=5
; Protected.f _x, _y, _z
; Protected.i id_vpt, id_vt
; Protected.i num_vpt, num_vt
;
; num_vt = ArraySize(vt())
;
; For id_vpt = 1 To 4
; For id_vt = 0 To num_vt
;
; gluProject_(vt(id_vt)\x, vt(id_vt)\y, vt(id_vt)\z, *v\model(), *v\proj(), *v\_viewport(), @_x, @_y, @_z)
;
; If( _x < *m\x+zone And _x > *m\x-zone And _y < *m\x+zone And _y > *m\x-zone )
;
; vt(id_vt)\is_Select = 1
; ProcedureReturn
; EndIf
; Next
; Next
;
; EndProcedure
;
; Procedure SelectAllVertex()
; Shared vt.Vec3()
;
; Protected.i id, size
;
; size = ArraySize(vt())
;
; For id = 0 To size
; vt(id)\is_Select = 1
; Next
;
; EndProcedure
;
; Procedure deselectallVertex()
; Shared vt.Vec3()
; Protected.i id, size
;
; size = ArraySize(vt())
;
; For id = 0 To size
; vt(id)\is_Select = 0
; Next
; EndProcedure
;
; Procedure DeleteVertexSelect(id.i)
; Shared vt.Vec3()
; Protected.i it, size
;
; size = ArraySize(vt())
;
; For it = 0 To size
; If vt(it)\id = id
; If vt(it)\is_Select = 1
; DeleteArrayElement(vt, vt(it)\id)
; EndIf
; EndIf
; Next
; EndProcedure
;
; Procedure DeleteAllVertex()
; Shared model.Vertex()
;
; FreeArray(model())
;
; EndProcedure
;
Procedure draw_vertex()
Shared vt.Vec3()
Protected.i id, number
number = ArraySize(vt())
glBegin_(#GL_POINTS)
For id = 0 To number
If vt(id)\is_Select = 1
glColor3f_(1,0,0)
Else
glColor3f_(1,1,1)
EndIf
glVertex3f_(vt(id)\x, vt(id)\y, vt(id)\z)
Next
glEnd_()
EndProcedure
;
; Procedure draw_vertex_gl()
;
; glPointSize_(3)
;
; draw_vertex()
;
; glPointSize_(1)
; EndProcedure
;
; Procedure Face_id_tris(id.i, id_vtx1.i, id_vtx2.i, id_vtx3.i)
; Shared vt.Vec3()
; Shared f3.Face_tris
;
; f3\id = id
;
; f3\a(id)\x = vt(id_vtx1)\x
; f3\a(id)\y = vt(id_vtx1)\y
; f3\a(id)\z = vt(id_vtx1)\z
; f3\b(id)\x = vt(id_vtx2)\x
; f3\b(id)\y = vt(id_vtx2)\y
; f3\b(id)\z = vt(id_vtx2)\z
; f3\c(id)\x = vt(id_vtx3)\x
; f3\c(id)\y = vt(id_vtx3)\y
; f3\c(id)\z = vt(id_vtx3)\z
;
; EndProcedure
;
; Procedure Face_id_quad(id.i, id_vtx1.i, id_vtx2.i, id_vtx3.i, id_vtx4.i)
; Shared f4.Face_quad
;
;
; EndProcedure
;
; Procedure Draw_Face_tris()
; Shared f3.Face_tris
; Shared n.Vec3
; Protected.i id, size
;
;
; size = ArraySize(f3\a())
;
; glColor3f_(1,1,1)
; glBegin_(#GL_TRIANGLES)
;
; For id=0 To size
;
; normal_face(f3\a(id), f3\b(id), f3\c(id), @n)
; glNormal3fv_(n)
; glVertex3fv_(f3\a(id))
; glVertex3fv_(f3\b(id))
; glVertex3fv_(f3\c(id))
; Next
;
; glEnd_()
; EndProcedure
;
; Declare getvertex(id.i)
;
; Procedure AddFaceTris(*m.Mouse, *v.Viewport)
; Shared vt.Vec3()
; Shared f3.Face_tris
; Protected.i zone = 5
; Protected.f _x, _y, _z
; Protected.i id_vpt
; Protected.i size, id, it=0
;
; size = ArraySize(vt())
;
; For id=0 To size
;
; gluProject_(vt(id)\x, vt(id)\y, vt(id)\z, *v\model(), *v\proj(), *v\_viewport(), @_x, @_y, @_z)
;
; If _x < *m\x+zone And _x > *m\x-zone And _y < *m\y+zone And _y > *m\y-zone
;
; If vt(id)\is_Select <> 1
;
; vt(id)\is_Select = 1
;
; If f3\cmpFace = 0
;
; f3\tmpFace(0) = vt(id)\id
; f3\cmpface = f3\cmpface + 1
; ProcedureReturn
;
; ElseIf f3\cmpFace = 1
;
; f3\tmpFace(1) = vt(id)\id
; f3\cmpFace = f3\cmpface + 1
; ProcedureReturn
;
; ElseIf f3\cmpFace = 2
;
; f3\tmpFace(2) = vt(id)\id
; Face_id_tris(it, GetVertex(f3\tmpFace(0)), GetVertex(f3\tmpFace(1)), GetVertex(f3\tmpFace(2)))
; it = it+1
; f3\cmpFace=0
; DeSelectAllVertex()
; ProcedureReturn
; EndIf
; EndIf
; EndIf
; Next
;
; EndProcedure
;
; Procedure.i getvertex(id.i)
;
; Shared vt.Vec3()
; Protected.i it, size
;
; size = ArraySize(vt())
;
; For it=0 To size
; If vt(it)\id = id
; ProcedureReturn vt(it)\id
; EndIf
; Next
; EndProcedure
;
; Procedure AnnuleFace()
; Shared f3.Face_tris
; f3\cmpFace = 0
; EndProcedure
;
; Procedure DeleteFace()
; Shared f3.Face_tris
; Protected.i i, check_face
;
; AnnuleFace()
;
; check_face = f3\id
;
; For i=0 To check_face
;
; If f3\a(i)\is_Select = 1 Or f3\b(i)\is_Select = 1 Or f3\c(i)\is_Select = 1
;
; DeleteArrayElement(f3\a, f3\a(i)\id)
; DeleteArrayElement(f3\b, f3\b(i)\id)
; DeleteArrayElement(f3\c, f3\c(i)\id)
;
; Continue
; EndIf
; Next
; EndProcedure
;
; Procedure Lathe()
; EndProcedure
;
; Procedure drawaxes()
; glPushMatrix_()
; ; glDisable(GL_LIGHTING)
;
; glBegin_(#GL_LINE_STRIP)
; glColor3ub_(255, 0, 0)
; glVertex3f_(0.0, 0.0, 0.0)
; glVertex3f_(10.0, 0.0, 0.0)
; glVertex3f_(7.5, 2.5, 0.0)
; glVertex3f_(7.5, -2.5, 0.0)
; glVertex3f_(10.0, 0.0, 0.0)
; glVertex3f_(10.0, 0.0, 0.0)
; glEnd_()
; glBegin_(#GL_LINE_STRIP)
; glVertex3f_(0.0, 0.0, 0.0)
; glVertex3f_(0.0, 10.0, 0.0)
; glVertex3f_(0.0, 10.0, 0.0)
; glVertex3f_(2.5, 7.5, 0.0)
; glVertex3f_(-2.5, 7.5, 0.0)
; glVertex3f_(0.0, 10.0, 0.0)
; glEnd_()
; glBegin_(#GL_LINE_STRIP);
; glVertex3f_(0.0, 0.0, 0.0)
; glVertex3f_(0.0, 0.0, 10.0)
; glVertex3f_(2.5, 0.0, 7.5)
; glVertex3f_(-2.5, 0.0, 7.5)
; glVertex3f_(0.0, 0.0, 10.0)
; glVertex3f_(0.0, 0.0, 10.0)
; glEnd_()
;
; ; glEnable(GL_LIGHTING)
; glColor3f_(1, 1, 1)
;
; glPopMatrix_()
; EndProcedure
Procedure v_sys_init(_w.i, _h.i)
Shared my_w.my_win
my_w\w = _w
my_w\h = _h
; zoominview0(10)
; setviewport0( 0, my_w\h/2, my_w\w/2, my_w\h/2, 0, 0, 0)
; loadviewport0()
;
; zoominview1(10)
; setviewport1( my_w\w/2 , my_w\h/2 , my_w\w/2, my_w\h/2, 0, 0, 0)
; loadviewport1()
;setrotview(0,0,0)
; zoominview(0,10)
; setviewport2(0, 0, 0, my_w\w, my_w\h, my_w\w/2, my_w\h/2, 0)
; ;LoadOrtho()
; loadviewport(0)
zoominview(0,10)
setviewport_persp(0, 0, my_w\h/2, my_w\w/2, my_w\h/2, 0, 0, 0)
loadviewport(0)
;loadviewport(1)
;setrotview(1,1,90)
; zoominview(1,10)
; setviewport_ortho(1, my_w\w/2 , my_w\h/2 , my_w\w/2, my_w\h/2, 0, 0, 0)
; loadviewport(1)
; ; setrotview(2,0,0)
; ;
; zoominview(3,10)
; setviewport_ortho(3, my_w\w/2 , 0, my_w\w/2, my_w\h/2, 0, 0, 0)
; loadviewport(3)
; ;setrotview(3,0,-90)
; ;
; zoominview(4,10)
; setviewport_ortho(4 , 0, 0, my_w\w/2, my_w\h/2, 0, 0, 0)
; loadviewport(4)
; ;setrotview(4,0,-45)
; ; setrotview(4,1,45)
;
;zoominview(0,10)
; zoominview(2,10)
; zoominview(3,10)
; zoominview(4,10)
;
EndProcedure
Procedure init_Engine_CAD(x.i, y.i)
OpenWindow(0,0,0,#Width/DesktopResolutionX(),#Height/DesktopResolutionY()+100,"PureCAD", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, #Width, #Height+32)
;AddWindowTimer(0, #myTimer_Render, 15)
ButtonGadget(#button_add_vertex,0,#Height-235,100,24,"add vertex")
ButtonGadget(#button_add_face,100,#Height-235,100,24,"add face")
ButtonGadget(#button_remove_vertex,200,#Height-235,100,24,"remove vertex")
ButtonGadget(#button_remove_face,300,#Height-235,100,24,"remove face")
ButtonGadget(#button_draw_lathe,400,#Height-235,100,24,"draw lathe")
ButtonGadget(#button_clear_lathe,500,#Height-235,100,24,"clear lathe")
ButtonGadget(#button_opengl_flat,600,#Height-235,100,24,"flat")
ButtonGadget(#button_opengl_smooth,0,#Height-210,100,24,"Smooth")
EndProcedure
; Procedure draw_objects()
; glColor3f_(0,0,0)
; Draw_Face_tris()
; glDisable_(#GL_LIGHTING)
;
; glPointSize_(3)
; draw_vertex()
; glPointSize_(1)
; EndProcedure
Procedure Engine_CAD()
;add_vertex(@ms, viewtb())
draw_vertex()
EndProcedure
Procedure draw_point()
glist = glGenLists_(1)
glNewList_(glist, #GL_COMPILE_AND_EXECUTE)
glPointSize_(30)
; If MouseButton(#PB_MouseButton_Left)
; ms\Left=#True
; EndIf
If ms\Left = #True
glBegin_(#GL_POINTS)
glColor3f_(1,0,0)
glVertex3f_(ms\x, ms\y, 0)
glEnd_()
EndIf
glPointSize_(30)
glEndList_()
EndProcedure
Procedure draw_cube()
glist = glGenLists_(1)
glNewList_(glist, #GL_COMPILE_AND_EXECUTE)
;glPointSize_(30)
If MouseButton(#PB_MouseButton_Left)
ms\Left=#True
EndIf
; If ms\Left = #True
glBegin_(#GL_QUADS)
glColor3f_(0.3, 0.3, 1.0)
glNormal3f_( 0.0, 0.0, 1.0)
glVertex3f_( 0.5, 0.5, 0.5)
glVertex3f_(-0.5, 0.5, 0.5)
glVertex3f_(-0.5,-0.5, 0.5)
glVertex3f_( 0.5,-0.5, 0.5)
glNormal3f_( 0.0, 0.0,-1.0)
glVertex3f_(-0.5,-0.5,-0.5)
glVertex3f_(-0.5, 0.5,-0.5)
glVertex3f_( 0.5, 0.5,-0.5)
glVertex3f_( 0.5,-0.5,-0.5)
glNormal3f_( 0.0, 1.0, 0.0)
glVertex3f_( 0.5, 0.5, 0.5)
glVertex3f_( 0.5, 0.5,-0.5)
glVertex3f_(-0.5, 0.5,-0.5)
glVertex3f_(-0.5, 0.5, 0.5)
glNormal3f_( 0.0,-1.0, 0.0)
glVertex3f_(-0.5,-0.5,-0.5)
glVertex3f_( 0.5,-0.5,-0.5)
glVertex3f_( 0.5,-0.5, 0.5)
glVertex3f_(-0.5,-0.5, 0.5)
glNormal3f_( 1.0, 0.0, 0.0)
glVertex3f_( 0.5, 0.5, 0.5)
glVertex3f_( 0.5,-0.5, 0.5)
glVertex3f_( 0.5,-0.5,-0.5)
glVertex3f_( 0.5, 0.5,-0.5)
glNormal3f_(-1.0, 0.0, 0.0)
glVertex3f_(-0.5,-0.5,-0.5)
glVertex3f_(-0.5,-0.5, 0.5)
glVertex3f_(-0.5, 0.5, 0.5)
glVertex3f_(-0.5, 0.5,-0.5)
glEnd_()
glTranslatef_(1/4,1/4,0)
glRotatef_(1.0, 0.5, 1.0, 0.2)
glTranslatef_(-1/4,-1/4,0)
;EndIf
;ms\Left=#False
glEndList_()
EndProcedure
Procedure my_Circle(X, Y)
Protected.i n
Protected.f cx, cy
For n=0 To 360
cx = 3 * Cos(n)
cy= 3 * Sin(n)
Plot(cx+X,cy+Y,RGB(255,0,0))
Next
EndProcedure
Define Event, Exit, time.i, quit
init_Engine_CAD(1024, 768+32)
SetFrameRate(30)
;Engine_CAD()
Global xm, ym
Repeat
glClearColor_(0.6, 0.6, 0.6, 1.0) ; background color
glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
v_sys_init(1024, 768+32)
glEnable_(#GL_LIGHT0)
glEnable_(#GL_LIGHTING)
glEnable_(#GL_COLOR_MATERIAL)
glEnable_(#GL_DEPTH_TEST)
glEnable_(#GL_CULL_FACE)
Repeat
event = WindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case #button_add_vertex
Case #button_add_face
Case #button_remove_vertex
Case #button_remove_face
Case #button_opengl_flat
Case #button_draw_lathe
Case #button_clear_lathe
Case #button_opengl_smooth
; Case #my_GL
; ms\x = GetGadgetAttribute(#my_GL, #PB_OpenGL_MouseX) : ms\y = GetGadgetAttribute(#my_GL, #PB_OpenGL_MouseY)
; Select EventType()
; Case #PB_EventType_LeftButtonDown
; ms\Left = #True
;
; ;add_vertex(@ms, viewtb())
; ;draw_vertex()
; ; Case #PB_EventType_LeftButtonUp
; ; ms\Left = #False
; EndSelect
EndSelect
Case #PB_Event_CloseWindow
quit = 1
Select EventType()
Case #PB_EventType_LeftButtonDown
ms\Left = #True
;add_vertex(@ms, viewtb())
;draw_vertex()
; Case #PB_EventType_LeftButtonUp
; ms\Left = #False
EndSelect
EndSelect
Until event = 0
;ClearScreen(RGB(0,0,0))
; ExamineMouse()
; xm = MouseX() ; Position en x de la souris
; ym = MouseY() ; Position en y de la souris
;
;
; StartDrawing(ScreenOutput())
; If xm < 3
; xm = 3
; Else
; If xm >750
; xm = 750
; EndIf
; EndIf
;
; If ym < 3
; ym = 3
; Else
; If ym > 768+100-5
; ym = 768+100-5
; EndIf
; EndIf
; my_Circle(xm, ym)
; StopDrawing()
; ms\x = MouseX()
; ms\y = MouseY()
draw_cube()
glFinish_()
FlipBuffers()
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape) Or quit = 1

See you soon

PS : @marc_256 you will love this and say me what do you think of that ?
