BaseQC CCam rotation?

Discuss programming in the QuakeC language.
ceriux
Posts: 2230
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

BaseQC CCam rotation?

Post by ceriux »

hey i was trying to get this camera to rotate around the player, but it seems all you can do is move it. but i was thinking maybe what i was editing was wrong?

anyways, is there a spot here that lets you choose which way the camera is facing? and if so how do i make it face the player at all times?

i was trying to edit "self.camview."

Code: Select all

  if (self.aflag == FALSE) 
     {
        self.aflag = TRUE;
        camera = spawn ();
        spot = spawn ();
        self.trigger_field = camera;
        camera.classname = "camera";
        camera.movetype = MOVETYPE_FLY;
        camera.solid = SOLID_NOT;
        setmodel (camera,"progs/eyes.mdl");
        setsize (camera,'0 0 0','0 0 0');
        makevectors (self.v_angle);
        traceline ((self.origin + self.view_ofs),(((self.origin + self.view_ofs)
           + (v_forward * -64.000))),FALSE,self);
        self.camview = '0 0-64'; // added
        setorigin (camera,trace_endpos);
        camera.angles = self.angles;
        self.weaponmodel = "";
        msg_entity = self;
        WriteByte (MSG_ONE,5);
        WriteEntity (MSG_ONE,camera);
        WriteByte (MSG_ONE,10.000);
        WriteAngle (MSG_ONE,camera.angles_x);
        WriteAngle (MSG_ONE,camera.angles_y);
        WriteAngle (MSG_ONE,camera.angles_z);
        sprint (self,"Chase Cam On\n");
      }
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Post by Spike »

well, with the last 4 writes, you're basically doing svc_setangles(self, self.angles); which is basically a noop.

Note that if you change the client's angle with that svc, you're also going to change the player's angle when it echos off the client. There's no real reason to use the svc when you can use fixangles.
ceriux
Posts: 2230
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Post by ceriux »

ahh , well. this was part of the source, i just now started editing it and well i havnt done anything with qc really since before i left for job corps. so basically i should remove this chase cam and code my own which "should" work better?

well i just looked and the chase cam is coded from the first tutorial on the tutorial page, would this one be better?

http://inside3d.com/showtutorial.php?id=102
apolluwn
Posts: 35
Joined: Tue Apr 26, 2011 11:57 pm

Post by apolluwn »

What you are looking to do is to rotate the camera around the player with the mouse input, or what is it exactly you are trying to do?

I wouldn't use the tutorial you are using as a base... It is filled with non-sense... Use the one from Ender's scratch tutorial to start.
ceriux
Posts: 2230
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Post by ceriux »

platformer camera.
apolluwn
Posts: 35
Joined: Tue Apr 26, 2011 11:57 pm

Post by apolluwn »

ceriux wrote:platformer camera.
So you are trying to do something like this more or less?

Code: Select all

.entity  camera;             
void SetViewAngle()
{
   msg_entity = self;

   WriteByte (MSG_ONE,SVC_SETANGLE);
   WriteAngle (MSG_ONE,self.camera.angles_x);
   WriteAngle (MSG_ONE,self.camera.angles_y);
   WriteAngle (MSG_ONE,self.camera.angles_z); 
}

void SetViewPoint(entity ent)  
{
 	msg_entity = self;         
 	
 	WriteByte(MSG_ONE, SVC_SETVIEW); 
 	WriteEntity(MSG_ONE, ent);       
}

void Chasecam_Update();    

void Chasecam_On()
{
 	self.camera 				= spawn();           
 	self.camera.classname 	= "camera";         
 	self.camera.movetype 	= MOVETYPE_NONE;     
 	self.camera.solid     	= SOLID_NOT;         
 	
 	setmodel (self.camera,"progs/eyes.mdl");
 	setsize(self.camera, '0 0 0', '0 0 0');      

 	Chasecam_Update();                           

 	stuffcmd(self, "r_drawviewmodel 0\ncl_bob 0\ncl_rollangle 0\nv_kickpitch 0\nv_kickroll 0\n");
 	SetViewPoint(self.camera);
 	SetViewAngle(); 	
}

