Gamestudio Links
Zorro Links
Newest Posts
webGL
by Ice2642. 11/17/25 21:27
Camera always moves upwards?
by NeoDumont. 11/17/25 09:56
Future of ZorroHFT
by TipmyPip. 11/16/25 13:52
COT Download with Quandl does not work
by Petra. 11/15/25 09:35
Training with the R bridge does not work
by Petra. 11/15/25 09:31
Zorro 2.70
by jcl. 11/15/25 08:43
brokerCommand PLOT_HLINE parameters
by M_D. 11/13/25 10:42
ZorroGPT
by TipmyPip. 11/10/25 11:04
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (AndrewAMD), 7,596 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
tritom, sheliepaley, Blueguy, blobplayintennis, someone2
19178 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Camera collision code help? #151447
09/01/07 04:38
09/01/07 04:38
Joined: Aug 2007
Posts: 21
J
jfizer Offline OP
Newbie
jfizer  Offline OP
Newbie
J

Joined: Aug 2007
Posts: 21
Following is my current camera code that allows for pan, tilt and zoom using the mouse. What I'm now trying to add is object detection so that the camera dosn't get blocked from viewing the player entity. However, I'm having no luck with this. In fact, when ever I try to set the camera postion relivtive to the target returned by c_trace I get a hard crash.

Any ideas?


if(mouse_right)
{
cam_ang.pan+=rotspd*mouse_force.x;
cam_ang.tilt+=rotspd*mouse_force.y;
cam_ang.tilt=clamp(cam_ang.tilt,minang,maxang);
}
// orbit no tilt
if(mouse_left)
{
cam_ang.pan+=rotspd*mouse_force.x;
}

// zoom with mousewheel
cam_dist-=integer(mickey.z);
cam_dist=clamp(cam_dist,mindist,maxdist);

// do some trig to find camera location and then aim it at pFocus
camera.x=my_entity.x+cos(cam_ang.pan)*(cam_dist*cos(cam_ang.tilt));
camera.y=my_entity.y+sin(cam_ang.pan)*(cam_dist*cos(cam_ang.tilt));
camera.z=my_entity.z+sin(cam_ang.tilt)*cam_dist;
vec_set(temp,my_entity.x);
vec_sub(temp,camera.x);
vec_to_angle(camera.pan,temp);

// Find objects between player and camera. c_trace(my_entity.x,vector(camera.x,camera.y,camera.z),IGNORE_ME|IGNORE_PASSABLE|IGNORE_MODELS|IGNORE_SPRITES);
if(trace_hit == 1)
{
vec_set(miscTemp,target);
//vec_diff(miscTemp,camera,target);
//vec_set(cameraTPos,target);
// offset from the wall along normal by the near clipping dist
//vec_normalize(normal,(camera.clip_near/2));
//vec_add(cameraTPos,normal);
} else {vec_set(miscTemp,vector(0,0,0));}


Re: Camera collision code help? [Re: jfizer] #151448
09/02/07 08:33
09/02/07 08:33
Joined: Aug 2007
Posts: 21
J
jfizer Offline OP
Newbie
jfizer  Offline OP
Newbie
J

Joined: Aug 2007
Posts: 21
Simple enough. Needed to move the collision detection before the trigonometry and have it modify the distance to target and then have my trig calcuations use that to figure out the postion.

Somthing like...


// zoom with mousewheel
cam_dist-=integer(mickey.z);
cam_dist=clamp(cam_dist,mindist,maxdist);

// Find objects between player and camera.
var dist=c_trace(my_entity.x,vector(camera.x,camera.y,camera.z),IGNORE_ME|IGNORE_PASSABLE|IGNORE_MODELS|IGNORE_SPRITES);
if(trace_hit == 1)
{
cam_dist=clamp(cam_dist,mindist,dist);
}

// do some trig to find camera location and then aim it at pFocus
camera.x=my_entity.x+cos(cam_ang.pan)*(cam_dist*cos(cam_ang.tilt));
camera.y=my_entity.y+sin(cam_ang.pan)*(cam_dist*cos(cam_ang.tilt));
camera.z=my_entity.z+sin(cam_ang.tilt)*cam_dist;
vec_set(temp,my_entity.x);
vec_sub(temp,camera.x);
vec_to_angle(camera.pan,temp);


Not perfect by a long shot, but a step in the right direction.


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | 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