Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,187 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Writing custom face-object function, need help #215382
07/10/08 21:28
07/10/08 21:28
Joined: Mar 2007
Posts: 677
0x00000USA
M
MrCode Offline OP
User
MrCode  Offline OP
User
M

Joined: Mar 2007
Posts: 677
0x00000USA
Hi, all. I've decided to write a custom utility function used for facing one entity to another (for instance the camera to another object). I had thought I had all the math worked out (as for using trigonometry to find the angles and whatnot), but apparently I haven't got it all figured out as far as the code is concerned.

Here's the function:

Code:
void FaceObject(ENTITY* ent1,ENTITY* ent2)
{
	distz= ent2.z - ent1.z; //these are the distance variables.
	disty= ent2.y - ent1.y; //as you can see,these find
	distx= ent2.x - ent1.x; //the distance between the x,y,and z components.
	
	distxy= sqrt(pow(distx,2) + pow(disty,2)); //finding general distance to object
	/*I prefer not to use vec_dist() here because
	 *I have already found the z distance above,
	 *and I don't need more than the x and y in
	 *this case.*/
	
	ent1.pan= atan(disty/distx); //using arc tangent to find pan
	ent1.tilt= atan(distz/distxy); //and tilt angles.
}


Can anyone tell me what I'm doing wrong here? Maybe I should be using atanv()?

Well, I suppose it would help if I explained a bit more in detail,blush. I run it, and the camera is just sitting there, doing nothing, facing straight. I have the object that I want the camera to face at an obscure position from the camera, so I know it's not just that the effect isn't visible.

Last edited by MrCode; 07/11/08 23:50.

Code:
void main()
{
    cout << "I am MrCode,";
    cout << "hear me roar!";
    system("PAUSE");
}
Re: Writing custom face-object function, need help [Re: MrCode] #215693
07/12/08 20:50
07/12/08 20:50
Joined: Mar 2007
Posts: 677
0x00000USA
M
MrCode Offline OP
User
MrCode  Offline OP
User
M

Joined: Mar 2007
Posts: 677
0x00000USA
Nobody at all?

Re: Writing custom face-object function, need help [Re: MrCode] #215697
07/12/08 20:57
07/12/08 20:57
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
why you dont use vec_to_angle?
vec_to_angle(camera.pan,TARGET.x);


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: Writing custom face-object function, need help [Re: WretchedSid] #215704
07/12/08 21:27
07/12/08 21:27
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
this faces first one to second:
Code:
void ent_face_first(ENTITY* first,ENTITY* second){
	if(first == NULL || second == NULL){
		printf("Null object in ent_face_first.");
	}	
	VECTOR vec;
	vec_set(vec.x,second.x);
	ANGLE angl;
	vec_set(vec.x,vec_sub(vec.x,first.x));
	vec.z = 0;
	vec_to_angle(angl.pan,vec.x);
	first.pan = angl.pan;
	
}



this faces two objects to each other:

Code:
void ent_face_both(ENTITY* first,ENTITY* second){
	if(first == NULL || second == NULL){
		printf("Null object in ent_face_both.");
	}
	
	VECTOR vec;
	ANGLE angl;
	
	vec_set(vec.x,second.x);
	vec_set(vec.x,vec_sub(vec.x,first.x));
	vec.z = 0;
	vec_to_angle(angl.pan,vec.x);
	first.pan = angl.pan;
	
	vec_set(vec.x,first.x);
	vec_set(vec.x,vec_sub(vec.x,second.x));
	vec_to_angle(angl.pan,vec.x);
	second.pan = angl.pan;
}




a lil exp. i did when i saw the thread:

http://rapidshare.de/files/39985587/face.zip.html
-move the first object with mouse, uncomment ent_face_first and comment ent_face_both to see the other function-

edit: vec.z = 0; lines are NOT needed since i used first.pan = angl.pan;

Last edited by Quadraxas; 07/12/08 22:24.

3333333333
Re: Writing custom face-object function, need help [Re: Quad] #215721
07/13/08 00:23
07/13/08 00:23
Joined: Mar 2007
Posts: 677
0x00000USA
M
MrCode Offline OP
User
MrCode  Offline OP
User
M