void Chasecam_Off()
{
 	stuffcmd(self, "r_drawviewmodel 1\ncl_bob 0.02\ncl_rollangle 2.0\nv_kickpitch 0.6\nv_kickroll 0.6\n");
 	SetViewPoint(self);
 	remove(self.camera);
}

void Chasecam_Update()
{
	local vector camera_origin;
	local vector vec, camera_angles;
	local float diff;
 	
 	if (!self.camera) 
 		return;
	
	self.angles 			= '0 90 0';
	self.camera.angles 	= '0 180 0'; 
	self.camera.origin_y = self.origin_y;		
	self.camera.origin_x = self.origin_x+256;	

	self.camera.origin_z = self.origin_z;	

	setorigin (self.camera, self.camera.origin); 
}

void ChaseCam_Toggle()
{
 	if (!self.camera) {Chasecam_On();} else {Chasecam_Off();}
}
ceriux
Posts: 2230
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Post by ceriux »

i dont know but ill test it =)
apolluwn
Posts: 35
Joined: Tue Apr 26, 2011 11:57 pm

Post by apolluwn »

Actually... That's just going to be trouble... Particularly if you want to toggle it.

Sorry, It's a wee bit late.

Code: Select all

entity camera;
void SetViewAngle(entity ent)
{
   msg_entity = self;

   WriteByte  (MSG_ONE, 10);
   WriteAngle (MSG_ONE, ent.angles_x);
   WriteAngle (MSG_ONE, ent.angles_y);
   WriteAngle (MSG_ONE, ent.angles_z); 
}

void SetViewPoint(entity ent)  
{
 	msg_entity = self;         
 	
 	WriteByte  (MSG_ONE, 5); 
 	WriteEntity(MSG_ONE, ent);       
}

void ChaseCam_Update()
{ 		 	
		// face the player in a constant direction		
		self.angles 		= '0 90 0';

		// camera distance from player		
		camera.origin_x = self.origin_x+128;			
		// set camera origin based on self.origin
		camera.origin_y = self.origin_y;

		camera.origin_z = self.origin_z;	
			
 		setorigin (camera,  camera.origin);      			
}

void ChaseCam_Toggle()
{
 	if (self.aflag == FALSE) 
 	{
		self.aflag 			= TRUE;
		
 		camera 				= spawn();           
 		camera.classname 	= "camera";         
 		camera.movetype 	= MOVETYPE_NONE;     
 		camera.solid     	= SOLID_NOT;         
 	
 		setmodel  (camera,  "progs/null.spr");
 		setsize 	 (camera,  '0 0 0', '0 0 0');
	
		// 180 degrees to face player model	
		camera.angles 		= '0 180 0'; 
		
 		SetViewPoint(camera);
 		SetViewAngle(camera); 

 		stuffcmd(self, "r_drawviewmodel 0\ncl_bob 0\ncl_rollangle 0\nv_kickpitch 0\nv_kickroll 0\n");
 	}
 	else 
 	{
 		self.aflag 		= FALSE;
 		stuffcmd(self, "r_drawviewmodel 1\ncl_bob 0.02\ncl_rollangle 2.0\nv_kickpitch 0.6\nv_kickroll 0.6\n");
		
		// face the same direction as the player model appeared w/ chasecam on
		self.angles = '0 90 0';
		
 		SetViewPoint(self);
 		SetViewAngle(self); 
 		
 		remove(camera);
 	} 		
} 

------

In PlayerPreThink() at the very bottom should be fine:

if(self.aflag)
ChaseCam_Update();

------

Above ImpulseCommands():

void ChaseCam_Toggle();

------

In ImpulseCommands() before self.impulse = 0;

if (self.impulse == 100) {ChaseCam_Toggle();}   		
EDIT: To remove mistakes and typo's
Last edited by apolluwn on Sun Aug 28, 2011 10:08 pm, edited 1 time in total.
ceriux
Posts: 2230
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Post by ceriux »

