Gamestudio Links
Zorro Links
Newest Posts
WFO Training with parallel cores Zorro64
by Martin_HH. 02/24/26 19:51
Zorro version 3.0 prerelease!
by TipmyPip. 02/24/26 17:09
ZorroGPT
by TipmyPip. 02/23/26 21:52
Camera always moves upwards?
by clonman. 02/21/26 09:29
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 02/19/26 13:22
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
5 registered members (Martin_HH, TipmyPip, AndrewAMD, Grant, USER0328), 5,287 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
alx, ApprenticeInMuc, PatrickH90, USER0328, Sfrdragon
19199 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
3rd Camera Code ? #295739
10/27/09 09:50
10/27/09 09:50
Joined: Oct 2009
Posts: 90
WickWoody Offline OP
Junior Member
WickWoody  Offline OP
Junior Member

Joined: Oct 2009
Posts: 90
This code available as C-Script, but I can't convert to Lite-C. Can you convert? Or do you have? Thanks in advance.

Re: 3rd Camera Code ? [Re: WickWoody] #295745
10/27/09 10:43
10/27/09 10:43
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
lol, you might want to post the C-script code, to see if someone will convert it for you.

Re: 3rd Camera Code ? [Re: DJBMASTER] #295747
10/27/09 11:09
10/27/09 11:09
Joined: Oct 2009
Posts: 90
WickWoody Offline OP
Junior Member
WickWoody  Offline OP
Junior Member

Joined: Oct 2009
Posts: 90
I'm not write the code here grin I know, this is too long. Convert this or write a simple code. Decision is yours. Thanks in advance.


Here it is:
Code:
ifndef camera3rd_wdl;
define camera3rd_wdl;

// ---------------------------------------------------------------------
// STARTHEADER
//
// ver: 5.0
// engineReq: 6.4
// date: 061011
//
//
// title: 3rd Person Camera (01)
// class: CAMERA
// type: USER
// image: camera3rd.pcx
// help: The 3rd Person Camera is an external camera that follows the current "camera target".
// help: The camera follows the 'target' at a certain offset distance and points at another offset (see help).
//
// uses: display_active_camera_vec
// needs: display00.wdl
//
// needs: cameraSelect.wdl cameraTarget.wdl
//
// prefix: camera3rd01_
// idcode: 005
//
// ENDHEADER
// ---------------------------------------------------------------------




// ---------------------------------------------------------------------
// General Camera Entries



// entry: ID
// help: Identification number for this camera (used in cameraSelect)
// help: NOTE: Action not defined if two camera share a single value
// id: 2
define	camera3rd01_id = 2;

// enable: Write out debug values
// id: 1
//define CAMERA3RD01_DEBUG;


ifdef CAMERA3RD01_DEBUG;
string camera3rd01_debug_string[128];
endif;

// enable: Make 3rd person camera selectable by user?
// id: 3
define	camera3rd01_usr_selectable_b;

// enable: Is this an "avatar" camera?
// help: Avatar cameras are cameras who's source/pan are those of the player's eyes
// id: 16
//define	camera3rd01_avatar_q;


// ---------------------------------------------------------------------
// section: Focus hiding and fading

// enable: Hide Focus when Inside?
// id: 4
define	camera3rd01_hide_focus_b;


// entry: Fade Dist (ticks)
// help: Start fading at this distance (-1 = no fade)
// cntl: spin -1 x 1
// id: 5
define	camera3rd01_fade_start = 80;

// entry: Total Fade Dist (ticks)
// help: Target entity is 100% faded at this distance
// id: 6
define	camera3rd01_fade_end = 10;



// ---------------------------------------------------------------------
// section: Camera Offsets and Orientation

// enable: Use target's tilt value?
// id: 7
define	camera3rd01_use_tilt;

// entry: Offset Height
// help: this is the height the camera is located above/below the camera target
// id: 8
var 	camera3rd01_height = 20;

// entry: Offset Distance
// help: this is the distance away from the camera target (not including height)
// id: 9
var 	camera3rd01_dist = 100;

// entry: Offset Rotation
// help: this is the rotation the camera is located behind the camera target
// help: 0 = in front, 180 = behind, etc.
// id: 10
var	camera3rd01_rotation = 180;


