some idea would really help me...

Previous topic - Next topic

mars_chaos89

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....
     

matchy

I can't think of any reason to load 3d object files other than pre-loading them at the start and then switching.

Cliff3D

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).

matchy

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:

Kitty Hello

if you want dynamic objects, you can create them with X_OBJSTART in code. You can also X_OBJSAVE that result then.

mars_chaos89

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?

matchy

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).

mars_chaos89

im a bit lost here....what the difference between non-dynamic and dynamic object?some examples perhaps...

mars_chaos89


matchy

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.

Cliff3D

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.

Slydog

#11
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.
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

mars_chaos89

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...
 



matchy

mars_chaos89, use a code box for posting your code!  :'(

Code (glbasic) Select

// --------------------------------- //
// 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

mars_chaos89

sorry..i dont know how to use it