yes, actually thats perfect. if you wouldnt mind explaining what you changed and why? ( i had to change a few entities and .entities around .entity camera was conflicting with entity camera so i just changed .entity camera to ccamera...)

also can someone point me in the direction of altering players to where they only move left to right ? i need things like up to only make the player aim up. (you dont have to code it for me just point me in the right place and give me some tips maybe?) thanks! (apolluwn you will be receiving credit in the readme.)
apolluwn
Posts: 35
Joined: Tue Apr 26, 2011 11:57 pm

Post by apolluwn »

ceriux wrote:if you wouldnt mind explaining what you changed and why?
Do you mean between the two versions that were posted?

It seems like it should be creating a new entity that can be referenced by self since self.camera should just be pointing to the new empty entity that was spawned with self.camera = spawn()... Then the fields are filled in. The same goes for "entity camera" except it can't be assigned to other entities like self. If you had .entity camera and entity ccamera then you could spawn ccamera and make self.camera = ccamera to grab fields from ccamera...

When the entity gets spawned it then ceases being !camera (or !self.camera). In the original code, it needed !self.camera to know it was off.

It was also no longer !self.camera after it was removed and it would try to apply the origin change to self.camera even though it had been removed(and you can't set the origin of a free'd entity). This is also why it wouldn't respawn after being removed.

It now uses the same field .float aflag that you were using as a toggle now.

That said, it should have worked as either .entity or entity as long as it doesn't try to use ! as "off" after it has been spawned and then subsequently removed.

ceriux wrote:( i had to change a few entities and .entities around .entity camera was conflicting with entity camera so i just changed .entity camera to ccamera...)
Well, you can't have a .entity and an entity of the same name because then it has no idea what kind of data you want it to be... This applies for anything... You couldn't have a .entity camera and a float camera either.

ceriux wrote:also can someone point me in the direction of altering players to where they only move left to right ?
One way would be to design the maps in a certain way and feed it a constant for origin_x. Or, you could grab the starting origin vector and make it so that it stays at the same origin_x for example... This should help to stop from being pushed if you collide with an object. If you had only just removed the buttons you could still move along x possibly if it "slides around" an object.
ceriux wrote:(apolluwn you will be receiving credit in the readme.)
I really can't take credit for any of that.

It was really just a modified version of the chasecam in Ender's scratch tutorial except now when it is on it keeps the player facing at a constant angle, the camera moved out from the player origin on the x-axis 128 units, and the camera angle is changed to turn back towards the player...

It would probably be worth checking out some of RenegadeC's stuff. I'm pretty sure he had a few different versions of platforming cameras himself that were much better than this and just seeing how he accomplished it would probably give you some ideas as to how to improve your camera.
ceriux
Posts: 2230
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Post by ceriux »

you still helped and did work, downsider helped me with the rest of what i needed. you will be credited for your contribution and help. not necessarily for the camera code. so far things are working great too and since i'm not using a dummy, theres less information to be sent and what not so hopefully it will run nicely on the psp. my next step ill be locking the position of the camera that way the angles cant be changed by moving the mouse (analog stick) or by any other means, i should be able to accomplish this on my own. (sorry for the horrible brick of text.) ill keep everyone updated.
Blackstar1000
Posts: 52
Joined: Mon Sep 13, 2010 5:16 pm

Post by Blackstar1000 »

I've been trying to do this for months. I'm using quake clean. Unmodified. I just don't understand how you implement what you are talking about above.

I guess what I'm asking for is sort of a tut, I'm sorry I'm a total newb at quakes code but I am finding it a bit convoluted. How do I get this to compile? I can't help but feel I'm only getting half of what I need to.
Knives out. Catch the mouse. Squash his head. Put him in your mouth.
apolluwn
Posts: 35
Joined: Tue Apr 26, 2011 11:57 pm

Post by apolluwn »

Blackstar1000 wrote:I've been trying to do this for months. I'm using quake clean. Unmodified. I just don't understand how you implement what you are talking about above.

I guess what I'm asking for is sort of a tut, I'm sorry I'm a total newb at quakes code but I am finding it a bit convoluted. How do I get this to compile? I can't help but feel I'm only getting half of what I need to.
I'm not sure what problem you are having exactly, but the second code post does give some clues as to where things should be. I can make it a little more specific, however.