// ---------------------------------------------------------------------
// section: Camera TARGET Offsets

// entry: Offset Height
// help: this is the height offset of where the 3rd person camera will be looking at
// id: 11
var 	camera3rd01_target_height = 10;

// entry: Offset Distance
// help: this is the distance away from the camera target (not including height) that the camera is looking at
// id: 12
var 	camera3rd01_target_dist = 0;


// entry: Offset Rotation
// help: this is the rotational offset of where the camera is looking at.
// help: 0 = in front, 180 = behind, etc.
// id: 13
var	camera3rd01_target_rotation = 0;

// ---------------------------------------------------------------------
// section: Collision and "Smoothing"

// enable: Preform collision test?
// id: 14
define	camera3rd01_collide_b;

// enable: Preform collision with models?
// help: Preform collision test (above) must be set too.
// id: 17
define camera3rd01_mod_collide_b;

// entry: "Smoothing" factor
// help: 0-snap to position, 1-100 -percent distance covered to target
// cntl: spin 0 100 1
// id: 15
var	camera3rd_smooth = 65;


// Local variables
var	camera3rd01_pos_vec[3];	// x,y,z postion of orbit camera
var	camera3rd01_ang_vec[3];	// pan,tilt,roll angles of the orbit camera
var	camera3rd01_bit_check; 	// used in bit-compairs to check is this camera is active


/////////////////////////////////////////////////////////////////////////
// desc: Used to attach an 3rd person camera to an entity
starter Camera3rd01_Init
{
	var	updated_b;	// has the camera been update yet this frame?
	var	view_number;	// the current view being concidered

	diag("\nWDL-Loaded:Camera3rd01.wdl");

	// init bit-field value used to check to see if this camera is active
	camera3rd01_bit_check = 1<<camera3rd01_id;

	ifdef camera3rd01_usr_selectable_b;
	//if(1 == camera3rd01_usr_selectable_b)
	//{
		// increase the camera select "max_camera" value if this value fall outside the current range
		if(camera3rd01_bit_check > cameraSelect_max_camera)
		{ cameraSelect_max_camera = camera3rd01_bit_check; }

		// add this camera type to the collection of valid cameras in camera select
		cameraSelect_valid_cameras |= camera3rd01_bit_check;
	//}
	endif;

	// calculate smoothing value
	if(camera3rd_smooth > 0)
	{
		camera3rd_smooth /= 100;  // get a percentage

		if(camera3rd_smooth > 1)
		{
			camera3rd_smooth = 1;
		}

	}



	while(1)
	{
		// don't update while level is not loaded
		while(gid01_level_state  == gid01_level_not_loaded) {wait(1); }


		updated_b = 0;	// camera hasn't been updated yet this frame
		view_number = 0;	// start with main view

		// for all active views
		while(view_number < display_active_views)
		{
			// check to see if this camera updates the current view
			if(display_active_camera_vec[view_number] & camera3rd01_bit_check)
			{
				// if the camera hasn't updated itself this frame...
				if(0 == updated_b)
				{
					// update camera position
					Camera3rd01_Update();

					// camera has been updated this frame
					updated_b = 1;
				}

				// update current view
				Camera3rd01_Update_View(view_number);

			}

			view_number +=1;
		}

		wait(1);	// every frame
	}

}

