Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //About:
- // This is basically for particles but also has rotation because it started of as a class
- // that was only for holding some data that would be shared between almost everything (position + rotation)
- // it was easier to just convert this into particles than to write another one entirely.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Audio;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.GamerServices;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using Microsoft.Xna.Framework.Media;
- namespace gphysics
- {
- public class Particle
- {
- protected Vector3 mPosition;
- protected Vector3 mVelocity;
- protected Vector3 mAcceleration;
- protected Vector3 mForceAccum;
- //Added variable to allow us to not use damping because it makes space physics not work.
- public static bool mUseDamping = true;
- protected double mDamping;
- protected double mInverseMass;
- protected Vector3 mRotation;
- public Particle()
- {
- //I'm lazy so I want mDamping to have a default value.
- mDamping = 0.9999999999999999999999999999999999f;
- }
- public Vector3 GetPosition()
- {
- return mPosition;
- }
- public void SetPosition(Vector3 Position)
- {
- mPosition = Position;
- }
- public void Move(Vector3 Movement)
- {
- mPosition += Movement;
- }
- public Vector3 GetVelocity()
- {
- return mVelocity;
- }
- public void SetVelocity(Vector3 Velocity)
- {
- mVelocity = Velocity;
- }
- public void AddVelocity(Vector3 AddedVel)
- {
- mVelocity += AddedVel;
- }
- public Vector3 GetAcceleration()
- {
- return mAcceleration;
- }
- public void SetAcceleration(Vector3 Acceleration)
- {
- mAcceleration = Acceleration;
- }
- public void AddAcceleration(Vector3 AddedAccel)
- {
- mAcceleration += AddedAccel;
- }
- public Vector3 GetForceAccum()
- {
- return mForceAccum;
- }
- public void SetForceAccum(Vector3 ForceAccum)
- {
- mForceAccum = ForceAccum;
- }
- public void AddForce(Vector3 Force)
- {
- mForceAccum += Force;
- }
- private void ClearAccumulator()
- {
- mForceAccum = Vector3.Zero;
- }
- public double GetDamping()
- {
- return mDamping;
- }
- public void SetDamping(double Damping)
- {
- mDamping = Damping;
- }
- public bool HasFiniteMass()
- {
- if (mInverseMass <= 0.0f)
- return false;
- return true;
- }
- public double GetInverseMass()
- {
- return mInverseMass;
- }
- public double GetMass()
- {
- return 1.0f / mInverseMass;
- }
- public void SetInverseMass(double InverseMass)
- {
- mInverseMass = InverseMass;
- }
- public void SetMass(double Mass)
- {
- mInverseMass = 1.0f / Mass;
- }
- public Vector3 GetRotation()
- {
- return mRotation;
- }
- public void SetRotation(Vector3 Rotation)
- {
- mRotation = Rotation;
- }
- public void Rotate(Vector3 Rotation)
- {
- mRotation += Rotation;
- }
- public void Integrate(GameTime elapsedTime)
- {
- if (mInverseMass <= 0.0f) return;
- float elapsedSeconds = (float)elapsedTime.ElapsedGameTime.Milliseconds/1000.0f;
- elapsedSeconds *= 100.0f;
- if (elapsedSeconds <= 0.0f) return;
- Vector3 resultingAcc = mAcceleration;
- resultingAcc += mForceAccum * (float)mInverseMass;
- mPosition += mVelocity * elapsedSeconds;
- if(!mUseDamping)
- mVelocity = (mVelocity) + resultingAcc * elapsedSeconds;
- else
- mVelocity = (mVelocity * (float)mDamping) + resultingAcc * elapsedSeconds;
- ClearAccumulator();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement