Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (TipmyPip, AndrewAMD), 1,151 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
How to move 3d objects using mouse in real time #200911
04/06/08 04:38
04/06/08 04:38
Joined: Apr 2008
Posts: 15
Oz
T
tex Offline OP
Newbie
tex  Offline OP
Newbie
T

Joined: Apr 2008
Posts: 15
Oz
Hi, I don't think "how to move 3d objects using mouse in real time" has ever been answered in any detail. Lots of code snippets, but nothing comprehensive.

Any ideas?

Re: How to move 3d objects using mouse in real time [Re: tex] #200927
04/06/08 07:32
04/06/08 07:32
Joined: Aug 2005
Posts: 1,558
HK
V
vlau Offline
Serious User
vlau  Offline
Serious User
V

Joined: Aug 2005
Posts: 1,558
HK
The question is "How do you want to move the 3D objects
in real time".

Re: How to move 3d objects using mouse in real time [Re: vlau] #200935
04/06/08 08:51
04/06/08 08:51
Joined: Apr 2008
Posts: 15
Oz
T
tex Offline OP
Newbie
tex  Offline OP
Newbie
T

Joined: Apr 2008
Posts: 15
Oz
I am developing some psychology experiments. I need to be able to pick an object in the scene with the mouse pointer and move it around - such that it follows the pointer, whilst preserving the absolute distance from the camera/screen.

Re: How to move 3d objects using mouse in real time [Re: vlau] #200937
04/06/08 09:00
04/06/08 09:00
Joined: Apr 2008
Posts: 15
Oz
T
tex Offline OP
Newbie
tex  Offline OP
Newbie
T

Joined: Apr 2008
Posts: 15
Oz
I found your modelNodePath demo. It almost does what I need. However, I can't seem to get the object to maintain the same distance from the camera if the camera is rotated dynamically. The oject always jumps to the camera coordinates. I can see this is not a problem in the demo as the camera is fixed. I need to be able to move the camera and the objects dynamically.

Re: How to move 3d objects using mouse in real time [Re: tex] #200951
04/06/08 10:18
04/06/08 10:18
Joined: Aug 2005
Posts: 1,558
HK
V
vlau Offline
Serious User
vlau  Offline
Serious User
V

Joined: Aug 2005
Posts: 1,558
HK
Have send you the demo to the email address you gave me.
This is what I've done so far, I don't have too much time
dealing with it, sorry.

It may not exactly what you're after but I hope it will
get you started.

You may keep on asking here if you got any problem, maybe
other people can help.

Re: How to move 3d objects using mouse in real time [Re: vlau] #201152
04/07/08 09:17
04/07/08 09:17
Joined: Apr 2008
Posts: 15
Oz
T
tex Offline OP
Newbie
tex  Offline OP
Newbie
T

Joined: Apr 2008
Posts: 15
Oz
Thank you for this.

However, it only moves about a plane. I need to be able to move objects around in any direction - up, down, etc. Your examples fix the z value and direction. Although I am able to adjust it to move about in drag_new.zip it seems to jump to the extent of the raycast until it finds a wall and then circumscribes the boundary?

I can't seem to get it to accept:

dist = vec_dist(my.x,camera.x);
vec_set(temp,mouse_dir3d);
//vec_normalize(temp,600);
vec_normalize(temp,dist);

Which should set it to a constant distance from the camera.

What am I doing wrong?

Re: How to move 3d objects using mouse in real time [Re: tex] #201158
04/07/08 10:04
04/07/08 10:04
Joined: Jun 2004
Posts: 2,234
Wisconsin USA
FoxHound Offline
Expert
FoxHound  Offline
Expert

Joined: Jun 2004
Posts: 2,234
Wisconsin USA
You need to put the pan of the camera into your formula. Been a long time since I've used 3dgs and I don't have it installed on this computer so I can't try anything out for you. but that should get you going.


---------------------
There is no signature here.


QUIT LOOKING FOR ONE!
Re: How to move 3d objects using mouse in real time [Re: FoxHound] #201161
04/07/08 10:33
04/07/08 10:33
Joined: Aug 2005
Posts: 1,558
HK
V
vlau Offline
Serious User
vlau  Offline
Serious User
V

Joined: Aug 2005
Posts: 1,558
HK
@tex, yes it's not perfect. I'm still busy with my work here,
if I got some free time, I will rework for it again.

@Fox, nice to see you back again.



Last edited by vlau; 04/07/08 10:34.
Re: How to move 3d objects using mouse in real tim [Re: vlau] #201162
04/07/08 10:39
04/07/08 10:39
Joined: Apr 2008
Posts: 15
Oz
T
tex Offline OP
Newbie
tex  Offline OP
Newbie
T

Joined: Apr 2008
Posts: 15
Oz
Thanks Foxh and vlau,
I will keep working on it. I think ultimately this may be of use to some others too - so it is worth getting it to work properly.

It is late in Oz - so need to sleep...zzzzzzz

Cheers!:)

Re: How to move 3d objects using mouse in real tim [Re: tex] #205538
05/07/08 06:38
05/07/08 06:38
Joined: Apr 2008
Posts: 15
Oz
T
tex Offline OP
Newbie
tex  Offline OP
Newbie
T

Joined: Apr 2008
Posts: 15
Oz
I have done some more work on this problem.

I decided to use an orbit function. It is the opposite to the camera orbiting the avatar/object Instead I have a box orbiting the avatar/camera. However, the box should not follow the avatar/camera, or keep the same distance. But the distance between the object and the avatar/camera needs to be updated each time the camera/avatar moves so that when the box is moved it simply rotates about the new camer/avatar centroid coords.

The problem I have now is that it is not precise. When you move the camera/avatar around and then click/move the box it jumps a bit to a new cordinate.

What am I doing wrong?:


#include <acknex.h>
#include <default.c>

ENTITY* eBall;

var temp[3];

var rotspd=0.5; // cam movement speed

VECTOR vSpeed, vAngularSpeed, vForce, vMove;

float temp_x, temp_y, temp_z;
float temp_x2, temp_y2, temp_z2;
float tempx, tempy, tempz;

var cam_dist;

ANGLE cam_ang;

void main()
{
video_mode = 7;
shadow_stencil = 1;
// Load the level named "small.hmp"
level_load("small.hmp");
// Now create the "earth.mdl" model at x = 10, y = 20, z = 30 in our 3D world
eBall = ent_create("box.mdl",vector(0, 0, 0),NULL);
// Set an entity flag to cast a dynamic shadow
set(eBall,SHADOW);
// Use one of the default materials for giving it a shiny look
eBall.material = mat_metal;

//phent_settype(eBall,PH_RIGID,PH_SPHERE);
//phent_setmass(eBall,1,PH_SPHERE);
//phent_setfriction(eBall,90);
//phent_setelasticity(eBall,75,100);
//phent_setdamping(eBall,30,5);

// A ball game would be no fun without gravity.
//ph_setgravity(vector(0,0,-500));

while (1)
{


if(key_r)
{
if(mouse_left)
{

cam_ang.pan += rotspd*mouse_force.x;
cam_ang.tilt += rotspd*mouse_force.y;

eBall.x= (camera.x+cos(cam_ang.pan)*(cam_dist*cos(cam_ang.tilt)));
eBall.y= -1*(camera.y+sin(cam_ang.pan)*(cam_dist*cos(cam_ang.tilt)));
eBall.z= (camera.z+sin(cam_ang.tilt)*cam_dist);

vec_set(temp,eBall.x);
vec_sub(temp,camera.x);
vec_to_angle(eBall.pan,temp);

}

}

else {

temp_x2 = eBall.x - camera.x;
temp_y2 = eBall.y - camera.y;
temp_z2 = eBall.z - camera.z;
cam_dist = sqrt(temp_x2*temp_x2 + temp_y2*temp_y2 + temp_z2*temp_z2);

if(mouse_left)
{

vForce.x = -5*(mouse_force.x); // pan angle
vForce.y = 5*(mouse_force.y); // tilt angle
vForce.z = 0; // roll angle
vec_accelerate(vMove,vAngularSpeed,vForce,0.8);
vec_add(eBall.pan,vMove);

}
}

if(mouse_right)
{
vForce.x = -5*(key_force.x + mouse_force.x); // pan angle
vForce.y = 5*(key_force.y + mouse_force.y); // tilt angle
vForce.z = 0; // roll angle
vec_accelerate(vMove,vAngularSpeed,vForce,0.8);
vec_add(camera.pan,vMove);
}
vForce.x = 6 * (key_w - key_s); // forward
vForce.y = 6 * (key_a - key_d); // sideward
vForce.z = 6 * (key_home - key_end); // upward
vForce.z = 6 * (key_pgup - key_pgdn); // upward
vec_accelerate(vMove,vSpeed,vForce,0.5);
vec_rotate(vMove,camera.pan);
vec_add(camera.x,vMove);

wait(1);
}
}

Page 1 of 2 1 2

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1