sine function

Discuss programming in the QuakeC language.
Post Reply
sp4x0r
Posts: 16
Joined: Mon Jul 21, 2008 11:48 am

sine function

Post by sp4x0r »

silly question, but I'm stupid and tired, my brain isn't working. Is there a sin() function in qc? I'm pretty inept at programming generally, so I don't know what I'm supposed to be looking for.

I want to spawn monsters at random points on a circle on the x/y plane around an entity. They can't spawn too close to the origin of the entity, otherwise they'll telefrag it. So I was thinking something like:

Code: Select all

newent.origin_x = ent.origin_x + (sin(angle) * minDistFromEnt);
newent.origin_y = ent.origin_y + (cos(angle) * minDistFromEnt);
Does that make sense? Any help appreciated.

I guess it doesn't even really need to be a circle, just far enough outside the entity's hitbox that the new entity doesn't cause problems.
frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

Post by frag.machine »

There's no sin() or cos() function in standard QuakeC (although they do exist in DP and probably in FTE as built-ins, too). If you want to make a fully portable code, I'd suggest you to make something like:

a) make the central point entity face a random direction (randomize self.angles_y);
b) make it to fire a traceline from its origin to a destination at a random number of units from its origin (check the shotgun fire function in weapons.qc for examples of how to do that);
c) use trace_endpos as the spawn coordinates for your new entity;
d) restore self.angles_y (optional).

This approach has the advantage of make sure your destination won't be a solid spot. Of course, you'll still need to check if there's enough room for your about to spawn entity.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Post by Spike »

Code: Select all

local vector v;
v_y = angle;
makevectors(v);
newent.origin = ent.origin + v_forward * minDistFromEnt;
is basically equivelent
ceriux
Posts: 2230
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Post by ceriux »

or you could just do it with mapping and just have a trigger set off spawns in a circle?
frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

Post by frag.machine »

Spike wrote:

Code: Select all

local vector v;
v_y = angle;
makevectors(v);
newent.origin = ent.origin + v_forward * minDistFromEnt;
is basically equivelent
^^^ What Spike said.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
Error
InsideQC Staff
Posts: 865
Joined: Fri Nov 05, 2004 5:15 am
Location: VA, USA
Contact:

Post by Error »

gnounc
Posts: 428
Joined: Mon Apr 06, 2009 6:26 am

Post by gnounc »

What he said ^^
sp4x0r
Posts: 16
Joined: Mon Jul 21, 2008 11:48 am

Post by sp4x0r »

Oh, excellent. Thanks for the help everyone.
Sajt
Posts: 1215
Joined: Sat Oct 16, 2004 3:39 am

Post by Sajt »

mathlib.qc is if you need sin(). But you don't, you want makevectors. makevectors does for you what you wanted to do with sin and cos, so using mathlib would be redundant and wasteful (since mathlib uses makevectors to generate sin/cos anyway).
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.
Post Reply