// desc: update the 3rd person camera
function Camera3rd01_Update()
{
	var	temp2[3];

	// offset from the camera target (Note: ang returns value -180 to +180
 	camera3rd01_pos_vec.x = cameraTarget_pos_vec.x + (camera3rd01_dist * COS(ang(camera3rd01_rotation+cameraTarget_ang_vec.pan)));
 	camera3rd01_pos_vec.y = cameraTarget_pos_vec.y + (camera3rd01_dist * SIN(ang(camera3rd01_rotation+cameraTarget_ang_vec.pan)));
ifndef camera3rd01_use_tilt;
 	camera3rd01_pos_vec.z = cameraTarget_pos_vec.z + camera3rd01_height;
ifelse;
 	camera3rd01_pos_vec.z = cameraTarget_pos_vec.z + (camera3rd01_dist * SIN(-cameraTarget_ang_vec.tilt));
endif;
//----Moved above collision test in case camera is pushed past model origin
 	// face the target
	vec_diff(temp.x,cameraTarget_pos_vec.x,camera3rd01_pos_vec.x);
 	vec_to_angle(temp,temp);
 	camera3rd01_ang_vec.PAN = temp.PAN;
 	camera3rd01_ang_vec.TILT = temp.TILT;

//	vec_set(camera3rd01_ang_vec,vector(camera3rd01_ang_vec.pan,asin(  ,0));

	ifdef camera3rd01_collide_b;
	//if(1 == camera3rd01_collide_b)
	//{
		// NOTE: we are assuming that "USE_BOX" c_trace is far more expensive then normal c_trace.

		// collide with any object in the way
		ifdef camera3rd01_mod_collide_b;
		you = cameraTarget_ent; // ignore target entity
		c_trace(cameraTarget_pos_vec.x,camera3rd01_pos_vec.x,
					  (IGNORE_PASSABLE+IGNORE_PASSENTS+IGNORE_YOU));
		ifelse;
 		c_trace(cameraTarget_pos_vec.x,camera3rd01_pos_vec.x,
					  (IGNORE_PASSABLE+IGNORE_PASSENTS+IGNORE_MODELS));
		endif;
		if(trace_hit == 1)
 		{
 			// offset from that target along the vector
			vec_set(camera3rd01_pos_vec.x,TARGET.x);
			// offset from the wall along normal by the near clipping dist
			vec_normalize(NORMAL.x,(camera.clip_near/2));
			vec_add(camera3rd01_pos_vec.x,NORMAL.x);
//draw_text("HIT_BACK",30,300,vector(123,123,200));
 		}
 		else
		{
			// make sure we don't 'clip' into walls next to us..
			vec_diff(temp,cameraTarget_pos_vec.x,camera3rd01_pos_vec.x);
			vec_normalize(temp,camera.clip_near);
			vec_rotate(temp,vector(90,0,0));
			vec_set(temp2,camera3rd01_pos_vec);
			vec_add(temp2,temp);  // move out by the clip_near value
			c_trace(camera3rd01_pos_vec.x,temp2.x,(IGNORE_PASSABLE+IGNORE_PASSENTS+IGNORE_MODELS));
			if(trace_hit == 1)
			{
 				// offset from that target along the vector
				vec_set(camera3rd01_pos_vec.x,TARGET.x);
				// offset from the wall along normal by the near clipping dist
				vec_normalize(NORMAL.x,(camera.clip_near/2));
				vec_add(camera3rd01_pos_vec.x,NORMAL.x);
//draw_text("HIT_1",30,300,vector(123,123,200));
			}
			else
			{
				// rotate temp back the other dir twice as much..
				vec_rotate(temp,vector(-180,0,0));
				vec_set(temp2,camera3rd01_pos_vec);
				vec_add(temp2,temp);    // move out by the clip_near value
				c_trace(camera3rd01_pos_vec.x,temp2.x,(IGNORE_PASSABLE+IGNORE_PASSENTS+IGNORE_MODELS));
				if(trace_hit == 1)
				{
 					// offset from that target along the vector
					vec_set(camera3rd01_pos_vec.x,TARGET.x);
					// offset from the wall along normal by the near clipping dist
					vec_normalize(NORMAL.x,(camera.clip_near/2));
					vec_add(camera3rd01_pos_vec.x,NORMAL.x);
//draw_text("HIT_2",30,300,vector(123,123,200));
				}
			}

		}

	//}
	endif;  //camera3rd01_collide_b

	// Fading and Visiblity
	if(cameraTarget_ent != NULL)   // make sure we have an entity
	{
		cameraTarget_ent.invisible = off;   // need to do this incase another camera made this ent invisible (e.g. FPCam)

		if(camera3rd01_fade_start > 0)
		{
			temp2.x = vec_dist(cameraTarget_pos_vec,camera3rd01_pos_vec);//vec_length(temp.x);     // distance from camera to target
			if(temp2.x < camera3rd01_fade_start)
			{
				// fade to zero depending distance to fade end
				cameraTarget_ent.transparent = ON;
				// NOTE: use 1st max to avoid negitive alpha
				//			use 2nd max to avoid devide by zero
				cameraTarget_ent.alpha = 100*max(0,
									((temp2.x-camera3rd01_fade_end)
										/ max(1,(camera3rd01_fade_start-camera3rd01_fade_end))));
			}
			else
			{
				cameraTarget_ent.transparent = OFF;
			}
		}

	}
}


