Inside3D!
     

Question For A Pythagorean Specialist

 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming
View previous topic :: View next topic  
Author Message
Junrall



Joined: 21 Sep 2009
Posts: 136
Location: North West Oregon, USA

PostPosted: Sun Jan 31, 2010 9:09 pm    Post subject: Question For A Pythagorean Specialist Reply with quote

Pointing to two spots in front of the player is straight forward. (If there is a simpler method... please let me know)


My question is... how do I point to two spots, in relation to the player, 35, 45, 90, or any chosen degree to the left or to the right? (in the images above and below spot1 is 50 units away from player and spot2 is 50 units from spot1)

_________________
Good God! You shot my leg off!
Back to top
View user's profile Send private message
Spirit



Joined: 20 Nov 2004
Posts: 476

PostPosted: Sun Jan 31, 2010 9:32 pm    Post subject: Reply with quote

I have no idea how to code or whatever nor if you have coordinates, but if you do:

x = startingpointcoordinate + length * sinus (angle)
y = startingpointcoordinate + length * cosinus (angle)

would get your coordinates.

In your example with the player being 0,0 and the angle 45°.

x1 = 0 + 50 * sinus (45°)
y1 = 0 + 50 * cosinus (45°)

x2 = 0 + 100 * sinus (45°)
y2 = 0 + 100 * cosinus (45°)
or use the new coordinates you got for spot1.
_________________
Quake Maps
Back to top
View user's profile Send private message Visit poster's website
Sajt



Joined: 16 Oct 2004
Posts: 1026

PostPosted: Mon Feb 01, 2010 3:11 am    Post subject: Reply with quote

To get two points 45 degrees to the left and right, each 50 units away from the player, add a yaw offset to the player angles:

makevectors(self.v_angle + '0 45 0');
dot1 = self.origin + v_forward * 50;

makevectors(self.v_angle + '0 -45 0');
dot2 = self.origin + v_forward * 50;

You don't have to normalize v_forward, it's always unit-length (unless you changed it yourself).

In your first picture, note that:

(normalize(v_forward) * 50) + (normalize(v_forward));

is thus the same as:

v_forward * 50 + v_forward;

Which is of course the same as:

v_forward * 51;
_________________
F. A. Špork, an enlightened nobleman and a great patron of art, had a stately Baroque spa complex built on the banks of the River Labe.
Back to top
View user's profile Send private message
Teiman



Joined: 03 Jun 2007
Posts: 309

PostPosted: Mon Feb 01, 2010 1:55 pm    Post subject: Reply with quote

another simple-lame way to do that, could be to generate the points from photo1, then add enough v_left ( or -v_left ) to have the ones on photo2.

is just better to use sin and cos, anyway..
Back to top
View user's profile Send private message
Junrall



Joined: 21 Sep 2009
Posts: 136
Location: North West Oregon, USA

PostPosted: Mon Feb 01, 2010 7:10 pm    Post subject: Reply with quote

Teiman wrote:
is just better to use sin and cos, anyway..


I like Sajt's method because it is easy to use... however I'm not sure how to pass an arbitrary degree value to makevectors(self.v_angle + '0 45 0'); And, whenever I look down, the two points move downwards and and towards each other... eventually overlapping one another. What I want is to be able to look up or down and have the two points remain where they are.

I did end up using sin and cos... and like the control I have with it. Also, with the following code, the spots do not drift when I look up and down, but do move with my left to right rotation... which is just what I want.
Code:
spot1 = normalize(v_forward) * distance * mathlib_sin(degrees) + normalize(v_right) * distance * mathlib_cos(degrees);


Lol... I may have over coded the above (as usual!)... I'm sure it can be shortened in some way!

I sure like that Mathlib v2! I'd like to see more of these types of qc utilites! Thanks FrikaC!
_________________
Good God! You shot my leg off!
Back to top
View user's profile Send private message
Sajt



Joined: 16 Oct 2004
Posts: 1026

PostPosted: Mon Feb 01, 2010 8:55 pm    Post subject: Reply with quote

If you want to ignore the player's pitch angle (look up/down) completely, then do this:

makevectors('0 1 0' * (self.v_angle_y + yawoffset));

Where yawoffset is your angle (e.g. -45 or 45).

If you're new to how QuakeC's vectors work, here is a more verbose but more readable version of the same thing:

local vector ang;
ang_x = 0; // no pitch
ang_y = self.v_angle_y + yawoffset; // offset yaw
ang_z = 0; // no roll
makevectors(ang);

If you do want the player's pitch to be taken into account, and thus you want these positions to be in the same position on the screen at all times, you'd have to implement some matrix math. But I assume that that isn't what you were trying to do anyway.

You should know that sin/cos is exactly what makevectors does (in fact, mathlib probably uses makevectors in order to use those functions), so there's no point in not using makevectors here.

Also, you might want to use self.origin + self.view_ofs as the origin instead of self.origin.

pos = self.origin + self.view_ofs + v_forward * distance; // distance is e.g. 50

The player's camera is located at self.origin + self.view_ofs. If you don't add view_ofs you will be working from about the player's chest level.
_________________
F. A. Špork, an enlightened nobleman and a great patron of art, had a stately Baroque spa complex built on the banks of the River Labe.
Back to top
View user's profile Send private message
Junrall



Joined: 21 Sep 2009
Posts: 136
Location: North West Oregon, USA

PostPosted: Mon Feb 01, 2010 9:38 pm    Post subject: Reply with quote

Sajt: Excellent info! Yes I am new to quake vectors... especially when it comes to trying to figure out what is available... such as .v_angle_y
I kinda figured that there was a "something_y" that I needed to work with.
I wish there were a specific place to go for in depth descriptions and examples of this stuff... though, if a person digs enough, there is a lot of info embedded within this forum and the thousands of mods.

I'm actually starting to informally make notes (with pictures/videos) of a few things I have learned. Ha! maybe I'll find time to put something together that others can use as well.

Thanks again! Later tonight I'll play around with the info you have given... and take notes!
_________________
Good God! You shot my leg off!
Back to top
View user's profile Send private message
Junrall



Joined: 21 Sep 2009
Posts: 136
Location: North West Oregon, USA

PostPosted: Tue Feb 02, 2010 4:23 am    Post subject: Reply with quote

Ok, here it is later tonight...

Sajt: Works like a charm! Is it safe to assume that your code is processed faster than what I was doing?
_________________
Good God! You shot my leg off!
Back to top
View user's profile Send private message
Sajt



Joined: 16 Oct 2004
Posts: 1026

PostPosted: Thu Feb 04, 2010 9:45 am    Post subject: Reply with quote

If you look at the source to the mathlib_sin and mathlib_cos functions (http://www.inside3d.com/frikbot/qc/mathlib.qc), you'll see that they are calling makevectors. So by calling sin and cos you're calling makevectors twice, which is a waste...

Of course, speed-wise it doesn't really matter because this would only actually affect your framerate if you were doing it thousands of times per frame. But it is "good practice" and "cleaner" to do it this way (calling makevectors instead of sin/cos), which is a big deal to obsessive programmers like us...
_________________
F. A. Špork, an enlightened nobleman and a great patron of art, had a stately Baroque spa complex built on the banks of the River Labe.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2004 phpBB Group