Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
4 registered members (NewbieZorro, Grant, TipmyPip, AndrewAMD), 13,040 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 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