Forum

sine function

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

sine function

Postby sp4x0r » Wed Sep 15, 2010 12:51 pm

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.
User avatar
sp4x0r
 
Posts: 16
Joined: Mon Jul 21, 2008 11:48 am

Postby frag.machine » Wed Sep 15, 2010 2:40 pm

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)
User avatar
frag.machine
 
Posts: 2090
Joined: Sat Nov 25, 2006 1:49 pm

Postby Spike » Wed Sep 15, 2010 5:44 pm

Code: Select all
local vector v;
v_y = angle;
makevectors(v);
newent.origin = ent.origin + v_forward * minDistFromEnt;

is basically equivelent
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby ceriux » Wed Sep 15, 2010 6:05 pm

or you could just do it with mapping and just have a trigger set off spawns in a circle?
User avatar
ceriux
 
Posts: 2223
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Postby frag.machine » Wed Sep 15, 2010 7:19 pm

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)
User avatar
frag.machine
 
Posts: 2090
Joined: Sat Nov 25, 2006 1:49 pm

Postby Error » Thu Sep 16, 2010 12:02 am

User avatar
Error
InsideQC Staff
 
Posts: 865
Joined: Fri Nov 05, 2004 5:15 am
Location: VA, USA

Postby gnounc » Thu Sep 16, 2010 5:44 am

What he said ^^
User avatar
gnounc
 
Posts: 424
Joined: Mon Apr 06, 2009 6:26 am

Postby sp4x0r » Thu Sep 16, 2010 8:01 am

Oh, excellent. Thanks for the help everyone.
User avatar
sp4x0r
 
Posts: 16
Joined: Mon Jul 21, 2008 11:48 am

Postby Sajt » Thu Sep 16, 2010 11:53 pm

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.
Sajt
 
Posts: 1215
Joined: Sat Oct 16, 2004 3:39 am


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest