Entity look at camera keeping it's orientation

Posted By: alibaba

Entity look at camera keeping it's orientation - 05/12/17 08:31

I want an entity to look at the camera and keep the same orientation as the camera. So basically it should just behave like a panel. I couldn't wrap my head around the vector calculations needed. Thanks in advance.
Posted By: painkiller

Re: Entity look at camera keeping it's orientation - 05/12/17 09:10

something like this?

Code:
VECTOR temp_vec;

...

vec_diff(temp_vec,camera.x,my.x);
vec_to_angle(my.pan,temp_vec); //always look to camera

Posted By: 3run

Re: Entity look at camera keeping it's orientation - 05/12/17 09:14

Hey, man!

Is this what you are looking for?
Code:
#define PRAGMA_POINTER

void main(){
	
	shadow_stencil = 2;
	warn_level = 6;
	fps_max = 60;
	level_load("");
	wait(3);
	
	def_move();
	
	ENTITY *ground = ent_create(CUBE_MDL, vector(0, 0, -32), NULL);
	vec_set(&ground->scale_x, vector(20, 20, 1));
	
	ENTITY *panel_like = ent_create(CUBE_MDL, vector(200, 0, 0), NULL);
	vec_set(&panel_like->scale_x, vector(1, 5, 1));
	set(panel_like, SHADOW);
	
	VECTOR offset_vec;
	vec_fill(&offset_vec.x, 0);
	
	while(panel_like){
		
		
		
		vec_set(&offset_vec.x, vector(200, 0, 0));
		vec_rotate(&offset_vec.x, &camera->pan);
		vec_add(&offset_vec.x, &camera->x);
		
		vec_set(&panel_like->x, &offset_vec.x);
		vec_set(&panel_like->pan, &camera->pan);
		
		wait(1);
	}
	
	sys_exit(NULL);
}



Edit: painkiller was faster grin

Best regards!
Posted By: alibaba

Re: Entity look at camera keeping it's orientation - 05/12/17 09:26

@Painkiller Well that's the standard way to do it. But it does not keep the orientation. You can see what I mean when you change the cameras roll angle.

@3run Yeah that's nearly the behavior I want, but the object should stay in place and not move with the camera.

Thanks for you answers so far laugh
Posted By: Superku

Re: Entity look at camera keeping it's orientation - 05/12/17 09:34

What's the use case for this?
If the entity stays in place you will probably get (different) perspective distortions when you rotate the camera - if I'm not mistaken. Maybe it would help to use a custom/ special view matrix in the vertex shader for that object, like an isometric/ orthographic one?
Posted By: alibaba

Re: Entity look at camera keeping it's orientation - 05/12/17 09:37

The view distortion is not a big deal. I want to place a kind of goal marker on the map.
Anyway, the answer was easier than I thought:

Code:
vec_set(panelEnt.pan, camera_view.pan);
ang_rotate(panelEnt.pan,vector(180,0,0));



Thank you all!

EDIT: the actual reason for using this way is because I'm working on a splitscreen game, but panels don't clip a the cameras border, so one panel can overlap with the view next to it etc. If you know a way how I can keep the rendering of a panel inside a specific view, then I'd prefer using panels.
Posted By: txesmi

Re: Entity look at camera keeping it's orientation - 05/12/17 16:40

Originally Posted By: alibaba
If you know a way how I can keep the rendering of a panel inside a specific view, then I'd prefer using panels.

Here goes a try I did some time ago
Code:
#include <acknex.h>
#include <default.c>

#define PRAGMA_PATH "%EXE_DIR%\templates\images";
#define PRAGMA_PATH "%EXE_DIR%\templates\models";

action actIcon ()
{
	BMAP *_bmp = bmap_create ( "schaden.tga" );
	PANEL *_pan = pan_create ( "", 1 );
	pan_setwindow ( _pan, 0, 0, 0, bmap_width(_bmp), bmap_height(_bmp), _bmp, &_pan->skill_x, &_pan->skill_y );
	while ( !key_esc )
	{
		VECTOR _v;
		vec_set ( &_v, &my->x );
		vec_to_screen ( &_v, camera );
		_pan->pos_x = floor(_v.x) - bmap_width(_bmp) / 2;
		_pan->pos_y = floor(_v.y) - bmap_height(_bmp) / 2;
		var _upperX = minv ( bmap_width(_bmp), camera->pos_x + camera->size_x - _pan->pos_x );
		var _upperY = minv ( bmap_height(_bmp), camera->pos_y + camera->size_y - _pan->pos_y );
		_pan->skill_x = maxv ( 0, camera->pos_x - _pan->pos_x );
		_pan->skill_y = maxv ( 0, camera->pos_y - _pan->pos_y );
		if ( ( _upperX < 1 ) || ( _upperY < 1 ) || ( _pan->skill_x > bmap_width(_bmp) ) || ( _pan->skill_y > bmap_height(_bmp) ) )
			_pan->flags &= ~SHOW;
		else
		{
			var _winSizeX = minv ( bmap_width(_bmp) - _pan->skill_x, _upperX );
			var _winSizeY = minv ( bmap_height(_bmp) - _pan->skill_y, _upperY );
			pan_setwindow ( _pan, 1, _pan->skill_x, _pan->skill_y, _winSizeX, _winSizeY, _bmp, &_pan->skill_x, &_pan->skill_y );
			_pan->flags |= SHOW;
		}
		wait(1);
	}
}

void main ()
{
	wait(1);
	level_load ( "" );
	camera->size_x = screen_size.x - 200;
	camera->size_y = screen_size.y - 200;
	camera->pos_x = 100;
	camera->pos_y = 100;
	ent_createlayer ( "skycube+6.tga", SKY | CUBE, 1 );
	ent_create ( "pistol.mdl", vector(300,0,0), actIcon );
	def_move ();
}

© 2024 lite-C Forums