public void Initialization() { mathlib = new MathLib(); }
/// <summary> /// SV_PushMove /// </summary> private void PushMove(MemoryEdict pusher, float movetime) { if (pusher.v.velocity == Vector3.Zero) { pusher.v.ltime += movetime; return; } Vector3 move, mins, maxs; MathLib.VectorScale(ref pusher.v.velocity, movetime, out move); MathLib.VectorAdd(ref pusher.v.absmin, ref move, out mins); MathLib.VectorAdd(ref pusher.v.absmax, ref move, out maxs); var pushorig = pusher.v.origin; var moved_edict = new MemoryEdict[QDef.MAX_EDICTS]; var moved_from = new Vector3[QDef.MAX_EDICTS]; // move the pusher to it's final position MathLib.VectorAdd(ref pusher.v.origin, ref move, out pusher.v.origin); pusher.v.ltime += movetime; this.LinkEdict(pusher, false); // see if any solid entities are inside the final position var num_moved = 0; for (var e = 1; e < this.sv.num_edicts; e++) { var check = this.sv.edicts[e]; if (check.free) { continue; } if (check.v.movetype == Movetypes.MOVETYPE_PUSH || check.v.movetype == Movetypes.MOVETYPE_NONE || check.v.movetype == Movetypes.MOVETYPE_NOCLIP) { continue; } // if the entity is standing on the pusher, it will definately be moved if (!((( int )check.v.flags & EdictFlags.FL_ONGROUND) != 0 && this.ProgToEdict(check.v.groundentity) == pusher)) { if (check.v.absmin.X >= maxs.X || check.v.absmin.Y >= maxs.Y || check.v.absmin.Z >= maxs.Z || check.v.absmax.X <= mins.X || check.v.absmax.Y <= mins.Y || check.v.absmax.Z <= mins.Z) { continue; } // see if the ent's bbox is inside the pusher's final position if (this.TestEntityPosition(check) == null) { continue; } } // remove the onground flag for non-players if (check.v.movetype != Movetypes.MOVETYPE_WALK) { check.v.flags = ( int )check.v.flags & ~EdictFlags.FL_ONGROUND; } var entorig = check.v.origin; moved_from[num_moved] = entorig; moved_edict[num_moved] = check; num_moved++; // try moving the contacted entity pusher.v.solid = Solids.SOLID_NOT; this.PushEntity(check, ref move); pusher.v.solid = Solids.SOLID_BSP; // if it is still inside the pusher, block var block = this.TestEntityPosition(check); if (block != null) { // fail the move if (check.v.mins.X == check.v.maxs.X) { continue; } if (check.v.solid == Solids.SOLID_NOT || check.v.solid == Solids.SOLID_TRIGGER) { // corpse check.v.mins.X = check.v.mins.Y = 0; check.v.maxs = check.v.mins; continue; } check.v.origin = entorig; this.LinkEdict(check, true); pusher.v.origin = pushorig; this.LinkEdict(pusher, false); pusher.v.ltime -= movetime; // if the pusher has a "blocked" function, call it // otherwise, just stay in place until the obstacle is gone if (pusher.v.blocked != 0) { this.Host.Programs.GlobalStruct.self = this.EdictToProg(pusher); this.Host.Programs.GlobalStruct.other = this.EdictToProg(check); this.Host.Programs.Execute(pusher.v.blocked); } // move back any entities we already moved for (var i = 0; i < num_moved; i++) { moved_edict[i].v.origin = moved_from[i]; this.LinkEdict(moved_edict[i], false); } return; } } }
public string Multiply(decimal valueone, decimal valuetwo) { return($"{MathLib.Multiply(valueone, valuetwo)}"); }
public string Ceiling(double number) { return($"{MathLib.Ceiling(number)}"); }
protected override void ExecuteSpecialB() { AudioManager.PlayClipByName("Shot2"); PolarityReverser.Spawn(transform.position + MathLib.FromPolar(Player.Radius + PolarityReverser.Radius, Player.TurretAngle).ToVector3(), Player.TurretAngle, Player.shotSpeed); }
public string Add(decimal valueone, decimal valuetwo) { return($"{MathLib.Add(valueone, valuetwo)}"); }
protected TimeBubbleSpawner ShootSlowBubble() { AudioManager.PlayClipByName("Shot1"); return(TimeBubbleSpawner.Spawn(transform.position + MathLib.FromPolar(Radius + TimeBubbleSpawner.Radius, TurretAngle).ToVector3(), true, TurretAngle, shotSpeed, 5, timeBubbleLimits)); }
/// <summary> /// Creates a global environment with all the base modules registered and /// some default values set. /// </summary> /// <returns></returns> public static LuaTable CreateGlobalEnviroment(bool createBaseLib = true, bool createStringLib = true, bool createTableLib = true, bool createOSLib = true, bool createIOLib = true, bool createFileLib = true, bool createMathLib = true, bool createScriptLib = true, bool createWinFormsLib = true, bool createConsoleLib = true, bool createCoroutineLib = true, bool createPackageLib = true, bool createClassLib = true, bool createFileSystemLib = true) { LuaTable global = new LuaTable(); // Register Lua Modules if (createBaseLib) { BaseLib.RegisterFunctions(global); } if (createStringLib) { StringLib.RegisterModule(global); } if (createTableLib) { TableLib.RegisterModule(global); } if (createIOLib) { IOLib.RegisterModule(global); } if (createFileLib) { FileLib.RegisterModule(global); } if (createMathLib) { MathLib.RegisterModule(global); } if (createOSLib) { OSLib.RegisterModule(global); } if (createScriptLib) { ScriptLib.RegisterModule(global); } if (createWinFormsLib) { WinFormLib.RegisterModule(global); } if (createConsoleLib) { ConsoleLib.RegisterModule(global); } if (createCoroutineLib) { CoroutineLib.RegisterModule(global); } if (createPackageLib) { PackageLib.RegisterModule(global); } if (createClassLib) { ClassLib.RegisterModule(global); } if (createFileSystemLib) { FileSystemLib.RegisterModule(global); } global.SetNameValue("_WORKDIR", new LuaString(Application.StartupPath + "\\")); global.SetNameValue("_VERSION", new LuaString("Sharp Lua 1.1")); global.SetNameValue("_G", global); if (createPackageLib) { // set package.preload table LuaTable preload = (LuaTable)(global.GetValue("package") as LuaTable).GetValue("preload"); if (createStringLib) { preload.SetNameValue("string", (LuaTable)global.GetValue("string")); } if (createTableLib) { preload.SetNameValue("table", (LuaTable)global.GetValue("table")); } if (createIOLib) { preload.SetNameValue("io", (LuaTable)global.GetValue("io")); } if (createFileLib) { preload.SetNameValue("file", (LuaTable)global.GetValue("file")); } if (createMathLib) { preload.SetNameValue("math", (LuaTable)global.GetValue("math")); } if (createOSLib) { preload.SetNameValue("os", (LuaTable)global.GetValue("os")); } if (createScriptLib) { preload.SetNameValue("script", (LuaTable)global.GetValue("script")); } if (createWinFormsLib) { preload.SetNameValue("WinForms", (LuaTable)global.GetValue("WinForms")); } if (createConsoleLib) { preload.SetNameValue("console", (LuaTable)global.GetValue("console")); } if (createCoroutineLib) { preload.SetNameValue("coroutine", (LuaTable)global.GetValue("coroutine")); } if (createPackageLib) // wait a second... { preload.SetNameValue("package", (LuaTable)global.GetValue("package")); } if (createClassLib) { preload.SetNameValue("class", (LuaTable)global.GetValue("class")); } if (createFileSystemLib) { preload.SetNameValue("filesystem", (LuaTable)global.GetValue("filesystem")); } } if (createFileSystemLib) { FileSystemLib.currentDir = global.GetValue("_WORKDIR").ToString(); } GlobalEnvironment = global; return(global); }
public void Update(float dt) { SecPassed += dt; while (SecPassed > NextSpawnIn) { //Debug.WriteLine(ActiveParticles.Count); if (ActiveParticles.Count < Budget) { // Spawn a particle Vector2 StartDirection = Vector2.Transform(SpawnDirection, Matrix.CreateRotationZ(MathLib.LinearInterpolate(SpawnNoiseAngle.X, SpawnNoiseAngle.Y, random.NextDouble()))); StartDirection.Normalize(); Vector2 EndDirection = StartDirection * MathLib.LinearInterpolate(EndSpeed.X, EndSpeed.Y, random.NextDouble()); StartDirection *= MathLib.LinearInterpolate(StartSpeed.X, StartSpeed.Y, random.NextDouble()); ActiveParticles.AddLast(new Particle( new Vector2(-5, MathLib.Random(Parent.minY, Parent.maxY)), //RelPosition + Parent.Position, StartDirection, EndDirection, MathLib.LinearInterpolate(StartLife.X, StartLife.Y, random.NextDouble()), MathLib.LinearInterpolate(StartScale.X, StartScale.Y, random.NextDouble()), MathLib.LinearInterpolate(EndScale.X, EndScale.Y, random.NextDouble()), MathLib.LinearInterpolate(StartColor1, StartColor2, random.NextDouble()), MathLib.LinearInterpolate(EndColor1, EndColor2, random.NextDouble()), this) ); ActiveParticles.Last.Value.Update(SecPassed); } SecPassed -= NextSpawnIn; NextSpawnIn = MathLib.LinearInterpolate(SecPerSpawn.X, SecPerSpawn.Y, random.NextDouble()); } LinkedListNode <Particle> node = ActiveParticles.First; while (node != null) { bool isAlive = node.Value.Update(dt); node = node.Next; if (!isAlive) { if (node == null) { ActiveParticles.RemoveLast(); } else { ActiveParticles.Remove(node.Previous); } } } }
/// <summary> /// Calcula parâmetros da transformação. /// </summary> private void btnProximo_Click(object sender, EventArgs e) { PointF[] targetPoints = new PointF[this.pointsList.Count]; PointF[] sourcePoints = new PointF[this.pointsList.Count]; Cursor.Current = Cursors.WaitCursor; // pontos do sistema de origem for (int i = 0; i < this.pointsList.Count; ++i) { sourcePoints[i] = new PointF((float)this.pointsList[i].X, (float)this.pointsList[i].Y); } // pontos do sistema de destino try { if (this.pointsList.Count == 6) { string[] refPoint = ConfigurationManager.AppSettings["6pt_RefPoint1"].Split(new char[] { ',' }); targetPoints[0] = new PointF(float.Parse(refPoint[0]), float.Parse(refPoint[1])); refPoint = ConfigurationManager.AppSettings["6pt_RefPoint2"].Split(new char[] { ',' }); targetPoints[1] = new PointF(float.Parse(refPoint[0]), float.Parse(refPoint[1])); refPoint = ConfigurationManager.AppSettings["6pt_RefPoint3"].Split(new char[] { ',' }); targetPoints[2] = new PointF(float.Parse(refPoint[0]), float.Parse(refPoint[1])); refPoint = ConfigurationManager.AppSettings["6pt_RefPoint4"].Split(new char[] { ',' }); targetPoints[3] = new PointF(float.Parse(refPoint[0]), float.Parse(refPoint[1])); refPoint = ConfigurationManager.AppSettings["6pt_RefPoint5"].Split(new char[] { ',' }); targetPoints[4] = new PointF(float.Parse(refPoint[0]), float.Parse(refPoint[1])); refPoint = ConfigurationManager.AppSettings["6pt_RefPoint6"].Split(new char[] { ',' }); targetPoints[5] = new PointF(float.Parse(refPoint[0]), float.Parse(refPoint[1])); } else { string[] refPoint = ConfigurationManager.AppSettings["12pt_RefPoint1"].Split(new char[] { ',' }); targetPoints[0] = new PointF(float.Parse(refPoint[0]), float.Parse(refPoint[1])); refPoint = ConfigurationManager.AppSettings["12pt_RefPoint2"].Split(new char[] { ',' }); targetPoints[1] = new PointF(float.Parse(refPoint[0]), float.Parse(refPoint[1])); refPoint = ConfigurationManager.AppSettings["12pt_RefPoint3"].Split(new char[] { ',' }); targetPoints[2] = new PointF(float.Parse(refPoint[0]), float.Parse(refPoint[1])); refPoint = ConfigurationManager.AppSettings["12pt_RefPoint4"].Split(new char[] { ',' }); targetPoints[3] = new PointF(float.Parse(refPoint[0]), float.Parse(refPoint[1])); refPoint = ConfigurationManager.AppSettings["12pt_RefPoint5"].Split(new char[] { ',' }); targetPoints[4] = new PointF(float.Parse(refPoint[0]), float.Parse(refPoint[1])); refPoint = ConfigurationManager.AppSettings["12pt_RefPoint6"].Split(new char[] { ',' }); targetPoints[5] = new PointF(float.Parse(refPoint[0]), float.Parse(refPoint[1])); refPoint = ConfigurationManager.AppSettings["12pt_RefPoint7"].Split(new char[] { ',' }); targetPoints[6] = new PointF(float.Parse(refPoint[0]), float.Parse(refPoint[1])); refPoint = ConfigurationManager.AppSettings["12pt_RefPoint8"].Split(new char[] { ',' }); targetPoints[7] = new PointF(float.Parse(refPoint[0]), float.Parse(refPoint[1])); refPoint = ConfigurationManager.AppSettings["12pt_RefPoint9"].Split(new char[] { ',' }); targetPoints[8] = new PointF(float.Parse(refPoint[0]), float.Parse(refPoint[1])); refPoint = ConfigurationManager.AppSettings["12pt_RefPoint10"].Split(new char[] { ',' }); targetPoints[9] = new PointF(float.Parse(refPoint[0]), float.Parse(refPoint[1])); refPoint = ConfigurationManager.AppSettings["12pt_RefPoint11"].Split(new char[] { ',' }); targetPoints[10] = new PointF(float.Parse(refPoint[0]), float.Parse(refPoint[1])); refPoint = ConfigurationManager.AppSettings["12pt_RefPoint12"].Split(new char[] { ',' }); targetPoints[11] = new PointF(float.Parse(refPoint[0]), float.Parse(refPoint[1])); } } catch { MessageBox.Show(this, this.resourceMgr.GetString("MSG0014"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); Cursor.Current = Cursors.Default; return; } // calcula parâmetros da transformação try { if (this.pointsList.Count == 6) { MathLib.CalcProjectiveTransfCoeffs6pt(out this.coeffTransf, ref sourcePoints, ref targetPoints); } else { MathLib.CalcProjectiveTransfCoeffs12pt(out this.coeffTransf, ref sourcePoints, ref targetPoints); } } catch { MessageBox.Show(this, this.resourceMgr.GetString("MSG0015"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); Cursor.Current = Cursors.Default; return; } // modifica cursor Cursor.Current = Cursors.Default; // fecha o formulário Close(); }
public MathLibTests() { _mathLibImpl = new Mock <IMathLib>(); _mathLib = new MathLib(_mathLibImpl.Object); }
/// <summary> /// R_RocketTrail /// </summary> public void RocketTrail(Double time, ref Vector3 start, ref Vector3 end, Int32 type) { var vec = end - start; var len = MathLib.Normalize(ref vec); Int32 dec; if (type < 128) { dec = 3; } else { dec = 1; type -= 128; } while (len > 0) { len -= dec; var p = AllocParticle( ); if (p == null) { return; } p.vel = Vector3.Zero; p.die = ( Single )/*Host.Client.cl.time*/ time + 2; switch (type) { case 0: // rocket trail p.ramp = (MathLib.Random( ) & 3); p.color = ParticleDef._Ramp3[( Int32 )p.ramp]; p.type = ParticleType.Fire; p.org = new Vector3(start.X + ((MathLib.Random( ) % 6) - 3), start.Y + ((MathLib.Random( ) % 6) - 3), start.Z + ((MathLib.Random( ) % 6) - 3)); break; case 1: // smoke smoke p.ramp = (MathLib.Random( ) & 3) + 2; p.color = ParticleDef._Ramp3[( Int32 )p.ramp]; p.type = ParticleType.Fire; p.org = new Vector3(start.X + ((MathLib.Random( ) % 6) - 3), start.Y + ((MathLib.Random( ) % 6) - 3), start.Z + ((MathLib.Random( ) % 6) - 3)); break; case 2: // blood p.type = ParticleType.Gravity; p.color = 67 + (MathLib.Random( ) & 3); p.org = new Vector3(start.X + ((MathLib.Random( ) % 6) - 3), start.Y + ((MathLib.Random( ) % 6) - 3), start.Z + ((MathLib.Random( ) % 6) - 3)); break; case 3: case 5: // tracer p.die = ( Single )time + 0.5f; p.type = ParticleType.Static; if (type == 3) { p.color = 52 + ((_TracerCount & 4) << 1); } else { p.color = 230 + ((_TracerCount & 4) << 1); } _TracerCount++; p.org = start; if ((_TracerCount & 1) != 0) { p.vel.X = 30 * vec.Y; // Uze: why??? p.vel.Y = 30 * -vec.X; } else { p.vel.X = 30 * -vec.Y; p.vel.Y = 30 * vec.X; } break; case 4: // slight blood p.type = ParticleType.Gravity; p.color = 67 + (MathLib.Random( ) & 3); p.org = new Vector3(start.X + ((MathLib.Random( ) % 6) - 3), start.Y + ((MathLib.Random( ) % 6) - 3), start.Z + ((MathLib.Random( ) % 6) - 3)); len -= 3; break; case 6: // voor trail p.color = 9 * 16 + 8 + (MathLib.Random( ) & 3); p.type = ParticleType.Static; p.die = ( Single )time + 0.3f; p.org = new Vector3(start.X + ((MathLib.Random( ) % 15) - 8), start.Y + ((MathLib.Random( ) % 15) - 8), start.Z + ((MathLib.Random( ) % 15) - 8)); break; } start += vec; } }
/// <summary> /// R_BlobExplosion /// </summary> public void BlobExplosion(Double time, ref Vector3 org) { for (var i = 0; i < 1024; i++) { var p = AllocParticle( ); if (p == null) { return; } p.die = ( Single )(time + 1 + (MathLib.Random( ) & 8) * 0.05); if ((i & 1) != 0) { p.type = ParticleType.Blob; p.color = 66 + MathLib.Random( ) % 6; } else { p.type = ParticleType.Blob2; p.color = 150 + MathLib.Random( ) % 6; } p.org = org + new Vector3((MathLib.Random( ) % 32) - 16, (MathLib.Random( ) % 32) - 16, (MathLib.Random( ) % 32) - 16); p.vel = new Vector3((MathLib.Random( ) % 512) - 256, (MathLib.Random( ) % 512) - 256, (MathLib.Random( ) % 512) - 256); } }
/// <summary> /// R_ParticleExplosion2 /// </summary> public void ParticleExplosion(Double time, ref Vector3 org, Int32 colorStart, Int32 colorLength) { var colorMod = 0; for (var i = 0; i < 512; i++) { var p = AllocParticle( ); if (p == null) { return; } p.die = ( Single )(time + 0.3); p.color = colorStart + (colorMod % colorLength); colorMod++; p.type = ParticleType.Blob; p.org = org + new Vector3((MathLib.Random( ) % 32) - 16, (MathLib.Random( ) % 32) - 16, (MathLib.Random( ) % 32) - 16); p.vel = new Vector3((MathLib.Random( ) % 512) - 256, (MathLib.Random( ) % 512) - 256, (MathLib.Random( ) % 512) - 256); } }
/** * This method returns a scalar that is the ammount of feedback that needs to be added to a trajectory. It is a function of the * phase in the controller's state (between 0 and 1), the vector between the stance foot and the center of mass, and the velocity of * the center of mass. */ override public float getFeedbackContribution(SimBiController con, CWJoint j, float phi, Vector3 d, Vector3 v) { CWRigidBody theBody; //Vector3 tmpP; float offset = 0; if (j != null) { theBody = j.getChild(); } else { theBody = con.getCharacter().getRoot(); } //we might want to initialize it (or add to it) some default value in case we are trying to control its projection offset = 0; float dToUse = Vector3.Dot(MathLib.getComplexConjugate(theBody.getOrientation()) * con.getDoubleStanceCOMError(), feedbackProjectionAxis); if (dToUse < dMin) { dToUse = dMin; } if (dToUse > dMax) { dToUse = dMax; } float vToUse = Vector3.Dot(MathLib.getComplexConjugate(theBody.getOrientation()) * con.getComVelocity(), feedbackProjectionAxis); if (vToUse < vMin) { vToUse = vMin; } if (vToUse > vMax) { vToUse = vMax; } float err = (dToUse * cd - vToUse * cv + offset); float result = err * totalMultiplier; //if (j) // tprintf("%s gets: %lf\n", j->getName(), result); // else //tprintf("root gets: %lf\n", result); if (result < minFeedbackValue) { result = minFeedbackValue; } if (result > maxFeedbackValue) { result = maxFeedbackValue; } // if (j == NULL && cv > 0.4) // logPrint("%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", theBody->getLocalCoordinates(con->COMOffset).dotProductWith(feedbackProjectionAxis), dToUse, theBody->getLocalCoordinates(con->comVelocity).dotProductWith(feedbackProjectionAxis), vToUse, result, forceRatioWeight); return(result); }
void Awake() { joint = this.gameObject.GetComponent <ConfigurableJoint>(); this.setParent(joint.connectedBody.gameObject.GetComponent <CWRigidBody>()); this.setChild(this.gameObject.GetComponent <CWRigidBody>()); initialLocalRotation = this.transform.localRotation; initialWorldRotation = this.transform.rotation; Vector3 localScale = this.gameObject.transform.root.transform.localScale; Vector3 anchorPos = new Vector3(joint.anchor.x * localScale.x, joint.anchor.y * localScale.y, joint.anchor.z * localScale.z); Vector3 worldAnchorPos = this.gameObject.transform.position + this.gameObject.transform.rotation * anchorPos; this.pJPos = MathLib.getComplexConjugate(joint.connectedBody.rotation) * worldAnchorPos - MathLib.getComplexConjugate(joint.connectedBody.rotation) * joint.connectedBody.position; this.cJPos = anchorPos; //pJPos.z = 0; //cJPos.z = 0; //Debug.Log(jName +" === "+pJPos+" ==== "+cJPos); this.child.GetComponent <Rigidbody>().centerOfMass = anchorPos; }
/// <summary> /// SV_CheckBottom /// </summary> public Boolean CheckBottom(MemoryEdict ent) { Vector3f mins, maxs; MathLib.VectorAdd(ref ent.v.origin, ref ent.v.mins, out mins); MathLib.VectorAdd(ref ent.v.origin, ref ent.v.maxs, out maxs); // if all of the points under the corners are solid world, don't bother // with the tougher checks // the corners must be within 16 of the midpoint Vector3 start; start.Z = mins.z - 1; for (var x = 0; x <= 1; x++) { for (var y = 0; y <= 1; y++) { start.X = (x != 0 ? maxs.x : mins.x); start.Y = (y != 0 ? maxs.y : mins.y); if (PointContents(ref start) != ( Int32 )Q1Contents.Solid) { goto RealCheck; } } } return(true); // we got out easy RealCheck: // // check it for real... // start.Z = mins.z; // the midpoint must be within 16 of the bottom start.X = (mins.x + maxs.x) * 0.5f; start.Y = (mins.y + maxs.y) * 0.5f; var stop = start; stop.Z -= 2 * STEPSIZE; var trace = Move(ref start, ref Utilities.ZeroVector, ref Utilities.ZeroVector, ref stop, 1, ent); if (trace.fraction == 1.0) { return(false); } var mid = trace.endpos.Z; var bottom = mid; // the corners must be within 16 of the midpoint for (var x = 0; x <= 1; x++) { for (var y = 0; y <= 1; y++) { start.X = stop.X = (x != 0 ? maxs.x : mins.x); start.Y = stop.Y = (y != 0 ? maxs.y : mins.y); trace = Move(ref start, ref Utilities.ZeroVector, ref Utilities.ZeroVector, ref stop, 1, ent); if (trace.fraction != 1.0 && trace.endpos.Z > bottom) { bottom = trace.endpos.Z; } if (trace.fraction == 1.0 || mid - trace.endpos.Z > STEPSIZE) { return(false); } } } return(true); }
protected override void ExecuteSpecialX() { AudioManager.PlayClipByName("Shot2"); ExtraDamageMarker.Spawn(transform.position + MathLib.FromPolar(Player.Radius + ExtraDamageMarker.Radius, Player.TurretAngle).ToVector3(), Player.TurretAngle, Player.shotSpeed, this); }
/// <summary> /// SV_movestep /// Called by monster program code. /// The move will be adjusted for slopes and stairs, but if the move isn't /// possible, no move is done, false is returned, and /// pr_global_struct.trace_normal is set to the normal of the blocking wall /// </summary> public Boolean MoveStep(MemoryEdict ent, ref Vector3f move, Boolean relink) { Trace_t trace; // try the move var oldorg = ent.v.origin; Vector3f neworg; MathLib.VectorAdd(ref ent.v.origin, ref move, out neworg); // flying monsters don't step up if ((( Int32 )ent.v.flags & (EdictFlags.FL_SWIM | EdictFlags.FL_FLY)) != 0) { // try one move with vertical motion, then one without for (var i = 0; i < 2; i++) { MathLib.VectorAdd(ref ent.v.origin, ref move, out neworg); var enemy = ProgToEdict(ent.v.enemy); if (i == 0 && enemy != sv.edicts[0]) { var dz = ent.v.origin.z - enemy.v.origin.z; if (dz > 40) { neworg.z -= 8; } if (dz < 30) { neworg.z += 8; } } trace = Move(ref ent.v.origin, ref ent.v.mins, ref ent.v.maxs, ref neworg, 0, ent); if (trace.fraction == 1) { if ((( Int32 )ent.v.flags & EdictFlags.FL_SWIM) != 0 && PointContents(ref trace.endpos) == ( Int32 )Q1Contents.Empty) { return(false); // swim monster left water } MathLib.Copy(ref trace.endpos, out ent.v.origin); if (relink) { LinkEdict(ent, true); } return(true); } if (enemy == sv.edicts[0]) { break; } } return(false); } // push down from a step height above the wished position neworg.z += STEPSIZE; var end = neworg; end.z -= STEPSIZE * 2; trace = Move(ref neworg, ref ent.v.mins, ref ent.v.maxs, ref end, 0, ent); if (trace.allsolid) { return(false); } if (trace.startsolid) { neworg.z -= STEPSIZE; trace = Move(ref neworg, ref ent.v.mins, ref ent.v.maxs, ref end, 0, ent); if (trace.allsolid || trace.startsolid) { return(false); } } if (trace.fraction == 1) { // if monster had the ground pulled out, go ahead and fall if ((( Int32 )ent.v.flags & EdictFlags.FL_PARTIALGROUND) != 0) { MathLib.VectorAdd(ref ent.v.origin, ref move, out ent.v.origin); if (relink) { LinkEdict(ent, true); } ent.v.flags = ( Int32 )ent.v.flags & ~EdictFlags.FL_ONGROUND; return(true); } return(false); // walked off an edge } // check point traces down for dangling corners MathLib.Copy(ref trace.endpos, out ent.v.origin); if (!CheckBottom(ent)) { if ((( Int32 )ent.v.flags & EdictFlags.FL_PARTIALGROUND) != 0) { // entity had floor mostly pulled out from underneath it // and is trying to correct if (relink) { LinkEdict(ent, true); } return(true); } ent.v.origin = oldorg; return(false); } if ((( Int32 )ent.v.flags & EdictFlags.FL_PARTIALGROUND) != 0) { ent.v.flags = ( Int32 )ent.v.flags & ~EdictFlags.FL_PARTIALGROUND; } ent.v.groundentity = EdictToProg(trace.ent); // the move is ok if (relink) { LinkEdict(ent, true); } return(true); }
static void Main(string[] args) { MathLib obj = new MathLib(); Console.WriteLine("****************************************************Math Application****************************************************"); Console.WriteLine("If you want to enter numbers in Integer Press 1 or Press 2 for double :"); int c = Convert.ToInt32(Console.ReadLine()); if (c == 1) { Console.WriteLine("Enter Two Integer Numbers :"); Console.Write("Number 1: "); int num1 = Convert.ToInt32(Console.ReadLine()); Console.Write("Number 2: "); int num2 = Convert.ToInt32(Console.ReadLine()); Console.Write("Press Corrosponding Numbers : \n Addition => 1 \t Substraction => 2 \t Multiplication => 3 \t Division => 4 \t Modulus Operation => 5 \t Your choice : "); int choice = Convert.ToInt32(Console.ReadLine()); switch (choice) { case 1: int sum = obj.Add(num1, num2); Console.WriteLine("Addition of two numbers is : " + sum); break; case 2: int sub = obj.Subtract(num1, num2); Console.WriteLine("Subtraction of two numbers is : " + sub); break; case 3: int mul = obj.Multiply(num1, num2); Console.WriteLine("Division of two numbers is : " + mul); break; case 4: int div = obj.Divide(num1, num2); Console.WriteLine("Multiplication of two numbers is : " + div); break; case 5: int mod = obj.Modulus(num1, num2); Console.WriteLine("Modulus of two numbers is : " + mod); break; default: Console.WriteLine("The Input is wrong."); break; } } else if (c == 2) { Console.WriteLine("Enter Two Floating Numbers :"); Console.Write("Number 1: "); double num1 = Convert.ToDouble(Console.ReadLine()); Console.Write("Number 2: "); double num2 = Convert.ToDouble(Console.ReadLine()); Console.Write("Press Corrosponding Numbers : \n Addition => 1 \t Substraction => 2 \t Multiplication => 3 \t Division => 4 \t Modulus Operation => 5 \t Your choice : "); int choice = Convert.ToInt32(Console.ReadLine()); switch (choice) { case 1: double sum = obj.FAdd(num1, num2); Console.WriteLine("Addition of two numbers is : " + sum); break; case 2: double sub = obj.FSubtract(num1, num2); Console.WriteLine("Substraction of two numbers is : " + sub); break; case 3: double mul = obj.FMultiply(num1, num2); Console.WriteLine("Multiplication of two numbers is : " + mul); break; case 4: double div = obj.FDivide(num1, num2); Console.WriteLine("Division of two numbers is : " + div); break; case 5: double mod = obj.FModulus(num1, num2); Console.WriteLine("Modulus of two numbers is : " + mod); break; default: Console.WriteLine("The Input is wrong."); break; } } else { Console.WriteLine("The Entered input is wrong."); } Console.ReadKey(); }
protected override void ExecuteSpecialX() { transform.position += MathLib.FromPolar(blinkDistance, Player.TurretAngle).ToVector3(); }
public string Subtract(decimal valueone, decimal valuetwo) { return($"{MathLib.Subtract(valueone, valuetwo)}"); }
/// <summary> /// CL_ParseTEnt /// </summary> private void ParseTempEntity() { Vector3 pos; dlight_t dl; var type = Host.Network.Reader.ReadByte(); switch (type) { case ProtocolDef.TE_WIZSPIKE: // spike hitting wall pos = Host.Network.Reader.ReadCoords(); Host.RenderContext.Particles.RunParticleEffect(Host.Client.cl.time, ref pos, ref Utilities.ZeroVector, 20, 30); Host.Sound.StartSound(-1, 0, _SfxWizHit, ref pos, 1, 1); break; case ProtocolDef.TE_KNIGHTSPIKE: // spike hitting wall pos = Host.Network.Reader.ReadCoords(); Host.RenderContext.Particles.RunParticleEffect(Host.Client.cl.time, ref pos, ref Utilities.ZeroVector, 226, 20); Host.Sound.StartSound(-1, 0, _SfxKnigtHit, ref pos, 1, 1); break; case ProtocolDef.TE_SPIKE: // spike hitting wall pos = Host.Network.Reader.ReadCoords(); #if GLTEST Test_Spawn(pos); #else Host.RenderContext.Particles.RunParticleEffect(Host.Client.cl.time, ref pos, ref Utilities.ZeroVector, 0, 10); #endif if ((MathLib.Random() % 5) != 0) { Host.Sound.StartSound(-1, 0, _SfxTink1, ref pos, 1, 1); } else { var rnd = MathLib.Random() & 3; if (rnd == 1) { Host.Sound.StartSound(-1, 0, _SfxRic1, ref pos, 1, 1); } else if (rnd == 2) { Host.Sound.StartSound(-1, 0, _SfxRic2, ref pos, 1, 1); } else { Host.Sound.StartSound(-1, 0, _SfxRic3, ref pos, 1, 1); } } break; case ProtocolDef.TE_SUPERSPIKE: // super spike hitting wall pos = Host.Network.Reader.ReadCoords(); Host.RenderContext.Particles.RunParticleEffect(Host.Client.cl.time, ref pos, ref Utilities.ZeroVector, 0, 20); if ((MathLib.Random() % 5) != 0) { Host.Sound.StartSound(-1, 0, _SfxTink1, ref pos, 1, 1); } else { var rnd = MathLib.Random() & 3; if (rnd == 1) { Host.Sound.StartSound(-1, 0, _SfxRic1, ref pos, 1, 1); } else if (rnd == 2) { Host.Sound.StartSound(-1, 0, _SfxRic2, ref pos, 1, 1); } else { Host.Sound.StartSound(-1, 0, _SfxRic3, ref pos, 1, 1); } } break; case ProtocolDef.TE_GUNSHOT: // bullet hitting wall pos = Host.Network.Reader.ReadCoords(); Host.RenderContext.Particles.RunParticleEffect(Host.Client.cl.time, ref pos, ref Utilities.ZeroVector, 0, 20); break; case ProtocolDef.TE_EXPLOSION: // rocket explosion pos = Host.Network.Reader.ReadCoords(); Host.RenderContext.Particles.ParticleExplosion(Host.Client.cl.time, ref pos); dl = AllocDlight(0); dl.origin = pos; dl.radius = 350; dl.die = ( Single )cl.time + 0.5f; dl.decay = 300; Host.Sound.StartSound(-1, 0, _SfxRExp3, ref pos, 1, 1); break; case ProtocolDef.TE_TAREXPLOSION: // tarbaby explosion pos = Host.Network.Reader.ReadCoords(); Host.RenderContext.Particles.BlobExplosion(Host.Client.cl.time, ref pos); Host.Sound.StartSound(-1, 0, _SfxRExp3, ref pos, 1, 1); break; case ProtocolDef.TE_LIGHTNING1: // lightning bolts ParseBeam(Host.Model.ForName("progs/bolt.mdl", true, ModelType.mod_alias)); break; case ProtocolDef.TE_LIGHTNING2: // lightning bolts ParseBeam(Host.Model.ForName("progs/bolt2.mdl", true, ModelType.mod_alias)); break; case ProtocolDef.TE_LIGHTNING3: // lightning bolts ParseBeam(Host.Model.ForName("progs/bolt3.mdl", true, ModelType.mod_alias)); break; // PGM 01/21/97 case ProtocolDef.TE_BEAM: // grappling hook beam ParseBeam(Host.Model.ForName("progs/beam.mdl", true, ModelType.mod_alias)); break; // PGM 01/21/97 case ProtocolDef.TE_LAVASPLASH: pos = Host.Network.Reader.ReadCoords(); Host.RenderContext.Particles.LavaSplash(Host.Client.cl.time, ref pos); break; case ProtocolDef.TE_TELEPORT: pos = Host.Network.Reader.ReadCoords(); Host.RenderContext.Particles.TeleportSplash(Host.Client.cl.time, ref pos); break; case ProtocolDef.TE_EXPLOSION2: // color mapped explosion pos = Host.Network.Reader.ReadCoords(); var colorStart = Host.Network.Reader.ReadByte(); var colorLength = Host.Network.Reader.ReadByte(); Host.RenderContext.Particles.ParticleExplosion(Host.Client.cl.time, ref pos, colorStart, colorLength); dl = AllocDlight(0); dl.origin = pos; dl.radius = 350; dl.die = ( Single )cl.time + 0.5f; dl.decay = 300; Host.Sound.StartSound(-1, 0, _SfxRExp3, ref pos, 1, 1); break; default: Utilities.Error("CL_ParseTEnt: bad type"); break; } }
public string Divide(decimal valueone, decimal valuetwo) { return($"{MathLib.Divide(valueone, valuetwo)}"); }
// CL_UpdateTEnts private void UpdateTempEntities() { _NumTempEntities = 0; // update lightning for (var i = 0; i < ClientDef.MAX_BEAMS; i++) { var b = _Beams[i]; if (b.model == null || b.endtime < cl.time) { continue; } // if coming from the player, update the start position if (b.entity == cl.viewentity) { b.start = _Entities[cl.viewentity].origin; } // calculate pitch and yaw var dist = b.end - b.start; Single yaw, pitch, forward; if (dist.Y == 0 && dist.X == 0) { yaw = 0; if (dist.Z > 0) { pitch = 90; } else { pitch = 270; } } else { yaw = ( Int32 )(Math.Atan2(dist.Y, dist.X) * 180 / Math.PI); if (yaw < 0) { yaw += 360; } forward = ( Single )Math.Sqrt(dist.X * dist.X + dist.Y * dist.Y); pitch = ( Int32 )(Math.Atan2(dist.Z, forward) * 180 / Math.PI); if (pitch < 0) { pitch += 360; } } // add new entities for the lightning var org = b.start; var d = MathLib.Normalize(ref dist); while (d > 0) { var ent = NewTempEntity(); if (ent == null) { return; } ent.origin = org; ent.model = b.model; ent.angles.X = pitch; ent.angles.Y = yaw; ent.angles.Z = MathLib.Random() % 360; org += dist * 30; // Uze: is this code bug (i is outer loop variable!!!) or what?????????????? //for (i=0 ; i<3 ; i++) // org[i] += dist[i]*30; d -= 30; } } }
public string Floor(double number) { return($"{MathLib.Floor(number)}"); }
public Runner(string[] args, string filename) { if (args.Length > 0) { string path = args[0]; StreamReader sr = new StreamReader(path, Encoding.Default); String line; string content = ""; while ((line = sr.ReadLine()) != null) { content += line.ToString() + "\n"; } const bool isLoadLib = true; const bool useArg = true; // try { Lua L = new Lua(); if (isLoadLib) { BaseLib.open(L); PackageLib.open(L); MathLib.open(L); OSLib.open(L); StringLib.open(L); TableLib.open(L); } if (useArg) { //FIXME: index may be minus (for example, arg[-1], before script file name) //@see http://www.ttlsa.com/lua/lua-install-and-lua-variable-ttlsa/ int narg = args.Length; LuaTable tbl = L.createTable(narg, narg); for (int i = 0; i < narg; i++) { L.rawSetI(tbl, i, args[i]); } L.setGlobal("arg", tbl); } int status = L.doString(content); if (status != 0) { object errObj = L.value(1); object tostring = L.getGlobal("tostring"); L.push(tostring); L.push(errObj); L.call(1, 1); string errObjStr = L.toString(L.value(-1)); throw new Exception("Error compiling : " + L.value(1)); } else { object result = L.value(1); object tostring_ = L.getGlobal("tostring"); L.push(tostring_); L.push(result); L.call(1, 1); string resultStr = L.toString(L.value(-1)); Console.WriteLine("Result >>> " + resultStr); } } // catch (Exception e) // { // Console.WriteLine(e); // } } else { Console.WriteLine("usage: {0} <filename>", filename); } }
/// <summary> /// SV_WaterMove /// </summary> private void WaterMove() { // // user intentions // var pangle = Utilities.ToVector(ref _Player.v.v_angle); MathLib.AngleVectors(ref pangle, out _Forward, out _Right, out _Up); var wishvel = _Forward * _Cmd.forwardmove + _Right * _Cmd.sidemove; if (_Cmd.forwardmove == 0 && _Cmd.sidemove == 0 && _Cmd.upmove == 0) { wishvel.Z -= 60; // drift towards bottom } else { wishvel.Z += _Cmd.upmove; } var wishspeed = wishvel.Length; var maxSpeed = Host.Cvars.MaxSpeed.Get <Single>(); if (wishspeed > maxSpeed) { wishvel *= maxSpeed / wishspeed; wishspeed = maxSpeed; } wishspeed *= 0.7f; // // water friction // Single newspeed, speed = MathLib.Length(ref _Player.v.velocity); if (speed != 0) { newspeed = ( Single )(speed - Host.FrameTime * speed * Host.Cvars.Friction.Get <Single>( )); if (newspeed < 0) { newspeed = 0; } MathLib.VectorScale(ref _Player.v.velocity, newspeed / speed, out _Player.v.velocity); } else { newspeed = 0; } // // water acceleration // if (wishspeed == 0) { return; } var addspeed = wishspeed - newspeed; if (addspeed <= 0) { return; } MathLib.Normalize(ref wishvel); var accelspeed = ( Single )(Host.Cvars.Accelerate.Get <Single>( ) * wishspeed * Host.FrameTime); if (accelspeed > addspeed) { accelspeed = addspeed; } wishvel *= accelspeed; _Player.v.velocity.x += wishvel.X; _Player.v.velocity.y += wishvel.Y; _Player.v.velocity.z += wishvel.Z; }
private void CellViewBind() { _dbUtil = new DBLib(); string qryString = "Select gCode_id,gName,modelNbr,custPrice,newPrice,transPrice,joinPrice,USimmPrice,Mfger,keywords,specSummary,gOrder,status,fruitRate,postStart,postEnd,point,reserveFund,registerDT,updateDT,register,IPaddress" + " FROM t_GoodsCell WHERE gCode_id=" + GdsCellBaseLib.Self.gCode_id; qryString += ";Select fileName,fileDESC" + " FROM t_GdsCellFiles WHERE gCode_id=" + GdsCellBaseLib.Self.gCode_id + " AND fileName LIKE 'S2%'"; qryString += ";Select scOptions, currStock " + " FROM t_CellStockCurrent WHERE gCode_id=" + GdsCellBaseLib.Self.gCode_id + " AND StkEnable = 1" + " ORDER BY scOrder DESC"; SqlDataReader drGoods = _dbUtil.MyExecuteReader(qryString); if (drGoods.Read()) //기본정보 { //this.fvCell.Controls[gCode_id]// this.gCode_id.Text = drGoods["gCode_id"].ToString(); this.modelNbr.Text = drGoods["modelNbr"].ToString(); this.gName.Text = drGoods["gName"].ToString(); Title = String.Format("서비스정보 > 휴대폰정보 > {0}({1})", gName.Text, modelNbr.Text); this.keywords.Text = drGoods["keywords"].ToString(); this.custPrice.Text = MathLib.GetComma(drGoods["custPrice"]); this.newPrice.Text = MathLib.GetComma(drGoods["newPrice"]); this.transPrice.Text = MathLib.GetComma(drGoods["transPrice"]); this.joinPrice.Text = MathLib.GetComma(drGoods["joinPrice"]); this.USimmPrice.Text = MathLib.GetComma(drGoods["USimmPrice"]); this.Mfger.Text = drGoods["Mfger"].ToString(); //this.fruitRate.Text = MathLib.GetComma(drGoods["fruitRate"]); //this.gOrder.Text = MathLib.GetComma(drGoods["gOrder"]); this.point.Text = MathLib.GetComma(drGoods["point"]); this.reserveFund.Text = MathLib.GetComma(drGoods["reserveFund"]); //this.registerDT.Text = drGoods["registerDT"].ToString(); //this.updateDT.Text = drGoods["updateDT"].ToString(); //this.register.Text = drGoods["register"].ToString(); this.specSummary.Text = drGoods["specSummary"].ToString(); this.status.Text = GdsCellBaseLib.Self.GetStatusText(drGoods["status"]); if (drGoods["status"].ToString() == "10") { hlAskPrice.Visible = true; hlAskPrice.NavigateUrl = "/CustomerServices/QnA/QnA_Master.aspx?qgrp=quota&qgi=" + Server.UrlEncode(modelNbr.Text); } hlAskGoods.NavigateUrl = "/CustomerServices/QnA/QnA_Master.aspx?qnaCX=form&qgrp=gds&qgi=" + Server.UrlEncode(modelNbr.Text); //Response.Write(drGoods["status"].ToString()); //게시기간 string postEnd = drGoods["postEnd"].ToString(); //게시종료일 this.litDisplayTerm.Text = drGoods["postStart"].ToString() + " ~ "; if (postEnd != "") { this.litDisplayTerm.Text += postEnd; } else { this.litDisplayTerm.Text += "영구게시"; } //특정상품셋팅 if (GdsCellBaseLib.Self.IsPopularGoods(this.gCode_id.Text)) { this.GoodsClass.Text = "인기상품, "; imgPopular.ImageUrl = "/Shop/Images/popular.gif"; imgPopular.Visible = true; } SortedList slSG = GdsCellBaseLib.Self.GetSpecificGcID(this.gCode_id.Text); for (int i = 0; i < slSG.Count; i++) { //Response.Write(String.Format("\t{0}:\t{1}", slSG.GetKey(i), slSG.GetByIndex(i))); this.GoodsClass.Text += slSG.GetByIndex(i) + ", "; if (slSG.GetKey(i).ToString() == "1") { imgRecommand.Visible = true; } else if (slSG.GetKey(i).ToString() == "3") { imgBest.Visible = true; } else if (slSG.GetKey(i).ToString() == "5") { imgSpecial.Visible = true; } } if (GoodsClass.Text.Length > 2) { this.GoodsClass.Text = GoodsClass.Text.Substring(0, GoodsClass.Text.Length - 2); } //상품데이터 폴더 _GdsUploadDir = SystemConfig.GetValue("GdsUploadDir") + "GC" + this.gCode_id.Text + "/"; this.hlLargeImages.NavigateUrl = "javascript:GoLargeImageView('" + GdsCellBaseLib.Self.gCode_id + "');"; //htmlPage페이지확인 string htmlPage = ""; //if (drGoods["htmlPage"].ToString() != "") // htmlPage = drGoods["htmlPage"].ToString(); //else htmlPage = _GdsUploadDir + "Detail_" + gCode_id.Text + ".html"; //Detail.html확인 if (FileLib.Self.FileExist(htmlPage)) { pnDetailedHTML.Visible = true; //WebUtil.CurrentResponse.Write("htmlPage = " + htmlPage); this.litHTML.Text = FileLib.Self.LoadHtmlPage(Application["BaseHref"].ToString(), htmlPage); //this.litHTML.Text = GdsCellBaseLib.Self.LoadHtmlPage(Application["BaseHref"].ToString(), htmlPage); } //else if (drGoods["htmlPage"].ToString() != "") //{ // pnDetailedHTML.Visible = true; // this.litHTML.Text = "파일경로에러"; //} //string strSendonemail = this.MbrName.Text + " <" + this.hlEmail.Text +">;"; //this.hlEmail.NavigateUrl = "../Mine/Mail/MailForm.aspx?s=" + strSendonemail; if (drGoods.NextResult()) //이미지파일정보 { if (drGoods.HasRows) { this.hlLargeImages.Visible = true; this.dlGdsImages.DataSource = drGoods; this.dlGdsImages.DataBind(); //바인딩하기 전에 drGds.Read();하지 말것. } } if (drGoods.NextResult()) //스탁정보 { while (drGoods.Read()) { this.currStock.Text += drGoods["scOptions"].ToString() + " => " + drGoods["currStock"].ToString() + "<br> "; } if (this.currStock.Text == "") { this.currStock.Text = "재고관리대상아님"; } } //DR,DB닫기 drGoods.Close(); _dbUtil.SqlConnection.Close(); } else { CompanyItems_CIMasterPage_wide master = this.Master; //MainMasterPage master = (MainMasterPage)this.Master; master.FindControl("ucClientMessage").Visible = true; master.LitMsgText = "The Goods Don't Exist!!"; master.LitDetailsText = "요구하신 상품의 정보가 존재하지 않습니다."; master.HlBackVisible = true; tblCellView.Visible = false; } }
protected override MosaicTile NewTile(int tileX, int tileZ, MathLib.Vector3 worldLocMM) { return new DataMosaicTile(this, desc.TileSizeSamples, desc.MetersPerSample, tileX, tileZ, worldLocMM); }
/// <summary> /// R_TeleportSplash /// </summary> public void TeleportSplash(Double time, ref Vector3 org) { for (var i = -16; i < 16; i += 4) { for (var j = -16; j < 16; j += 4) { for (var k = -24; k < 32; k += 4) { var p = AllocParticle( ); if (p == null) { return; } p.die = ( Single )(time + 0.2 + (MathLib.Random( ) & 7) * 0.02); p.color = 7 + (MathLib.Random( ) & 7); p.type = ParticleType.SlowGravity; var dir = new Vector3(j * 8, i * 8, k * 8); p.org = org + new Vector3(i + (MathLib.Random( ) & 3), j + (MathLib.Random( ) & 3), k + (MathLib.Random( ) & 3)); MathLib.Normalize(ref dir); Single vel = 50 + (MathLib.Random( ) & 63); p.vel = dir * vel; } } } }