Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/19/24 18:45
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
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
3 registered members (7th_zorro, AndrewAMD, TedMar), 837 guests, and 2 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
Page 1 of 2 1 2
Maths trig problem, angle to camera #341484
09/17/10 10:39
09/17/10 10:39
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline OP
Serious User
MrGuest  Offline OP
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
Hey Guys,

It's been alluding me for too long so hopefully you guys can help.

I'm trying to make an entity look directly at the camera using ent_create() as it displays it for ent_createlayer().

I've managed to get the position of the entity right, but can't work out how to find the angle needed to make it 'appear' flat.

Thanks in advance!

Re: Maths trig problem, angle to camera [Re: MrGuest] #341499
09/17/10 14:15
09/17/10 14:15
Joined: Aug 2009
Posts: 1,438
Spain
painkiller Offline
Serious User
painkiller  Offline
Serious User

Joined: Aug 2009
Posts: 1,438
Spain
Is this what you are looking for?

Code:
action angletocamera()
{
   VECTOR temppos;
   while(1)
   {
      vec_diff(temppos, camera.x, my.x);
      vec_to_angle(my.pan, temppos);

   wait(1);
   }
}
}



Last edited by painkiller; 09/17/10 14:16.

3D Gamestudio A8 Pro
AMD FX 8350 4.00 Ghz
16GB RAM
Gigabyte GeForce GTX 960 4GB
Re: Maths trig problem, angle to camera [Re: painkiller] #341502
09/17/10 15:18
09/17/10 15:18
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline OP
Serious User
MrGuest  Offline OP
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
Unfortunately not,

Here's a screenshot of what I currently have:


As you can see the highlighted areas are hiding some yellow as their orientation matches the cameras. There's a small adjustment I need to find to get them to face their position relative to the camera position, rather than the centre of the camera.

Thanks for your post.

Re: Maths trig problem, angle to camera [Re: MrGuest] #341506
09/17/10 16:51
09/17/10 16:51
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
What code/formula are you using to get them looking
at the cam-center, as they are now?

And if not too complex, what is your cam-code doing? Post?
Does it use a entity as a camera target or anything?




"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Maths trig problem, angle to camera [Re: EvilSOB] #341510
09/17/10 17:10
09/17/10 17:10
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline OP
Serious User
MrGuest  Offline OP
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
Currently, it looks a bit like this
Code:
while(int_gameState == gameState_ingame){
        
        proc_mode = PROC_LATE;
        
        for(i = 0; i < hand_max; i++){
            
            pos.x = camera.pos_x + (camera.size_x / 2);
            pos.y = camera.pos_y + (camera.size_y / 2);
            pos.z = 20; //dist
            
            pos.x += (sin((i+0) * 60) * 250);
            pos.y -= (cos((i+0) * 60) * 250);
            
            vec_for_screen(pos, camera);
            vec_set(ent_gameHand[i].x, pos);
            
            ent_gameHand[i].pan = camera.pan - 90;
            ent_gameHand[i].roll = camera.tilt + 90;
        }
        wait(1);
    }


Just to clarify, the entities stay exactly where they should be after any camera movement, just need a final angle adjustment.

The camera doesn't target anything atm, but if necessary can do, using default camera will give the same effect.

Re: Maths trig problem, angle to camera [Re: MrGuest] #341513
09/17/10 17:35
09/17/10 17:35
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
OK, nothing there to help or hinder me then.
I also assume by looking at the code that ...
A> The entities 'ent_gameHand[xx]' are the ones that need to face the screen.
B> The vector "pos" is no longer needed after the "vec_set(ent_gameHand[i].x, pos);"

So, as untested code, give this a try...
Code:
//Replace your existing lines ...
   ...
   ent_gameHand[i].pan = camera.pan - 90;
   ent_gameHand[i].roll = camera.tilt + 90;
   ...

//With the following code ...
   ...
   //set 'pos' to x,y screen co-ords of entity position (z unused)
   vec_set(pos, ent_gameHand[i].x);
   vec_to_screen(pos, camera);

   //set 'pos' to XYZ co-ords of screen-plane over entity
   pos.z = 0;
   vec_for_screen(pos, camera);

   //make entity "face" the XYZ co-ords of screen over entity
   vec_diff(pos, pos, ent_gameHand[i].x);
   vec_to_angle(ent_gameHand[i].pan, pos);
   ...


This code isnt 'optimised' at all, in order for you to see the logic...


This code IS optimised but still untested...
Code:
...
   vec_to_screen(vec_set(pos,ent_gameHand[i].x),camera);
   pos.z = 0;   vec_for_screen(pos,camera);
   vec_to_angle(ent_gameHand[i].pan,vec_diff(0,pos,ent_gameHand[i].x));
...




"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Maths trig problem, angle to camera [Re: EvilSOB] #341516
09/17/10 18:14
09/17/10 18:14
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline OP
Serious User
MrGuest  Offline OP
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
Again, unfortunatley not,

It's similar to the logic that I've previously tried, but the tiles rotate only around pan and roll, tilt needs to remain at 0. Variations of changing tilt to roll I've tried still causes problems.

With what you've sent, and minusing 90 from tilt gives:
,
but I was still unable to find a way to get sorted from here, and changing the camera tilt no longer 'locks' their position.

Your assumptions 1 and 2 are right.



Re: Maths trig problem, angle to camera [Re: MrGuest] #341519
09/17/10 18:39
09/17/10 18:39
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Try adding this line AFTER all mine, still inside the for-loop, but without the tilt=-90...

vec_rotate(ent_gameHand[i].pan, vector(0,-90,0));


Is there any way to post the project, or a mini-project version,
or even a video of what happen when you move the camera around?




"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Maths trig problem, angle to camera [Re: EvilSOB] #341520
09/17/10 18:54
09/17/10 18:54
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline OP
Serious User
MrGuest  Offline OP
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
Thanks, I've reduced it from 65MB to 18MB in a rar, can you send me your email address and I'll give you access to my skydrive?

Re: Maths trig problem, angle to camera [Re: MrGuest] #341523
09/17/10 18:58
09/17/10 18:58
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Hmmm, we can try... alex.littler@fujitsu.com.au

But this is from work, and many ports are blocked
so FTP and the like often fail.
If I cant get through, we can try alex.littler@internode.net.au
in a few hours when Im at home.

PM me any details you need kept quiet...
Or alternatively, email both my above addresses.

Thanks.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Page 1 of 2 1 2

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