// desc: update the view whos ID is passed in to the position/orientation
//      of the 3rd Person Camera
//
// uses: temp, camera, cameraTarget_avatar_view_q,
function	Camera3rd01_Update_View(view_number)
{
	if(view_number == 0)
	{
		if(0 < camera3rd_smooth)
		{
			// update main view (camera)
			vec_diff(temp.x,camera3rd01_pos_vec.x,camera.x);
ifdef CAMERA3RD01_DEBUG;
//++diag("\nCAM ORG DIST: ");
diag("\nCam: ");
str_for_num(camera3rd01_debug_string,vec_length(temp.x));
diag(camera3rd01_debug_string);
diag(" === ");
str_for_num(camera3rd01_debug_string,time_step);
diag(camera3rd01_debug_string);
diag(" : ");
str_for_num(camera3rd01_debug_string,fps_lock);
diag(camera3rd01_debug_string);
diag(" : ");
str_for_num(camera3rd01_debug_string,fps_max);
diag(camera3rd01_debug_string);

endif;
			vec_scale(temp.x,camera3rd_smooth);
			vec_add(camera.x,temp.x);
/*
ifdef CAMERA3RD01_DEBUG;
diag(" CAM MOVE DIST: ");
str_for_num(camera3rd01_debug_string,vec_length(temp.x));
diag(camera3rd01_debug_string);
endif;
*/
			vec_set(camera.pan, camera3rd01_ang_vec.pan);
		}
		else
		{
			// update main view (camera)
			vec_set(camera.x,camera3rd01_pos_vec.x);
			vec_set(camera.pan,camera3rd01_ang_vec.pan);
		}

		// is this an avatar view?
		ifdef camera3rd01_avatar_q;
			cameraTarget_avatar_view_q = 1;
		ifelse;
			cameraTarget_avatar_view_q = 0;
		endif;
	}

	ifdef camera3rd01_hide_focus_b;
	//	if(1==camera3rd01_hide_focus_b)
	//{	// hide the target entity from view if inside
		camera.genius = cameraTarget_ent;
	//}
	ifelse;
	//else
	//{	// show the target entity no matter what
		camera.genius = 0;
	//}
	endif;

	// +++ other views


}

endif;



Re: 3rd Camera Code ? [Re: WickWoody] #295779
10/27/09 15:22
10/27/09 15:22
Joined: Apr 2007
Posts: 125
Brazil - São Paulo
Ericmor Offline
Member
Ericmor  Offline
Member

Joined: Apr 2007
Posts: 125
Brazil - São Paulo
Here's a tested tip (i still use it in my early prototypes):
Use two triangle-type objects MDLs to position the câmera: one stuck into a vertex coodinate on the player, the other stuck on the camera coordinate. The first control's third person camera rotation and position, the other control câmera 'collision', so it doesn't enter walls or other models.
Good luck!

Re: 3rd Camera Code ? [Re: Ericmor] #295805
10/27/09 19:28
10/27/09 19:28
Joined: Oct 2009
Posts: 90
WickWoody Offline OP
Junior Member
WickWoody  Offline OP
Junior Member

Joined: Oct 2009
Posts: 90
I solved it myself. Have solved with a simple code.

Code:
camera.pan += (3*time_step)*1.4;
   camera.pan=my.pan;
	camera.x = my.x-200*cos(my.pan);
	camera.y = my.y-200*sin(my.pan);
	camera.z = my.z+100;
	camera.tilt += mouse_force.y;
	if(camera.tilt < -50) {camera.tilt = -50;}
	if(camera.tilt > 20) {camera.tilt = 20;}



Re: 3rd Camera Code ? [Re: WickWoody] #295809
10/27/09 20:20
10/27/09 20:20
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
you'll have to set parts of that in a while loop, to make sure it is updated each frame.

Re: 3rd Camera Code ? [Re: DJBMASTER] #295811
10/27/09 20:45
10/27/09 20:45
Joined: Oct 2009
Posts: 90
WickWoody Offline OP
Junior Member
WickWoody  Offline OP
Junior Member

Joined: Oct 2009
Posts: 90
I already do this.


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