static float angledelta(float a) { a = Mathlib.anglemod(a); if (a > 180) { a -= 360; } return(a); }
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 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); }
public static void SV_NewChaseDir(edict_t actor, edict_t enemy, float dist) { float olddir = Mathlib.anglemod((int)(actor.v.ideal_yaw / 45) * 45); float turnaround = Mathlib.anglemod(olddir - 180); float deltax = enemy.v.origin.x - actor.v.origin.x; float deltay = enemy.v.origin.y - actor.v.origin.y; v3f d; if (deltax > 10) { d.y = 0; } else if (deltax < -10) { d.y = 180; } else { d.y = q_shared.DI_NODIR; } if (deltay < -10) { d.z = 270; } else if (deltay > 10) { d.z = 90; } else { d.z = q_shared.DI_NODIR; } // try direct route float tdir; if (d.y != q_shared.DI_NODIR && d.z != q_shared.DI_NODIR) { if (d.y == 0) { tdir = (d.z == 90 ? 45 : 315); } else { tdir = (d.z == 90 ? 135 : 215); } if (tdir != turnaround && SV_StepDirection(actor, tdir, dist)) { return; } } // try other directions if (((Random() & 3) & 1) != 0 || Math.Abs(deltay) > Math.Abs(deltax)) { tdir = d.y; d.y = d.z; d.z = tdir; } if (d.y != q_shared.DI_NODIR && d.y != turnaround && SV_StepDirection(actor, d.y, dist)) { return; } if (d.z != q_shared.DI_NODIR && d.z != turnaround && SV_StepDirection(actor, d.z, dist)) { return; } // there is no direct path to the player, so pick another direction if (olddir != q_shared.DI_NODIR && SV_StepDirection(actor, olddir, dist)) { return; } if ((Random() & 1) != 0) //randomly determine direction of search { for (tdir = 0; tdir <= 315; tdir += 45) { if (tdir != turnaround && SV_StepDirection(actor, tdir, dist)) { return; } } } else { for (tdir = 315; tdir >= 0; tdir -= 45) { if (tdir != turnaround && SV_StepDirection(actor, tdir, dist)) { return; } } } if (turnaround != q_shared.DI_NODIR && SV_StepDirection(actor, turnaround, dist)) { return; } actor.v.ideal_yaw = olddir; // can't move // if a bridge was pulled out from underneath a monster, it may not have // a valid standing position at all if (!SV_CheckBottom(actor)) { SV_FixCheckBottom(actor); } }
public static void CL_RelinkEntities() { // determine partial update time float frac = CL_LerpPoint(); cl_numvisedicts = 0; // // interpolate player info // cl.velocity = cl.mvelocity[1] + frac * (cl.mvelocity[0] - cl.mvelocity[1]); if (cls.demoplayback) { // interpolate the angles Vector3 angleDelta = cl.mviewangles[0] - cl.mviewangles[1]; Mathlib.CorrectAngles180(ref angleDelta); cl.viewangles = cl.mviewangles[1] + frac * angleDelta; } float bobjrotate = Mathlib.anglemod(100 * cl.time); // start on the entity after the world for (int i = 1; i < cl.num_entities; i++) { entity_t ent = cl_entities[i]; if (ent.model == null) { // empty slot if (ent.forcelink) { R_RemoveEfrags(ent); // just became empty } continue; } // if the object wasn't included in the last packet, remove it if (ent.msgtime != cl.mtime[0]) { ent.model = null; continue; } Vector3 oldorg = ent.origin; if (ent.forcelink) { // the entity was not updated in the last message // so move to the final spot ent.origin = ent.msg_origins[0]; ent.angles = ent.msg_angles[0]; } else { // if the delta is large, assume a teleport and don't lerp float f = frac; Vector3 delta = ent.msg_origins[0] - ent.msg_origins[1]; if (Math.Abs(delta.X) > 100 || Math.Abs(delta.Y) > 100 || Math.Abs(delta.Z) > 100) { f = 1; // assume a teleportation, not a motion } // interpolate the origin and angles ent.origin = ent.msg_origins[1] + f * delta; Vector3 angleDelta = ent.msg_angles[0] - ent.msg_angles[1]; Mathlib.CorrectAngles180(ref angleDelta); ent.angles = ent.msg_angles[1] + f * angleDelta; } // rotate binary objects locally if ((ent.model.flags & q_shared.EF_ROTATE) != 0) { ent.angles.Y = bobjrotate; } if ((ent.effects & q_shared.EF_BRIGHTFIELD) != 0) { R_EntityParticles(ent); } if ((ent.effects & q_shared.EF_MUZZLEFLASH) != 0) { dlight_t dl = CL_AllocDlight(i); dl.origin = ent.origin; dl.origin.Z += 16; Vector3 fv, rv, uv; Mathlib.AngleVectors(ref ent.angles, out fv, out rv, out uv); dl.origin += fv * 18; dl.radius = 200 + (Random() & 31); dl.minlight = 32; dl.die = (float)cl.time + 0.1f; } if ((ent.effects & q_shared.EF_BRIGHTLIGHT) != 0) { dlight_t dl = CL_AllocDlight(i); dl.origin = ent.origin; dl.origin.Z += 16; dl.radius = 400 + (Random() & 31); dl.die = (float)cl.time + 0.001f; } if ((ent.effects & q_shared.EF_DIMLIGHT) != 0) { dlight_t dl = CL_AllocDlight(i); dl.origin = ent.origin; dl.radius = 200 + (Random() & 31); dl.die = (float)cl.time + 0.001f; } if ((ent.model.flags & q_shared.EF_GIB) != 0) { R_RocketTrail(ref oldorg, ref ent.origin, 2); } else if ((ent.model.flags & q_shared.EF_ZOMGIB) != 0) { R_RocketTrail(ref oldorg, ref ent.origin, 4); } else if ((ent.model.flags & q_shared.EF_TRACER) != 0) { R_RocketTrail(ref oldorg, ref ent.origin, 3); } else if ((ent.model.flags & q_shared.EF_TRACER2) != 0) { R_RocketTrail(ref oldorg, ref ent.origin, 5); } else if ((ent.model.flags & q_shared.EF_ROCKET) != 0) { R_RocketTrail(ref oldorg, ref ent.origin, 0); dlight_t dl = CL_AllocDlight(i); dl.origin = ent.origin; dl.radius = 200; dl.die = (float)cl.time + 0.01f; } else if ((ent.model.flags & q_shared.EF_GRENADE) != 0) { R_RocketTrail(ref oldorg, ref ent.origin, 1); } else if ((ent.model.flags & q_shared.EF_TRACER3) != 0) { R_RocketTrail(ref oldorg, ref ent.origin, 6); } ent.forcelink = false; if (i == cl.viewentity && chase_active.value == 0) { continue; } if (cl_numvisedicts < q_shared.MAX_VISEDICTS) { cl_visedicts[cl_numvisedicts] = ent; cl_numvisedicts++; } } }