bignono
Number of posts : 11 Age : 66 Localisation : Champigny-sur-Marne, 94500, France Registration date : 2013-03-12
| Subject: how to move in a scene in 3D Wed Mar 13, 2013 9:15 pm | |
| Hello with all, Today, I give you a code to move in a world in 3D. All the orders are explained at the beginning of program in remarks. I hope that this code will be useful to those which is interested in the 3D. As I am French, and that I do not speak English, I used the translator babylon online. Please excuse the bad translation. I thus tried to translate all the remarks and explanations which you will find in this program. So long perhaps… - Code:
-
' ****************************************************************************** ' ****************************** ORDERS KEYBOARD ******************************* ' ****************************************************************************** dim esc :' * KEY ESC ==> END PROGRAM:............................... CASE 27 * dim tpu :' * KEY "page up" ==> TO GO UP (air vision):............... CASE 33 * dim tpd :' * KEY "page down" ==> TO GO DOWN (vision aérienne):...... CASE 34 * dim tfg :' * KEY LEFT ARROW ==> TO TURN LEFT:....................... CASE 37 * dim tfh :' * KEY HIGHT ARROW ==> TO PROGRESS:....................... CASE 38 * dim tfd :' * KEY RIGHT ARROW ==> TO TURN RIGHT:..................... CASE 39 * dim tfb :' * KEY LOW ARROW ==> TO BACK:............................. CASE 40 * dim tcb :' * KEY "B" ==> TO LOOK AT DOWNWARDS:...................... CASE 66 * dim tch :' * KEY "H" ==> TO LOOK AT UPWARDS:........................ CASE 72 * ' ****************************************************************************** ' ****************************** NUMERIC KEYPAD ******************************** ' ****************************************************************************** dim pn1 :' * KEY "1" ==> TO BACK ON THE LEFT:....................... CASE 97 * dim pn2 :' * KEY "2" ==> TO BACK:................................... CASE 98 * dim pn3 :' * KEY "3" ==> TO BACK ON THE RIGHT:...................... CASE 99 * dim pn4 :' * KEY "4" ==> LEFT SIDE DISPLACEMENT:.................... CASE 100 * dim pn5 :' * KEY "5" ==> RETURN ORIGIN:............................. CASE 101 * dim pn6 :' * KEY "6" ==> RIGHT SIDE DISPLACEMENT:................... CASE 102 * dim pn7 :' * KEY "7" ==> TO PROGRESS ON THE LEFT:................... CASE 103 * dim pn8 :' * KEY "8" ==> TO PROGRESS:............................... CASE 104 * dim pn9 :' * KEY "9" ==> TO PROGRESS ON THE RIGHT:.................. CASE 105 * dim pnp :' * KEY "+" ==> TO GO UP:.................................. CASE 107 * dim pnm :' * KEY "-" ==> TO GO DOWN:................................ CASE 109 * ' ****************************************************************************** label t1,t2 on_key_down 0,t1 on_key_up 0,t2
dim rot,chy,phy,bh:rot=180:chy=1.7:phy=1.7 ' rot=angle to which the invisible cube of the engine 3D is, is 3d_y_rotate 1000,rot ' chy=the position Y there of the camera, is cam_y_position ' phy=the position Y there of the point aimed by the camera, is point_y_position label bouge
scene(): ' creation and initialization of the scene
timer 200:timer_interval 200,1:on_timer 200,bouge end
bouge: timer_off 200 deplace() timer_on 200 return
sub deplace() dim_local vrot,vd,vhy,i,mv,pv,x,z,a$,p$ vrot=1:vd=0.2:vhy=0.025:mv=1000:pv=1001 ' vrot=rotation speed when one swivels on the left or on the right (arrows keys left or right) ' vd=rate of travel when one progress, moves back, goes right or on the left ' vhy=climbing speed to go up or go down (keys + or -) ' mv=number object 3D towing vehicle is 1000 (3d_cube 1000,1) ' pv=number object 3D of the point concerned is 1001 (3d_mesh 1001; one can also put a 3d_cube or other, but it should be hidden too) if esc=1 then terminate if tpu=1 if chy<300 then for i=chy to 200 step 05:cam_position o3d_x_position(mv),i,o3d_z_position(mv):display:next i:chy=300 end_if if tpd=1 if chy>phy then for i=200 to phy step -5:cam_position o3d_x_position(mv),i,o3d_z_position(mv):display:next i:chy=phy end_if if tfg=1 then rot=rot+vrot:3d_y_rotate mv,rot if tfd=1 then rot=rot-vrot:3d_y_rotate mv,rot if tfh=1 then 3d_move mv,vd if tfb=1 then 3d_move mv,vd-(2*vd) if tcb=1 then bh=bh+.2:if bh>11 then bh=11 if tch=1 then bh=bh-.2:if bh<-11 then bh=-11 if pn1=1 then 3d_move mv,vd-(2*vd):3d_x_position mv,o3d_x_position(mv)+(cos(rot*3.1415/180)*vd):3d_z_position mv,o3d_z_position(mv)-(sin(rot*3.1415/180)*vd) if pn2=1 then 3d_move mv,vd-(2*vd) if pn3=1 then 3d_move mv,vd-(2*vd):3d_x_position mv,o3d_x_position(mv)-(cos(rot*3.1415/180)*vd):3d_z_position mv,o3d_z_position(mv)+(sin(rot*3.1415/180)*vd) if pn4=1 then 3d_x_position mv,o3d_x_position(mv)+(cos(rot*3.1415/180)*(vd*2)):3d_z_position mv,o3d_z_position(mv)-(sin(rot*3.1415/180)*(vd*2)) if pn5=1 then bh=0:rot=180:chy=1.7:phy=1.7:3d_position mv,0,chy,0:3d_y_rotate mv,rot:3d_move mv,-13 if pn6=1 then 3d_x_position mv,o3d_x_position(mv)-(cos(rot*3.1415/180)*(vd*2)):3d_z_position mv,o3d_z_position(mv)+(sin(rot*3.1415/180)*(vd*2)) if pn7=1 then 3d_move mv,vd:3d_x_position mv,o3d_x_position(mv)+(cos(rot*3.1415/180)*vd):3d_z_position mv,o3d_z_position(mv)-(sin(rot*3.1415/180)*vd) if pn8=1 then 3d_move mv,vd if pn9=1 then 3d_move mv,vd:3d_x_position mv,o3d_x_position(mv)-(cos(rot*3.1415/180)*vd):3d_z_position mv,o3d_z_position(mv)+(sin(rot*3.1415/180)*vd) if pnp=1 then phy=phy+vhy:chy=chy+vhy if pnm=1 then phy=phy-vhy:chy=chy-vhy
' after calculations following the support on a key, one updates the vision of the scene in 3D 3d_position pv,o3d_x_position(mv),o3d_y_position(mv),o3d_z_position(mv): ' one positions the vehicle not aimed to the new site of the towing vehicle 3d_rotate pv,o3d_x_rotate(mv),o3d_y_rotate(mv),o3d_z_rotate(mv): ' one positions the angle conveys not aimed to the new angle of the towing vehicle 3d_move pv,1:' one moves the vehicle concerned which must always be in front of the camera cam_position o3d_x_position(mv),sin(bh/6.28)+chy,o3d_z_position(mv): ' now, in its turn, the camera positions with the new site of the towing vehicle point_position o3d_x_position(pv),phy,o3d_z_position(pv): ' the new point concerned
' screen display of the positions of X, Y and Z as well as swing angle x=o3d_x_position(mv):z=o3d_z_position(mv) p$="X= "+str$(int(x*100)/100)+" Y= "+str$(int(chy*100)/100)+" Z= "+str$(int(z*100)/100):a$="Angle= "+str$(wrap_value(rot))+"°" 3d_position 27,o3d_x_position(pv),phy+0.3,o3d_z_position(pv):3d_text_change 27,p$ 3d_position 28,o3d_x_position(pv),phy-0.7,o3d_z_position(pv):3d_text_change 28,a$ 3d_rotate 27,o3d_x_rotate(mv),o3d_y_rotate(mv)+180,o3d_z_rotate(mv) 3d_rotate 28,o3d_x_rotate(mv),o3d_y_rotate(mv)+180,o3d_z_rotate(mv) end_sub
' sub of creation of the scene3d sub scene() full_space 0: ' one adjusts the space of the form to all the screen scene3d 1:' a scene in 3D is created hide 1:' it is hiding place so that the creation of the objects inside is faster full_space 1:' one occupies all the space of the form, i.e. all the screen color 1,0,0,200: ' is given him a color (blue)
' creation of the objects of the scene in 3D ' ground of our scene 3d_plane 1 3d_scale 1,40,40,1 3d_x_rotate 1,90 3d_y_position 1,0 3d_color 1,0,150,0
' creation of a wall on the left 3d_box 2,8,3,1 3d_position 2,-8,1.5,-5 3d_y_rotate 2,90
' creation of a sphere on the right with half inserted in the ground 3d_sphere 3,2 3d_position 3,8,0,-4 3d_color 3,255,0,0
' creation of a cone to far 3d_cone 4,10,4 3d_position 4,0,5,-50 3d_color 4,200,200,0
' creation of a cylinder to far behind the camera, therefore invisible at the beginning 3d_cylinder 5,10,3,3 3d_position 5,0,5,52 3d_color 5,0,200,200
' objects of posting of the positions of X and Z as well as swing angle 3d_text 27,"":3d_scale 27,.1,.1,.1:3d_text 28,"":3d_scale 28,.1,.1,.1
' here one creates the towing vehicle of the camera, a cube which one hides 3d_cube 1000,1 3d_y_rotate 1000,rot:3d_move 1000,-13:3d_hide 1000 ' here the vehicle concerned is created: that perhaps a sphere, a cube, etc… (but it should be also hidden 3d_hide 1001) 3d_mesh 1001
show 1 end_sub
t1: if key_down_code=27 then esc=1 if key_down_code=33 then tpu=1 if key_down_code=34 then tpd=1 if key_down_code=37 then tfg=1 if key_down_code=38 then tfh=1 if key_down_code=39 then tfd=1 if key_down_code=40 then tfb=1 if key_down_code=66 then tcb=1 if key_down_code=72 then tch=1 if key_down_code=97 then pn1=1 if key_down_code=98 then pn2=1 if key_down_code=99 then pn3=1 if key_down_code=100 then pn4=1 if key_down_code=101 then pn5=1 if key_down_code=102 then pn6=1 if key_down_code=103 then pn7=1 if key_down_code=104 then pn8=1 if key_down_code=105 then pn9=1 if key_down_code=107 then pnp=1 if key_down_code=109 then pnm=1 return t2: if key_down_code=27 then esc=0 if key_down_code=33 then tpu=0 if key_down_code=34 then tpd=0 if key_down_code=37 then tfg=0 if key_down_code=38 then tfh=0 if key_down_code=39 then tfd=0 if key_down_code=40 then tfb=0 if key_down_code=66 then tcb=0 if key_down_code=72 then tch=0 if key_down_code=97 then pn1=0 if key_down_code=98 then pn2=0 if key_down_code=99 then pn3=0 if key_down_code=100 then pn4=0 if key_down_code=101 then pn5=0 if key_down_code=102 then pn6=0 if key_down_code=103 then pn7=0 if key_down_code=104 then pn8=0 if key_down_code=105 then pn9=0 if key_down_code=107 then pnp=0 if key_down_code=109 then pnm=0 return
| |
|
bignono
Number of posts : 11 Age : 66 Localisation : Champigny-sur-Marne, 94500, France Registration date : 2013-03-12
| Subject: Re: how to move in a scene in 3D Sat Mar 16, 2013 10:20 am | |
| If you do not understand the code, or if you have questions, do not hesitate. This forum is there for that! You can also come to take part on the French forum which is more active. There will be certainly always somebody to answer you. | |
|