Jump to content


Photo

movement 3D


  • Please log in to reply
3 replies to this topic

#1 marfin201

marfin201

    GMC Member

  • New Member
  • 170 posts
  • Version:GM8

Posted 01 July 2012 - 03:37 PM

Ok, everyone I have the code like this in create event for obj_player
z = 10;
camdirection = direction;
camzdirection = 0;
zdirection = 0;

draw_set_color(c_white);

d3d_start();
display_mouse_set(display_get_width()/2,display_get_height()/2);
and in step event
camdirection -= (display_get_width()/2-display_mouse_get_x()); 
camzdirection += (display_get_height()/2-display_mouse_get_y());
display_mouse_set(display_get_width()/2,display_get_height()/2);
draw event
distance = 50;
d3d_set_projection (
x-cos(degtorad(camdirection))*cos(degtorad(camzdirection))*distance,
y+sin(degtorad(camdirection))*cos(degtorad(camzdirection))*distance,
z+sin(degtorad(camzdirection))*distance,
x,y,z,
0,0,1);
d3d_transform_add_rotation_z(direction);
d3d_transform_add_translation(x,y,z);
d3d_draw_ellipsoid(10, 10, -10, -10,-10,10, (b_player) ,1,1,20);
d3d_transform_set_identity();
And my question,, is same as my title.
So, can anyone help me ??

EDIT ::
Sorry if my English is bad,,
Ok,, how I can make the object is moving in 3D game,, to front, to back, to right, to left....????

Edited by marfin201, 02 July 2012 - 03:11 AM.

  • 0

#2 Tepi

Tepi

    GMC Member

  • Global Moderators
  • 4201 posts
  • Version:GM8.1

Posted 01 July 2012 - 07:19 PM

your topic title, in fact, does not contain a question.

Please post it quick before I close this topic...
  • 0

#3 marfin201

marfin201

    GMC Member

  • New Member
  • 170 posts
  • Version:GM8

Posted 02 July 2012 - 03:01 AM

Really ?
Ok, I was wondering about how to make object moving to front, right, back, and left like pacman 3D.....
And that's actually I want to ask about...
Could you help ?? or anyone ??
  • 0

#4 Qon

Qon

    GMC Member

  • GMC Member
  • 85 posts

Posted 17 July 2012 - 05:54 AM

from your code:
cos(degtorad(camdirection))*cos(degtorad(camzdirection))*distance
-sin(degtorad(camdirection))*cos(degtorad(camzdirection))*distance
-sin(degtorad(camzdirection))*distance

This is the vector you've calculated for the camera direction. Use this as the vector for movement also.

When you say "forward,back,left,right" do you mean the directions in the "ground plane" or the "camera plane"? If it's in the ground plane just leave out *cos(degtorad(camzdirection))
and set the z vector component to 0.

Qam.xt yt zt is the camera forward vector
xr = Qam.yt
yr = -Qam.xt //xr and yr is given by the cross product of the vector (xt,yt,zt) and the vector (0,0,1). It is the vector pointing to the right. zr=0/not used since your up vector is ALWAYS (0,0,1)
QF=cos(dirmod)
QR=sin(dirmod)
x+=(Qam.xt*QF-xr*QR)*movespeed
y+=(Qam.yt*QF-yr*QR)*movespeed
z+=(Qam.zt*QF)*acc //this line will make your camera move up/down when you go forward/backward while looking up/down
not tested as written above, but this is taken from my working engine and I stripped out stuff that is too complex for your case, so it should work fine.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users