Joined: Mar 2007
Posts: 677
0x00000USA
Well, I've done the vec_set(),vec_sub(),vec_to_angle() thing before, but I've never really figured out quite how that works. I wanted to make a function that doesn't compute values that I won't need, and one where I know how it works so that I can take advantage of that in different possible applications. I was thinking like this when I did the first write:



as you can see, I'm using basic trig to find the angles. Or so I thought. Maybe I need to take a different approach?


Code:
void main()
{
    cout << "I am MrCode,";
    cout << "hear me roar!";
    system("PAUSE");
}
Re: Writing custom face-object function, need help [Re: MrCode] #216094
07/15/08 04:06
07/15/08 04:06
Joined: Mar 2007
Posts: 677
0x00000USA
M
MrCode Offline OP
User
MrCode  Offline OP
User
M

Joined: Mar 2007
Posts: 677
0x00000USA
btw, it's not because I'm forgetting to call it in a while loop. It's being called in a loop, it's just not working.

Here's the whole code:
Code:
#include <acknex.h>
#include <default.c>

float distx,disty,distz,distxy;

void FaceObject(ENTITY* ent1,ENTITY* ent2)
{
	distz= ent2.z - ent1.z; //these are the distance variables.
	disty= ent2.y - ent1.y; //as you can see,these find
	distx= ent2.x - ent1.x; //the distance between the x,y,and z components.
	
	distxy= sqrt(pow(distx,2) + pow(disty,2)); //finding general distance to object
	/*I prefer not to use vec_dist() here because
	 *I have already found the z distance above,
	 *and I don't need more than the x and y in
	 *this case.*/
	
	ent1.pan= atan(disty/distx); //using arc tangent to find pan
	ent1.tilt= atan(distz/distxy); //and tilt angles.
}

void main()
{
	video_mode= 8;
	video_screen= 1;
	level_load("terr_env.wmb");
	wait(3);
	
	camera.z= 250;
	
	ENTITY* face_me= ent_create("dummy.mdl",vector(100,100,100),NULL);
	
	while(1)
	{
		FaceObject(camera,face_me);
		
		face_me.x+= 10 * time_step;
		wait(1);
	}
}



Code:
void main()
{
    cout << "I am MrCode,";
    cout << "hear me roar!";
    system("PAUSE");
}
Re: Writing custom face-object function, need help [Re: MrCode] #216104
07/15/08 07:54
07/15/08 07:54
Joined: Jun 2008
Posts: 31
Moscow, Russia
L
LunaticX Offline
Newbie
LunaticX  Offline
Newbie
L

Joined: Jun 2008
Posts: 31
Moscow, Russia
void FaceObject(ENTITY* ent1,ENTITY* ent2)//i think its not working because camera is a VIEW and not ENTITY

void FaceObject(VIEW* ent1,ENTITY* ent2) try something like this

or try vectors
void FaceObject(VECTOR* ent1,VECTOR* ent2)
...
FaceObject(camera.x,face_me.x);

and sorry cant help you with code cuz im bad with all these atan thingies =(

Re: Writing custom face-object function, need help [Re: LunaticX] #216243
07/16/08 00:33
07/16/08 00:33
Joined: Mar 2007
Posts: 677
0x00000USA
M
MrCode Offline OP
User
MrCode  Offline OP
User
M

Joined: Mar 2007
Posts: 677
0x00000USA
Well, thx, but the first suggestion kinda defeats the purpose of modularity, and the second one won't work, as the compiler complains that "'pan' is not a member of VECTOR". I've tried using void*, but again, "'x' is not a member of VOID.

But I think I have a solution. I suppose I could create a dummy entity, and have that be ent1, and have the camera match it's coordinates/angles.


Thanks for the replies!

EDIT: Success! Well, mostly. It turns in accordance to the position of the test entity, but I can't make it face the test entity exactly. I've tried multiplying the atan()s by different values, and adding angles to them as well, but nothing's working. I guess my estimates were waaaaay off. frown

Last edited by MrCode; 07/16/08 00:47.

Code:
void main()
{
    cout << "I am MrCode,";
    cout << "hear me roar!";
    system("PAUSE");
}

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

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