public static void R_SetupFrame() { // don't allow cheats in multiplayer if (cl.maxclients > 1) { Cvar.Cvar_Set("r_fullbright", "0"); } R_AnimateLight(); r_framecount++; // build the transformation matrix for the given view angles r_origin = r_refdef.vieworg; Mathlib.AngleVectors(ref r_refdef.viewangles, out vpn, out vright, out vup); // current viewleaf r_oldviewleaf = r_viewleaf; r_viewleaf = Mod_PointInLeaf(ref r_origin, cl.worldmodel); game_engine.V_SetContentsColor(r_viewleaf.contents); game_engine.V_CalcBlend(); r_cache_thrash = false; c_brush_polys = 0; c_alias_polys = 0; }
public static void R_TeleportSplash(ref Vector3 org) { for (int i = -16; i < 16; i += 4) { for (int j = -16; j < 16; j += 4) { for (int k = -24; k < 32; k += 4) { particle_t p = AllocParticle(); if (p == null) { return; } p.die = (float)(cl.time + 0.2 + (Random() & 7) * 0.02); p.color = 7 + (Random() & 7); p.type = ptype_t.pt_slowgrav; Vector3 dir = new Vector3(j * 8, i * 8, k * 8); p.org = org + new Vector3(i + (Random() & 3), j + (Random() & 3), k + (Random() & 3)); Mathlib.Normalize(ref dir); float vel = 50 + (Random() & 63); p.vel = dir * vel; } } } }
public static int SV_HullPointContents(hull_t hull, int num, ref Vector3 p) { while (num >= 0) { if (num < hull.firstclipnode || num > hull.lastclipnode) { Sys_Error("SV_HullPointContents: bad node number"); } short[] node_children = hull.clipnodes[num].children; mplane_t plane = hull.planes[hull.clipnodes[num].planenum]; float d; if (plane.type < 3) { d = Mathlib.Comp(ref p, plane.type) - plane.dist; } else { d = Vector3.Dot(plane.normal, p) - plane.dist; } if (d < 0) { num = node_children[1]; } else { num = node_children[0]; } } return(num); }
public static trace_t PushEntity(edict_t ent, ref v3f push) { v3f end; Mathlib.VectorAdd(ref ent.v.origin, ref push, out end); trace_t trace; if (ent.v.movetype == q_shared.MOVETYPE_FLYMISSILE) { trace = Move(ref ent.v.origin, ref ent.v.mins, ref ent.v.maxs, ref end, q_shared.MOVE_MISSILE, ent); } else if (ent.v.solid == q_shared.SOLID_TRIGGER || ent.v.solid == q_shared.SOLID_NOT) { // only clip against bmodels trace = Move(ref ent.v.origin, ref ent.v.mins, ref ent.v.maxs, ref end, q_shared.MOVE_NOMONSTERS, ent); } else { trace = Move(ref ent.v.origin, ref ent.v.mins, ref ent.v.maxs, ref end, q_shared.MOVE_NORMAL, ent); } Mathlib.Copy(ref trace.endpos, out ent.v.origin); SV_LinkEdict(ent, true); if (trace.ent != null) { SV_Impact(ent, trace.ent); } return(trace); }
public static void R_LavaSplash(ref Vector3 org) { Vector3 dir; for (int i = -16; i < 16; i++) { for (int j = -16; j < 16; j++) { for (int k = 0; k < 1; k++) { particle_t p = AllocParticle(); if (p == null) { return; } p.die = (float)(cl.time + 2 + (Random() & 31) * 0.02); p.color = 224 + (Random() & 7); p.type = ptype_t.pt_slowgrav; dir.X = j * 8 + (Random() & 7); dir.Y = i * 8 + (Random() & 7); dir.Z = 256; p.org = org + dir; p.org.Z += Random() & 63; Mathlib.Normalize(ref dir); float vel = 50 + (Random() & 63); p.vel = dir * vel; } } } }
static void PF_droptofloor() { edict_t ent = PROG_TO_EDICT(pr_global_struct.self); Vector3 org, mins, maxs; Mathlib.Copy(ref ent.v.origin, out org); Mathlib.Copy(ref ent.v.mins, out mins); Mathlib.Copy(ref ent.v.maxs, out maxs); Vector3 end = org; end.Z -= 256; trace_t trace = SV_Move(ref org, ref mins, ref maxs, ref end, 0, ent); if (trace.fraction == 1 || trace.allsolid) { G_FLOAT((float)0); } else { Mathlib.Copy(ref trace.endpos, out ent.v.origin); SV_LinkEdict(ent, false); ent.v.flags = (int)ent.v.flags | q_shared.FL_ONGROUND; ent.v.groundentity = EDICT_TO_PROG(trace.ent); G_FLOAT((float)1); } }
public static void Chase_Update() { // if can't see player, reset Vector3 forward, up, right; Mathlib.AngleVectors(ref cl.viewangles, out forward, out right, out up); // calc exact destination chase_dest = r_refdef.vieworg - forward * chase_back.value - right * chase_right.value; chase_dest.Z = r_refdef.vieworg.Z + chase_up.value; // find the spot the player is looking at Vector3 dest = r_refdef.vieworg + forward * 4096; Vector3 stop; TraceLine(ref r_refdef.vieworg, ref dest, out stop); // calculate pitch to look at the same spot from camera stop -= r_refdef.vieworg; float dist; Vector3.Dot(ref stop, ref forward, out dist); if (dist < 1) { dist = 1; } r_refdef.viewangles.X = (float)(-Math.Atan(stop.Z / dist) / Math.PI * 180.0); //r_refdef.viewangles[PITCH] = -atan(stop[2] / dist) / M_PI * 180; // move towards destination r_refdef.vieworg = chase_dest; //VectorCopy(chase_dest, r_refdef.vieworg); }
public static void SV_AirAccelerate(Vector3 wishveloc) { float wishspd = Mathlib.Normalize(ref wishveloc); if (wishspd > 30) { wishspd = 30; } float currentspeed = Vector3.Dot(ToVector(ref sv_player.v.velocity), wishveloc); float addspeed = wishspd - currentspeed; if (addspeed <= 0) { return; } float accelspeed = (float)(sv_accelerate.value * wishspeed * host_framtime); if (accelspeed > addspeed) { accelspeed = addspeed; } wishveloc *= accelspeed; sv_player.v.velocity.x += wishveloc.X; sv_player.v.velocity.y += wishveloc.Y; sv_player.v.velocity.z += wishveloc.Z; }
static unsafe void PF_traceline() { float * v1 = G_VECTOR(q_shared.OFS_PARM0); float * v2 = G_VECTOR(q_shared.OFS_PARM1); int nomonsters = (int)G_FLOAT(q_shared.OFS_PARM2); edict_t ent = G_EDICT(q_shared.OFS_PARM3); Vector3 vec1, vec2; Copy(v1, out vec1); Copy(v2, out vec2); trace_t trace = SV_Move(ref vec1, ref q_shared.ZeroVector, ref q_shared.ZeroVector, ref vec2, nomonsters, ent); pr_global_struct.trace_allsolid = trace.allsolid ? 1 : 0; pr_global_struct.trace_startsolid = trace.startsolid ? 1 : 0; pr_global_struct.trace_fraction = trace.fraction; pr_global_struct.trace_inwater = trace.inwater ? 1 : 0; pr_global_struct.trace_inopen = trace.inopen ? 1 : 0; Mathlib.Copy(ref trace.endpos, out pr_global_struct.trace_endpos); Mathlib.Copy(ref trace.plane.normal, out pr_global_struct.trace_plane_normal); pr_global_struct.trace_plane_dist = trace.plane.dist; if (trace.ent != null) { pr_global_struct.trace_ent = EDICT_TO_PROG(trace.ent); } else { pr_global_struct.trace_ent = EDICT_TO_PROG(sv.edicts[0]); } }
public static void Test5_f() { entity_t p = cl_entities[cl.viewentity]; if (p == null) { return; } OpenTK.Vector3 org = p.origin; for (int i = 0; i < sv.edicts.Length; i++) { edict_t ed = sv.edicts[i]; if (ed.free) { continue; } OpenTK.Vector3 vmin, vmax; Mathlib.Copy(ref ed.v.absmax, out vmax); Mathlib.Copy(ref ed.v.absmin, out vmin); if (org.X >= vmin.X && org.Y >= vmin.Y && org.Z >= vmin.Z && org.X <= vmax.X && org.Y <= vmax.Y && org.Z <= vmax.Z) { Con_Printf("{0}\n", i); } } }
public static void R_SetFrustum() { if (r_refdef.fov_x == 90) { // front side is visible frustum[0].normal = vpn + vright; frustum[1].normal = vpn - vright; frustum[2].normal = vpn + vup; frustum[3].normal = vpn - vup; } else { // rotate VPN right by FOV_X/2 degrees Mathlib.RotatePointAroundVector(out frustum[0].normal, ref vup, ref vpn, -(90 - r_refdef.fov_x / 2)); // rotate VPN left by FOV_X/2 degrees Mathlib.RotatePointAroundVector(out frustum[1].normal, ref vup, ref vpn, 90 - r_refdef.fov_x / 2); // rotate VPN up by FOV_X/2 degrees Mathlib.RotatePointAroundVector(out frustum[2].normal, ref vright, ref vpn, 90 - r_refdef.fov_y / 2); // rotate VPN down by FOV_X/2 degrees Mathlib.RotatePointAroundVector(out frustum[3].normal, ref vright, ref vpn, -(90 - r_refdef.fov_y / 2)); } for (int i = 0; i < 4; i++) { frustum[i].type = q_shared.PLANE_ANYZ; frustum[i].dist = Vector3.Dot(r_origin, frustum[i].normal); frustum[i].signbits = (byte)SignbitsForPlane(frustum[i]); } }
public static void SV_ReadClientMove(ref usercmd_t move) { client_t client = host_client; // read ping time client.ping_times[client.num_pings % q_shared.NUM_PING_TIMES] = (float)(sv.time - Reader.MSG_ReadFloat()); client.num_pings++; // read current angles Vector3 angles = Reader.ReadAngles(); Mathlib.Copy(ref angles, out client.edict.v.v_angle); // read movement move.forwardmove = Reader.MSG_ReadShort(); move.sidemove = Reader.MSG_ReadShort(); move.upmove = Reader.MSG_ReadShort(); // read buttons int bits = Reader.MSG_ReadByte(); client.edict.v.button0 = bits & 1; client.edict.v.button2 = (bits & 2) >> 1; int i = Reader.MSG_ReadByte(); if (i != 0) { client.edict.v.impulse = i; } }
static float angledelta(float a) { a = Mathlib.anglemod(a); if (a > 180) { a -= 360; } return(a); }
public virtual void Awake() { if (Instance == null) { Instance = this; return; } Destroy(this.gameObject); }
static unsafe void PF_normalize() { float * value1 = G_VECTOR(q_shared.OFS_PARM0); Vector3 tmp; Copy(value1, out tmp); Mathlib.Normalize(ref tmp); G_VECTOR(ref tmp); }
public static trace_t Move(ref v3f start, ref v3f mins, ref v3f maxs, ref v3f end, int type, edict_t passedict) { Vector3 vstart, vmins, vmaxs, vend; Mathlib.Copy(ref start, out vstart); Mathlib.Copy(ref mins, out vmins); Mathlib.Copy(ref maxs, out vmaxs); Mathlib.Copy(ref end, out vend); return(SV_Move(ref vstart, ref vmins, ref vmaxs, ref vend, type, passedict)); }
public static bool R_CullBox(ref Vector3 mins, ref Vector3 maxs) { for (int i = 0; i < 4; i++) { if (Mathlib.BoxOnPlaneSide(ref mins, ref maxs, frustum[i]) == 2) { return(true); } } return(false); }
static unsafe void PF_makevectors() { float * av = G_VECTOR(q_shared.OFS_PARM0); Vector3 a = new Vector3(av[0], av[1], av[2]); Vector3 fw, right, up; Mathlib.AngleVectors(ref a, out fw, out right, out up); Mathlib.Copy(ref fw, out pr_global_struct.v_forward); Mathlib.Copy(ref right, out pr_global_struct.v_right); Mathlib.Copy(ref up, out pr_global_struct.v_up); }
public static void DropPunchAngle() { Vector3 v = ToVector(ref sv_player.v.punchangle); double len = Mathlib.Normalize(ref v) - 10 * host_framtime; if (len < 0) { len = 0; } v *= (float)len; Mathlib.Copy(ref v, out sv_player.v.punchangle); }
public static void SV_ClientThink() { if (sv_player.v.movetype == q_shared.MOVETYPE_NONE) { return; } onground = ((int)sv_player.v.flags & q_shared.FL_ONGROUND) != 0; DropPunchAngle(); // // if dead, behave differently // if (sv_player.v.health <= 0) { return; } // // angles // show 1/3 the pitch angle and all the roll angle cmd = host_client.cmd; v3f v_angle; Mathlib.VectorAdd(ref sv_player.v.v_angle, ref sv_player.v.punchangle, out v_angle); Vector3 pang = ToVector(ref sv_player.v.angles); Vector3 pvel = ToVector(ref sv_player.v.velocity); sv_player.v.angles.z = game_engine.V_CalcRoll(ref pang, ref pvel) * 4; if (sv_player.v.fixangle == 0) { sv_player.v.angles.x = -v_angle.x / 3; sv_player.v.angles.y = v_angle.y; } if (((int)sv_player.v.flags & q_shared.FL_WATERJUMP) != 0) { SV_WaterJump(); return; } // // walk // if ((sv_player.v.waterlevel >= 2) && (sv_player.v.movetype != q_shared.MOVETYPE_NOCLIP)) { SV_WaterMove(); return; } SV_AirMove(); }
public static void SV_Physics_Noclip(edict_t ent) { // regular thinking if (!SV_RunThink(ent)) { return; } Mathlib.VectorMA(ref ent.v.angles, (float)host_framtime, ref ent.v.avelocity, out ent.v.angles); Mathlib.VectorMA(ref ent.v.origin, (float)host_framtime, ref ent.v.velocity, out ent.v.origin); SV_LinkEdict(ent, false); }
public static void CL_AdjustAngles() { float speed = (float)host_framtime; if (in_speed.IsDown) { speed *= cl_anglespeedkey.value; } if (!in_strafe.IsDown) { cl.viewangles.Y -= speed * cl_yawspeed.value * CL_KeyState(ref in_right); cl.viewangles.Y += speed * cl_yawspeed.value * CL_KeyState(ref in_left); cl.viewangles.Y = Mathlib.anglemod(cl.viewangles.Y); } if (in_klook.IsDown) { game_engine.V_StopPitchDrift(); cl.viewangles.X -= speed * cl_pitchspeed.value * CL_KeyState(ref in_forward); cl.viewangles.X += speed * cl_pitchspeed.value * CL_KeyState(ref in_back); } float up = CL_KeyState(ref in_lookup); float down = CL_KeyState(ref in_lookdown); cl.viewangles.X -= speed * cl_pitchspeed.value * up; cl.viewangles.X += speed * cl_pitchspeed.value * down; if (up != 0 || down != 0) { game_engine.V_StopPitchDrift(); } if (cl.viewangles.X > 80) { cl.viewangles.X = 80; } if (cl.viewangles.X < -70) { cl.viewangles.X = -70; } if (cl.viewangles.Z > 50) { cl.viewangles.Z = 50; } if (cl.viewangles.Z < -50) { cl.viewangles.Z = -50; } }
public static bool IsCollinear(float[] prev, float[] cur, float[] next) { Vector3 v1 = new Vector3(cur[0] - prev[0], cur[1] - prev[1], cur[2] - prev[2]); Mathlib.Normalize(ref v1); Vector3 v2 = new Vector3(next[0] - prev[0], next[1] - prev[1], next[2] - prev[2]); Mathlib.Normalize(ref v2); v1 -= v2; return((Math.Abs(v1.X) <= q_shared.COLINEAR_EPSILON) && (Math.Abs(v1.Y) <= q_shared.COLINEAR_EPSILON) && (Math.Abs(v1.Z) <= q_shared.COLINEAR_EPSILON)); }
public static void SV_TouchLinks(edict_t ent, areanode_t node) { // touch linked edicts link_t next; for (link_t l = node.trigger_edicts.Next; l != node.trigger_edicts; l = next) { next = l.Next; edict_t touch = (edict_t)l.Owner;// EDICT_FROM_AREA(l); if (touch == ent) { continue; } if (touch.v.touch == 0 || touch.v.solid != q_shared.SOLID_TRIGGER) { continue; } if (ent.v.absmin.x > touch.v.absmax.x || ent.v.absmin.y > touch.v.absmax.y || ent.v.absmin.z > touch.v.absmax.z || ent.v.absmax.x < touch.v.absmin.x || ent.v.absmax.y < touch.v.absmin.y || ent.v.absmax.z < touch.v.absmin.z) { continue; } int old_self = pr_global_struct.self; int old_other = pr_global_struct.other; pr_global_struct.self = EDICT_TO_PROG(touch); pr_global_struct.other = EDICT_TO_PROG(ent); pr_global_struct.time = (float)sv.time; PR_ExecuteProgram(touch.v.touch); pr_global_struct.self = old_self; pr_global_struct.other = old_other; } // recurse down both sides if (node.axis == -1) { return; } if (Mathlib.Comp(ref ent.v.absmax, node.axis) > node.dist) { SV_TouchLinks(ent, node.children[0]); } if (Mathlib.Comp(ref ent.v.absmin, node.axis) < node.dist) { SV_TouchLinks(ent, node.children[1]); } }
public static void R_DrawSpriteModel(entity_t e) { // don't even bother culling, because it's just a single // polygon without a surface cache mspriteframe_t frame = R_GetSpriteFrame(e); msprite_t psprite = (msprite_t)e.model.cache.data; Vector3 v_forward, right, up; if (psprite.type == q_shared.SPR_ORIENTED) { // bullet marks on walls Mathlib.AngleVectors(ref e.angles, out v_forward, out right, out up); // Uze: changed from _CurrentEntity to e } else { // normal sprite up = vup; // vup; right = vright; // vright; } GL.Color3(1f, 1, 1); GL_DisableMultitexture(); GL_Bind(frame.gl_texturenum); GL.Enable(EnableCap.AlphaTest); GL.Begin(BeginMode.Quads); GL.TexCoord2(0f, 1); Vector3 point = e.origin + up * frame.down + right * frame.left; GL.Vertex3(point); GL.TexCoord2(0f, 0); point = e.origin + up * frame.up + right * frame.left; GL.Vertex3(point); GL.TexCoord2(1f, 0); point = e.origin + up * frame.up + right * frame.right; GL.Vertex3(point); GL.TexCoord2(1f, 1); point = e.origin + up * frame.down + right * frame.right; GL.Vertex3(point); GL.End(); GL.Disable(EnableCap.AlphaTest); }
public static void SV_AirMove() { Vector3 pangles = ToVector(ref sv_player.v.angles); Mathlib.AngleVectors(ref pangles, out forward, out right, out up); float fmove = cmd.forwardmove; float smove = cmd.sidemove; // hack to not let you back into teleporter if (sv.time < sv_player.v.teleport_time && fmove < 0) { fmove = 0; } Vector3 wishvel = forward * fmove + right * smove; if ((int)sv_player.v.movetype != q_shared.MOVETYPE_WALK) { wishvel.Z = cmd.upmove; } else { wishvel.Z = 0; } wishdir = wishvel; wishspeed = Mathlib.Normalize(ref wishdir); if (wishspeed > sv_maxspeed.value) { wishvel *= sv_maxspeed.value / wishspeed; wishspeed = sv_maxspeed.value; } if (sv_player.v.movetype == q_shared.MOVETYPE_NOCLIP) { // noclip Mathlib.Copy(ref wishvel, out sv_player.v.velocity); } else if (onground) { SV_UserFriction(); SV_Accelerate(); } else { // not on ground, so little effect on velocity SV_AirAccelerate(wishvel); } }
static void SND_Spatialize(channel_t ch) { // anything coming from the view entity will allways be full volume if (ch.entnum == cl.viewentity) { ch.leftvol = ch.master_vol; ch.rightvol = ch.master_vol; return; } // calculate stereo seperation and distance attenuation sfx_t snd = ch.sfx; Vector3 source_vec = ch.origin - listener_origin; float dist = Mathlib.Normalize(ref source_vec) * ch.dist_mult; float dot = Vector3.Dot(listener_right, source_vec); float rscale, lscale; if (shm.channels == 1) { rscale = 1.0f; lscale = 1.0f; } else { rscale = 1.0f + dot; lscale = 1.0f - dot; } // add in distance effect float scale = (1.0f - dist) * rscale; ch.rightvol = (int)(ch.master_vol * scale); if (ch.rightvol < 0) { ch.rightvol = 0; } scale = (1.0f - dist) * lscale; ch.leftvol = (int)(ch.master_vol * scale); if (ch.leftvol < 0) { ch.leftvol = 0; } }
public static void PF_changeyaw() { edict_t ent = PROG_TO_EDICT(pr_global_struct.self); float current = Mathlib.anglemod(ent.v.angles.y); float ideal = ent.v.ideal_yaw; float speed = ent.v.yaw_speed; if (current == ideal) { return; } float move = ideal - current; if (ideal > current) { if (move >= 180) { move = move - 360; } } else { if (move <= -180) { move = move + 360; } } if (move > 0) { if (move > speed) { move = speed; } } else { if (move < -speed) { move = -speed; } } ent.v.angles.y = Mathlib.anglemod(current + move); }
static void PF_makestatic() { edict_t ent = G_EDICT(q_shared.OFS_PARM0); MsgWriter msg = sv.signon; msg.MSG_WriteByte(q_shared.svc_spawnstatic); msg.MSG_WriteByte(SV_ModelIndex(GetString(ent.v.model))); msg.MSG_WriteByte((int)ent.v.frame); msg.MSG_WriteByte((int)ent.v.colormap); msg.MSG_WriteByte((int)ent.v.skin); for (int i = 0; i < 3; i++) { msg.MSG_WriteCoord(Mathlib.Comp(ref ent.v.origin, i)); msg.MSG_WriteAngle(Mathlib.Comp(ref ent.v.angles, i)); } // throw the entity away now ED_Free(ent); }
public static void SV_CheckVelocity(edict_t ent) { // // bound velocity // if (Mathlib.CheckNaN(ref ent.v.velocity, 0)) { Con_Printf("Got a NaN velocity on {0}\n", GetString(ent.v.classname)); } if (Mathlib.CheckNaN(ref ent.v.origin, 0)) { Con_Printf("Got a NaN origin on {0}\n", GetString(ent.v.classname)); } Vector3 max = Vector3.One * sv_maxvelocity.value; Vector3 min = -Vector3.One * sv_maxvelocity.value; Mathlib.Clamp(ref ent.v.velocity, ref min, ref max, out ent.v.velocity); }