Physics abstract class.
A physics object is a tool to manipulate the position and orientation of an entity. The physics object is a container for idClipModels used for collision detection. The physics deals with moving these collision models through the world according to the laws of physics or other rules. The mass of a clip model is the volume of the clip model times the density. An arbitrary mass can however be set for specific clip models or the whole physics object. The contents of a clip model is a set of bit flags that define the contents. The clip mask defines the contents a clip model collides with. The linear velocity of a physics object is a vector that defines the translation of the center of mass in units per second. The angular velocity of a physics object is a vector that passes through the center of mass. The direction of this vector defines the axis of rotation and the magnitude defines the rate of rotation about the axis in radians per second. The gravity is the change in velocity per second due to gravitational force. Entities update their visual position and orientation from the physics using GetOrigin() and GetAxis(). Direct origin and axis changes of entities should go through the physics. In other words the physics origin and axis are updated first and the entity updates it's visual position from the physics.
Inheritance: IDisposable
示例#1
0
		protected virtual void SetPhysics(idPhysics phys)
		{
			// clear any contacts the current physics object has
			if(_physics != null)
			{
				_physics.ClearContacts();
			}

			// set new physics object or set the default physics if NULL
			if(phys != null)
			{
				_defaultPhysicsObject.SetClipModel(null, 1.0f);

				_physics = phys;
				_physics.Activate();
			}
			else
			{
				_physics = _defaultPhysicsObject;
			}

			_physics.UpdateTime(idR.Game.Time);

			idConsole.Warning("TODO: _physics.SetMaster(bindMaster, fl.bindOrientated);");
		}
示例#2
0
		private void InitDefaultPhysics(Vector3 origin, Matrix axis)
		{
			string temp = _spawnArgs.GetString("clipmodel", "");
			idClipModel clipModel = null;

			// check if a clipmodel key/value pair is set
			if(temp != string.Empty)
			{
				if(idClipModel.CheckModel(temp) != null)
				{
					clipModel = new idClipModel(temp);
				}
			}

			if(_spawnArgs.GetBool("noclipmodel", false) == false)
			{
				// check if mins/maxs or size key/value pairs are set
				if(clipModel == null)
				{
					idBounds bounds = idBounds.Zero;
					bool setClipModel = false;

					if((_spawnArgs.ContainsKey("mins") == true)
						&& (_spawnArgs.ContainsKey("maxs") == true))
					{
						bounds = new idBounds(_spawnArgs.GetVector3("mins"), _spawnArgs.GetVector3("maxs"));
						setClipModel = true;

						if((bounds.Min.X > bounds.Max.X)
							|| (bounds.Min.Y > bounds.Max.Y)
							|| (bounds.Min.Z > bounds.Max.Z))
						{
							idConsole.Error("Invalid bounds '{0}'-'{1}' on entity '{2}'", bounds.Min, bounds.Max, this.Name);
						}
					}
					else if(_spawnArgs.ContainsKey("size") == true)
					{
						Vector3 size = _spawnArgs.GetVector3("size");

						if((size.X < 0.0f)
							|| (size.Y < 0.0f)
							|| (size.Z < 0.0f))
						{
							idConsole.Error("Invalid size '{0}' on entity '{1}'", size, this.Name);
						}

						setClipModel = true;
						bounds = new idBounds(
									new Vector3(size.X * -0.5f, size.Y * -0.5f, 0.0f),
									new Vector3(size.X * 0.5f, size.Y * 0.5f, size.Z)
								);
					}

					if(setClipModel == true)
					{
						int sideCount = _spawnArgs.GetInteger("cyclinder", 0);

						idTraceModel traceModel = new idTraceModel();

						if(sideCount > 0)
						{
							idConsole.Warning("TODO: traceModel.SetupCyclinder(bounds, (sideCount < 3) ? 3 : sideCount);");
						}
						else if((sideCount = _spawnArgs.GetInteger("cone", 0)) > 0)
						{
							idConsole.Warning("TODO: traceModel.SetupCone(bounds, (sideCount < 3) ? 3 : sideCount);");
						}
						else
						{
							traceModel.SetupBox(bounds);
						}

						clipModel = new idClipModel(traceModel);
					}
				}

				// check if the visual model can be used as collision model
				if(clipModel == null)
				{
					temp = _spawnArgs.GetString("model");

					if(temp != string.Empty)
					{
						if(idClipModel.CheckModel(temp) != null)
						{
							clipModel = new idClipModel(temp);
						}
					}
				}
			}

			_defaultPhysicsObject.Self = this;
			_defaultPhysicsObject.SetClipModel(clipModel, 1.0f);
			_defaultPhysicsObject.SetOrigin(origin);
			_defaultPhysicsObject.SetAxis(axis);

			_physics = _defaultPhysicsObject;
		}