hello everybody...im trying to load several same 3d model into my application...these are the outline of what i want to do:
user push keyboard button [m] ----->the user went into the mode for loading the model...
if mouse left button is click then
the 3d model is load
endif
the user push again keyboard button [m] ------>the user left the mode...
need some idea on how to code this....
I can't think of any reason to load 3d object files other than pre-loading them at the start and then switching.
As matchy said, don't load it when the user says "NOW!" - preload it and use a flag to determine whether it is SHOWN or not.
fMarked%=false
main:
if keypressed
fMarked = true
showcross
endif
{other main loop code}
goto main
If you want to display multiple copies of the 3D object, then use an array of x,y,z co-ordinates (and arrays for scaling and rotation, perhaps) and a variable that indicates how many crosses the user has placed (so instead of fMarked% you would have something like numMarks%, starting at 0 when there are none to display).
Actually come to think of it, .dda files are text files which can be modified (by other programs or itself) and loaded during run time. ;) :whistle:
if you want dynamic objects, you can create them with X_OBJSTART in code. You can also X_OBJSAVE that result then.
there is no constraint on how many the user can put the cross..so how can i preload it so that i there wont be any limit?
To have quick switching, there are two ways to pre-load (for non dynamic objects):
1. Load each object id in to an array and change the object.
_OR_
2. Create ONE animated .ddd object file with each object in as frame and then change the frame (have not really tried this or different objects).
im a bit lost here....what the difference between non-dynamic and dynamic object?some examples perhaps...
ouhhhh....tq ocean...
I don't think this is an issue and probably confusing because prepared objects are loaded. ::) A dynamic object is when X_STARTOBJ is use again and again on the same object number. So it's really rewriting the points and recreating the object. An perfect example is an waving flag, where the wave can be calculate in the program.
Quote from: mars_chaos89 on 2010-Oct-21
there is no constraint on how many the user can put the cross..so how can i preload it so that i there wont be any limit?
Have an array of X,Y, and Z variables to hold the X,Y and Z locations of x's.
Dimension that array to 0 items.
Have another variable that is the current number of instance sof the "X" model - say "xCount%".
Each time the user says "plaqce another X" you increase xCount% and REDIM the array to add an extra variable.
Each loop around the "Display"/main portion of your code, draw an "X" object in a for-next loop:
draw "plane" at planeX, planeY, planeZ
for nX% = 1 to xCount%
draw "X" at X(nX%), Y(nX%), X(nX%)
next
Really, really simple. and straightforward - an array for x,y,z parameters for n instances of the "X" or "cross" model.
Just to clarify, to display the same object 10 times for example, you don't need to have 10 copies of that object loaded (or dynamically generated). You only need one copy loaded (load it when the program starts).
Then each loop / frame, you use the 'X_MOVEMENT' command to move the 3d cursor to where you want the model, then display it with 'X_DRAWOBJ'. Repeat both of these commands for each instance of the object you want (10 for now, but you can add/delete objects later). Then repeat it all over again next frame. You are using the same model, but displaying it 10 times per frame at different locations. Like a clone.
Store these x,y,z coordinates in an array. And when the user adds a new object instance, just redim the array one larger and store the new coords. The next frame will draw it for you.
i have reach this point...
TYPE coord
x
y
z
ENDTYPE
GLOBAL xmark[] AS coord
DIM xmark[10]
MOUSESTATE x,y,mbl,mbr
xmark.x = x
xmark.y = y
xmark.z = z
// load the x mark
main:
WHILE TRUE
MOUSESTATE x,y,mbl,mbr
// make3ddonut()
make3dmarking(i)
SHOWSCREEN
WEND
END
FUNCTION make3dmarking:m
MOUSESTATE x,y,mbl,mbr
X_MAKE3D 1,10000,45
X_CAMERA 10,0,0, 0,0,0
IF KEY(45)=TRUE //x
dirx=(dirx-KEY(203))
dirx=(dirx+KEY(205))
ENDIF
IF KEY(44)=TRUE //z
dirz=(dirz-KEY(208))
dirz=(dirz+KEY(200))
ENDIF
IF KEY(21)=TRUE //y
diry=(diry+KEY(200))
diry=(diry-KEY(208))
ENDIF
X_MOVEMENT dirz, diry, dirx
IF mbl=TRUE
X_SCREEN2WORLD x,y,0, wx,wy,wz
ENDIF
X_MOVEMENT wx,wy,wz
X_SCALING 0.04,0.04,0.04
X_ROTATION 90, 0,1,0
X_DRAWOBJ m,0
X_MAKE2D
PRINT "xmark(1) : x ="+ wx + " , y ="+ wy + " , z ="+ wz, 100,200
ENDFUNCTION
at the moment i try to draw 10 'x' that why the dimension is 10....
let say i want to use just a constraint first rather than jumping directly to what i have plan for my application...
so i just try to make the xmark is drawn only when the "m" button is pressed...so i have tried :
a)
if key(50)=true
make3dmarking(n)
endif
this command work but the xmark only appear when the "m" button is pressed and hold...if the we release the button, the xmark will disappear...so there will only be 1 'x'..
b)
if key(50)= true
i=i+1
endif
make3dmarking(i)
i execute this but nothing appeared...
this is as far i get right now...im still trying...
mars_chaos89, use a code box for posting your code! :'(
// --------------------------------- //
// Project: 3dselection example
// Start: Monday, October 25, 2010
// IDE Version: 8.125
// Multiple object selection - spacebar to cycle, arrows to rotate
TYPE shapes
x
y
z
angle_x
angle_y
angle_z
scale
object
ENDTYPE
GLOBAL shape[] AS shapes, shape_select, shape_select_last
GLOBAL OBJ_SPHERE, OBJ_CUBE, OBJ_PLANK
GLOBAL cam_x, cam_y, cam_z, cam_px, cam_py, cam_pz //,mouse_x, mouse_y, button_left, button_right,
CONSTANT KEY_SPACE=57
CONSTANT KEY_X=45
CONSTANT KEY_Y=21
CONSTANT KEY_Z=44
CONSTANT KEY_LEFT=203
CONSTANT KEY_RIGHT=205
CONSTANT KEY_UP=200
CONSTANT KEY_DOWN=208
init()
FUNCTION init:
init_obj()
animate_scene()
ENDFUNCTION
FUNCTION init_obj:
LOCAL shape_count
OBJ_SPHERE=1 // alt to GEN_XOBJ from X_LOADOBJ
OBJ_CUBE=2
OBJ_PLANK=3
sphere_object(OBJ_SPHERE, 0.0, 0.0, 0.0, 1.0, 8)
cube_object(OBJ_CUBE, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0)
cube_object(OBJ_CUBE, 0.0, 0.0, 0.0, 2.0, 4.0, 0.5)
// create array to object type (of 3 above) and position
FOR shape_count=0 TO 20
shape_add( RND(3)+1 , RND(6)-3, RND(6)-3, RND(6)-3 )
NEXT
cam_x=1
cam_y=5
cam_z=-20
cam_px=0
cam_py=0
cam_pz=0
ENDFUNCTION
FUNCTION shape_add: object, x,y,z
LOCAL shape_count
shape_count=BOUNDS(shape[],0)
REDIM shape[shape_count+1]
shape[shape_count].object=object // genrated object num
shape[shape_count].x=x
shape[shape_count].y=y
shape[shape_count].z=z
shape[shape_count].scale=1.0
ENDFUNCTION
FUNCTION animate_scene:
WHILE TRUE
input_calc()
set_3d(); draw_3d_shapes()
X_MAKE2D; draw_2d_text()
SHOWSCREEN
WEND
ENDFUNCTION
FUNCTION draw_2d_text:
PRINT shape_select, 10,10
ENDFUNCTION
FUNCTION draw_3d_shapes:
FOREACH shp IN shape[]
X_MOVEMENT shp.x,shp.y,shp.z
X_SCALING shp.scale,shp.scale,shp.scale
X_ROTATION shp.angle_x, 1,0,0
X_ROTATION shp.angle_y, 0,1,0
X_ROTATION shp.angle_z, 0,0,1
//if other shp.condition
// X_drawobj another_object, or frame
//else
X_DRAWOBJ shp.object, 0
NEXT
ENDFUNCTION
FUNCTION set_3d:
X_MAKE3D 0.01,100, 45
X_CAMERA cam_x,cam_y,cam_z, cam_px,cam_py,cam_pz
X_AMBIENT_LT 1,RGB(255,255,255)
ENDFUNCTION
FUNCTION input_calc:
// MOUSESTATE mouse_x,mouse_y,button_left,button_right;
IF KEY(KEY_SPACE)
shape[shape_select].scale=1.0
INC shape_select
IF shape_select>BOUNDS(shape[],0)-1
shape_select=0
ENDIF
ENDIF
shape[shape_select].scale=SIN(GETTIMERALL()/10)+2
// IF KEY(KEY_X)
IF KEY(KEY_LEFT)
DEC shape[shape_select].angle_x
ENDIF
IF KEY(KEY_RIGHT)
INC shape[shape_select].angle_x
ENDIF
// ENDIF
// IF KEY(KEY_Y)
IF KEY(KEY_UP)
DEC shape[shape_select].angle_y
ENDIF
IF KEY(KEY_DOWN)
INC shape[shape_select].angle_y
ENDIF
// ENDIF
IF KEY(KEY_Z)
IF KEY(KEY_UP)
DEC shape[shape_select].angle_z
ENDIF
IF KEY(KEY_DOWN)
INC shape[shape_select].angle_z
ENDIF
ENDIF
ENDFUNCTION
FUNCTION cube_object: obj, x,y,z, w,h,l
LOCAL col
col=RGB(255,255,255)
w=w/2
h=h/2
l=l/2
X_OBJSTART obj
X_OBJADDVERTEX x-l, y+h, z+w, 0, 0, col
X_OBJADDVERTEX x+l, y+h, z+w, 1, 0, col
X_OBJADDVERTEX x-l, y-h, z+w, 0, 1, col
X_OBJADDVERTEX x+l, y-h, z+w, 1, 1, col
X_OBJNEWGROUP
X_OBJADDVERTEX x+l, y+h, z-w, 0, 0, col
X_OBJADDVERTEX x-l, y+h, z-w, 1, 0, col
X_OBJADDVERTEX x+l, y-h, z-w, 0, 1, col
X_OBJADDVERTEX x-l, y-h, z-w, 1, 1, col
X_OBJNEWGROUP
X_OBJADDVERTEX x-l, y+h, z+w, 0, 0, col
X_OBJADDVERTEX x-l, y+h, z-w, 1, 0, col
X_OBJADDVERTEX x+l, y+h, z+w, 0, 1, col
X_OBJADDVERTEX x+l, y+h, z-w, 1, 1, col
X_OBJNEWGROUP
X_OBJADDVERTEX x-l, y-h, z-w, 1, 1, col
X_OBJADDVERTEX x-l, y-h, z+w, 0, 1, col
X_OBJADDVERTEX x+l, y-h, z-w, 1, 0, col
X_OBJADDVERTEX x+l, y-h, z+w, 0, 0, col
X_OBJNEWGROUP
X_OBJADDVERTEX x+l, y-h, z-w, 1, 1, col
X_OBJADDVERTEX x+l, y-h, z+w, 0, 1, col
X_OBJADDVERTEX x+l, y+h, z-w, 1, 0, col
X_OBJADDVERTEX x+l, y+h, z+w, 0, 0, col
X_OBJNEWGROUP
X_OBJADDVERTEX x-l, y-h, z+w, 1, 1, col
X_OBJADDVERTEX x-l, y-h, z-w, 0, 1, col
X_OBJADDVERTEX x-l, y+h, z+w, 1, 0, col
X_OBJADDVERTEX x-l, y+h, z-w, 0, 0, col
X_OBJNEWGROUP
X_OBJEND
ENDFUNCTION
FUNCTION sphere_object: num, x,y,z, r, n
LOCAL col, i,j, theta1, theta2, theta3, pi
col=RGB(255,255,255)
pi = ACOS(0)*2
IF r < 0 THEN r = -r
IF n < 3 THEN n = 3
X_OBJSTART num
FOR j=0 TO n/2-1
theta1 = j * 2*pi / n - pi/2;
theta2 = (j + 1) * 2*pi / n - pi/2;
FOR i=0 TO n
theta3 = i * 2*pi / n;
X_OBJADDVERTEX (r*COS(theta2)*COS(theta3))+x, r*SIN(theta2)+y, (r*COS(theta2)*SIN(theta3))+z, i/n, 2*(j+1)/n, col
X_OBJADDVERTEX (r*COS(theta1)*COS(theta3))+x, r*SIN(theta1)+y, (r*COS(theta1)*SIN(theta3))+z, i/n, 2*(j+0)/n, col
NEXT
X_OBJNEWGROUP
NEXT
X_OBJEND
ENDFUNCTION
sorry..i dont know how to use it
i have reach this point...
TYPE coord
x
y
z
ENDTYPE
GLOBAL xmark[] AS coord
DIM xmark[10]
MOUSESTATE x,y,mbl,mbr
xmark.x = x
xmark.y = y
xmark.z = z
// load the x mark
main:
WHILE TRUE
MOUSESTATE x,y,mbl,mbr
// make3ddonut()
make3dmarking(i)
SHOWSCREEN
WEND
END
FUNCTION make3dmarking:m
MOUSESTATE x,y,mbl,mbr
X_MAKE3D 1,10000,45
X_CAMERA 10,0,0, 0,0,0
IF KEY(45)=TRUE //x
dirx=(dirx-KEY(203))
dirx=(dirx+KEY(205))
ENDIF
IF KEY(44)=TRUE //z
dirz=(dirz-KEY(208))
dirz=(dirz+KEY(200))
ENDIF
IF KEY(21)=TRUE //y
diry=(diry+KEY(200))
diry=(diry-KEY(208))
ENDIF
X_MOVEMENT dirz, diry, dirx
IF mbl=TRUE
X_SCREEN2WORLD x,y,0, wx,wy,wz
ENDIF
X_MOVEMENT wx,wy,wz
X_SCALING 0.04,0.04,0.04
X_ROTATION 90, 0,1,0
X_DRAWOBJ m,0
X_MAKE2D
PRINT "xmark(1) : x ="+ wx + " , y ="+ wy + " , z ="+ wz, 100,200
ENDFUNCTION
at the moment i try to draw 10 'x' that why the dimension is 10....
let say i want to use just a constraint first rather than jumping directly to what i have plan for my application...
so i just try to make the xmark is drawn only when the "m" button is pressed...so i have tried :
a)
if key(50)=true
make3dmarking(n)
endif
this command work but the xmark only appear when the "m" button is pressed and hold...if the we release the button, the xmark will disappear...so there will only be 1 'x'..
b)
if key(50)= true
i=i+1
endif
make3dmarking(i)
i execute this but nothing appeared...
this is as far i get right now...im still trying...any help?
mars_chaos89, I wrote that code for you mate. Tell me you missed it!
i hav try execute the code..but it some error occur....
CONSTANT KEY_SPACE=57
CONSTANT KEY_X=45
CONSTANT KEY_Y=21
CONSTANT KEY_Z=44
CONSTANT KEY_LEFT=203
CONSTANT KEY_RIGHT=205
CONSTANT KEY_UP=200
CONSTANT KEY_DOWN=208
ti show that the error is here.....
That's odd. Please post the error!
"3d selection.gbas"(23) error : syntax error
this is the error....
CONSTANT seems to work fine with compiling with me. Besides, they only declare the key-codes and is irrelevant to the issue. By now you should have changed them to GLOBAL for now.
I've attached the project source with an exe: ;)
[attachment deleted by admin]
i have changed it but something else happen...
C:\DOCUME~1\CBM\LOCALS~1\Temp\glbasic\gpc_temp0.cpp: In function `DGInt __GLBASIC__::input_calc()':
C:\DOCUME~1\CBM\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:363: error: no matching function for call to `INC(DGInt&)'
C:\DOCUME~1\CBM\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:394: error: no matching function for call to `DEC(DGInt&)'
C:\DOCUME~1\CBM\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:407: error: no matching function for call to `INC(DGInt&)'
C:\DOCUME~1\CBM\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:422: error: no matching function for call to `DEC(DGInt&)'
C:\DOCUME~1\CBM\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:435: error: no matching function for call to `INC(DGInt&)'
C:\DOCUME~1\CBM\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:454: error: no matching function for call to `DEC(DGInt&)'
C:\DOCUME~1\CBM\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:467: error: no matching function for call to `INC(DGInt&)'
this error come up..
i also have see what your program do...but that not exactly what i want to do...
SYSTEMPOINTER TRUE
SETSCREEN 900,700,TRUE
TYPE coord
x
y
z
ENDTYPE
GLOBAL xmark[] AS coord
DIM xmark[10]
MOUSESTATE x,y,mbl,mbr
xmark[i].x = x
xmark[i].y = y
xmark[i].z = z
n=0
LOADSPRITE "../../3d viewer v2/3d viewer v2.app/donut.bmp", 1
X_LOADOBJ "../../3d viewer v2/3d viewer v2.app/donut.ddd", 1
X_LOADOBJ "../xmark.ddd",m
main:
WHILE TRUE
MOUSESTATE x,y,mbl,mbr
// make3ddonut()
make3dmarking(n)
GETSCREENSIZE width,height
centerx = width/2
centery = height/2
PRINT "x="+ x, 100,100
PRINT "y="+ y, 100,120
PRINT "width ="+ width, 100,140
PRINT "height ="+ height, 100,160
PRINT "center point = "+ centerx + " , " + centery, 100,180
PRINT "xmark(" + m +") : x ="+ xmark[m].x + " , y ="+ xmark[m].y + " , z ="+ xmark[m].z, 100,220
SHOWSCREEN
WEND
END
FUNCTION make3dmarking:m
MOUSESTATE x,y,mbl,mbr
X_MAKE3D 1,10000,45
X_CAMERA 10,0,0, 0,0,0
IF KEY(45)=TRUE //x
dirx=(dirx-KEY(203))
dirx=(dirx+KEY(205))
ENDIF
IF KEY(44)=TRUE //z
dirz=(dirz-KEY(208))
dirz=(dirz+KEY(200))
ENDIF
IF KEY(21)=TRUE //y
diry=(diry+KEY(200))
diry=(diry-KEY(208))
ENDIF
X_MOVEMENT dirz, diry, dirx
IF mbl=TRUE
X_SCREEN2WORLD x,y,0, wx,wy,wz
xmark[m].x=wx
xmark[m].y=wy
xmark[m].z=wz
ENDIF
X_MOVEMENT wx,wy,wz
X_SCALING 0.04,0.04,0.04
X_ROTATION 90, 0,1,0
X_DRAWOBJ m,0
X_MAKE2D
PRINT "xmark(1) : x ="+ wx + " , y ="+ wy + " , z ="+ wz, 100,200
//PRINT "xmark(" + m +") : x ="+ xmark[m].x + " , y ="+ xmark[m].y + " , z ="+ xmark[m].z, 100,220
ENDFUNCTION
FUNCTION make3ddonut:
INC phi, MOUSEAXIS(0)
X_MAKE3D 1,10000,45
X_CAMERA 10,0,0, 0,0,0
X_SCALING 0.1,0.1,0.1
X_ROTATION phi, 0,1,0
X_SETTEXTURE 1, -1
X_DRAWOBJ 1,0
ENDFUNCTION
this is my full code...what i want to do is put the 'x' mark on that donut model as many as we want...and save it...
[attachment deleted by admin]
At http://www.glbasic.com/forum/index.php?topic=4738.msg35786#msg35786 there's a really helpful post about a flow diagram program (free!) which might help find where the problem in your logic is. I'm stuck on a netbook at the moment which is not the very best for studying someone else's code on :( but based on previous posts it looks like you're not fully "getting" the way you need to pull the 3D model, the concept of an array of marker positions, the keypresses, and a disply loop (that displays the aircraft/doughnut, all previous X marks, and the current "floating" X mark) together.
I doubt I could draw a good chart using this screen either, but here's my thoughts in a "level at a time" manner.
First you have to decalre all your variables and set them to useful/default values.
In the outside / main loop you should display your main model. If any X's have been set you should display those. If an X has been activated but not fixed in place you should display it (differently to fixed X's IMHO).
Within the loop, either before or after displaying, you should check for keypresses. If the key is "make an X" then increase the number of X's, set the initial position of the new X.
ELSE If the key is a "move X" key then change the position of the current/last X mark.
ELSE If the key is a "set X position" then deal with that event (may be the same as the "create new X key, in which case this doesn't need writing).
ELSE If the key is a camera movement key then move the camera.
At the moment, although this may be partly because I can see so little code at a time on this tiny screen, I can't see how you are displaying all the pre-set X's as you think about setting a new one. Apologies if it's all present and correct and I am just failing to see it :(
A flowchart might be easier to study, and might enlighten you as to where things are going wrong as you create the chart anyway :D