Are you saying that you are using clean quakec as in http://tremor.quakedev.com/Clean_v106qc.zip ?


You could just paste all of this in above the PlayerPreThink function in client.qc

Code: Select all

entity camera;
void SetViewAngle(entity ent)
{
   msg_entity = self;

   WriteByte  (MSG_ONE, SVC_SETANGLE);
   WriteAngle (MSG_ONE, ent.angles_x);
   WriteAngle (MSG_ONE, ent.angles_y);
   WriteAngle (MSG_ONE, ent.angles_z);
}

void SetViewPoint(entity ent) 
{
    msg_entity = self;         
    
    WriteByte  (MSG_ONE, SVC_SETVIEW);
    WriteEntity(MSG_ONE, ent);       
}

void ChaseCam_Update()
{           
      // face the player in a constant direction      
      self.angles       = '0 90 0';

      // camera distance from player      
      camera.origin_x = self.origin_x+128;         
      // set camera origin based on self.origin
      camera.origin_y = self.origin_y;

      camera.origin_z = self.origin_z;   
         
       setorigin (camera,  camera.origin);               
}

void ChaseCam_Toggle()
{
    if (self.aflag == FALSE)
    {
      self.aflag          = TRUE;
      
       camera             = spawn();           
       camera.classname    = "camera";         
       camera.movetype    = MOVETYPE_NONE;     
       camera.solid        = SOLID_NOT;         
    
       setmodel  (camera,  "progs/null.spr");
       setsize     (camera,  '0 0 0', '0 0 0');
   
      // 180 degrees to face player model   
      camera.angles       = '0 180 0';
      
       SetViewPoint(camera);
       SetViewAngle(camera);

       stuffcmd(self, "r_drawviewmodel 0\ncl_bob 0\ncl_rollangle 0\nv_kickpitch 0\nv_kickroll 0\n");
    }
    else
    {
       self.aflag       = FALSE;
       stuffcmd(self, "r_drawviewmodel 1\ncl_bob 0.02\ncl_rollangle 2.0\nv_kickpitch 0.6\nv_kickroll 0.6\n");
      
      // face the same direction as the player model appeared w/ chasecam on
      self.angles = '0 90 0';
      
       SetViewPoint(self);
       SetViewAngle(self);
       
       remove(camera);
    }       
}
Inside of the PlayerPreThink function in client.qc at the very bottom paste this:

Code: Select all

if(self.aflag)
ChaseCam_Update();
Above the ImpulseCommands function in weapons.qc paste this:

Code: Select all

void ChaseCam_Toggle();

Inside of the ImpulseCommands function before self.impulse = 0; paste this:

Code: Select all

if (self.impulse == 100) {ChaseCam_Toggle();}   
Compile the code replace the old progs.dat with the one you've compiled then it is toggled by either going to the console and typing impulse 100, or binding a key to impulse 100

EDIT: To remove mistakes and typo's
Last edited by apolluwn on Sun Aug 28, 2011 10:09 pm, edited 1 time in total.
ceriux
Posts: 2230
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Post by ceriux »

or you could even put self.impulse = 666; in somewhere and it will automatically toggle it on when you start the game.
Blackstar1000
Posts: 52
Joined: Mon Sep 13, 2010 5:16 pm

Post by Blackstar1000 »

Thanks so much!

EDIT: Doh

warning: ent redefined on a different scope
Unknown Value "SVC_SETANGLE"
ent rediclared
Error client.qc Unknown Value "SVC_SETVIEW"
Error client.qc Unknown Value "SetViewPoint"
Error client.qc Unknown Value "ChaseCam_Update"

this all now comes out of client.qc
as well as two other warnings from fight.qc

I might get time later to try to bang some of these out. I get nothing but the standard quake clean warnings before following your instructions. What do you make of this? (Also, yes that is exactly the clean code that I'm using.)
Knives out. Catch the mouse. Squash his head. Put him in your mouth.
Post Reply