Libraries.Game.Physics.Mass2D Documentation
Mass2D is a class representing a mass in 2D space.
Example Code
use Libraries.Game.Physics.Mass2D
use Libraries.Compute.Vector2
Vector2 vectorSetting
vectorSetting:Set(8.0, 9.0)
Mass2D mass
mass:SetMass(5.0)
mass:SetInertia(2.0)
mass:SetCenter(vectorSetting)
number newMass = mass:GetMass()
number newInertia = mass:GetInertia()
number newX = mass:GetCenter():GetX()
number newY = mass:GetCenter():GetY()
output "The new mass has a mass of " + newMass + ", inertia of: " + newInertia + ", x center at: " + newX + ", and y center at: " + newY
Inherits from: Libraries.Language.Object
Actions Documentation
Compare(Libraries.Language.Object object)
This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.
Parameters
- Libraries.Language.Object: The object to compare to.
Return
integer: The Compare result, Smaller, Equal, or Larger.
Example
Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)
Copy()
This action returns a copy of the current mass. The copied mass will have the same mass, center, and inertia as the current mass.
Return
Libraries.Game.Physics.Mass2D: a mass in 2D space.
Example
use Libraries.Game.Physics.Mass2D
use Libraries.Compute.Vector2
Vector2 vectorSetting
vectorSetting:Set(8.0, 9.0)
Mass2D massBeingCopied
//setting the mass that we will copy
massBeingCopied:SetMass(5.0)
massBeingCopied:SetInertia(2.0)
massBeingCopied:SetCenter(vectorSetting)
//copy the mass
Mass2D copyMass
copyMass = massBeingCopied:Copy()
number copiedMass = copyMass:GetMass()
number copiedInertia = copyMass:GetInertia()
number copiedX = copyMass:GetCenter():GetX()
number copiedY = copyMass:GetCenter():GetY()
output "The copy of the mass has a mass of " + copiedMass + ", inertia of: " + copiedInertia + ", x center at: " + copiedX + ", and y center at: " + copiedY
Equals(Libraries.Language.Object object)
This action determines if two objects are equal based on their hash code values.
Parameters
- Libraries.Language.Object: The to be compared.
Return
boolean: True if the hash codes are equal and false if they are not equal.
Example
use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)
GetCenter()
This action gets the vector that points to the center of the mass in 2D.
Return
Libraries.Compute.Vector2: a 2D vector that points to the center of the mass in 2D.
Example
use Libraries.Game.Physics.Mass2D
use Libraries.Compute.Vector2
Vector2 centerOfMassSetting
centerOfMassSetting:Set(1.0, 3.0)
Mass2D mass
mass:SetCenter(centerOfMassSetting)
Vector2 centerOfMass
centerOfMass = mass:GetCenter()
number xComponent = centerOfMass:GetX()
number yComponent = centerOfMass:GetY()
output "The center of mass vector is: <" + xComponent + ", " + yComponent + ">"
GetHashCode()
This action gets the hash code for an object.
Return
integer: The integer hash code of the object.
Example
Object o
integer hash = o:GetHashCode()
GetInertia()
This action sets the inertia of a mass in 2D space.
Return
number: the value of inertia of the current 2D mass.
Example
use Libraries.Game.Physics.Mass2D
number inertiaSetting = 5.0
Mass2D mass
mass:SetInertia(inertiaSetting)
number inertiaValue = mass:GetInertia()
output "The inertia of mass in 2D is: " + inertiaValue
GetMass()
This action returns the mass of a mass in 2D space.
Return
number: the value of mass.
Example
use Libraries.Game.Physics.Mass2D
Mass2D mass
mass:SetMass(0.5)
number massValue = mass:GetMass()
output "The mass that you have set is: " + massValue
Set(Libraries.Game.Physics.Mass2D mass)
This action sets the properties of a 2D mass using another 2D mass.
Parameters
- Libraries.Game.Physics.Mass2D: The 2D mass whose properties will be copied.
Example
use Libraries.Game.Physics.Mass2D
use Libraries.Compute.Vector2
Vector2 vectorSetting
vectorSetting:Set(8.0, 9.0)
Mass2D mass1
Mass2D mass2
mass1:SetMass(5.0)
mass1:SetInertia(2.0)
mass1:SetCenter(vectorSetting)
mass2:Set(mass1)
number newMass = mass2:GetMass()
number newInertia = mass2:GetInertia()
number newX = mass2:GetCenter():GetX()
number newY = mass2:GetCenter():GetY()
output "The new mass has a mass of " + newMass + ", inertia of: " + newInertia + ", x center at: " + newX + ", and y center at: " + newY
SetCenter(Libraries.Compute.Vector2 center)
This action sets the vector that points to the center of a mass in 2D space.
Parameters
- Libraries.Compute.Vector2: The 2D vector that is used to set the center of mass.
Example
use Libraries.Game.Physics.Mass2D
use Libraries.Compute.Vector2
Vector2 centerOfMassSetting
centerOfMassSetting:Set(1.0, 3.0)
Mass2D mass
mass:SetCenter(centerOfMassSetting)
Vector2 centerOfMass
centerOfMass = mass:GetCenter()
number xComponent = centerOfMass:GetX()
number yComponent = centerOfMass:GetY()
output "The center of mass vector is: <" + xComponent + ", " + yComponent + ">"
SetInertia(number inertia)
This action sets the inertia of a mass in 2D space.
Parameters
- number inertia: The value of inertia of a 2D mass.
Example
use Libraries.Game.Physics.Mass2D
number inertiaSetting = 5.0
Mass2D mass
mass:SetInertia(inertiaSetting)
number inertiaValue = mass:GetInertia()
output "The inertia of mass in 2D is: " + inertiaValue
SetMass(number mass)
This action sets the value of mass of a mass in 2D space.
Parameters
- number mass: The value of mass that is used to set the property of a 2D mass.
Example
use Libraries.Game.Physics.Mass2D
Mass2D mass
mass:SetMass(5.5)
number massValue = mass:GetMass()
output "The mass of this mass in 2D is: " + massValue