Skip to content

Instantly share code, notes, and snippets.

@ronjunevaldoz
Created May 17, 2020 15:13
Show Gist options
  • Save ronjunevaldoz/85666588a7126f9542af59db2ab2314a to your computer and use it in GitHub Desktop.
Save ronjunevaldoz/85666588a7126f9542af59db2ab2314a to your computer and use it in GitHub Desktop.
class GameObject(
model: Model,
private val shape: btCollisionShape,
mass: Float
) : ModelInstance(
model
), Disposable {
// For ray picking
val center = Vector3()
val dimensions = Vector3()
var radius = 0f
private val bounds: BoundingBox = BoundingBox()
// end for ray picking
// for animation
var controller: AnimationController
// end for animation
private val localInertia = Vector3()
private val constructionInfo =
btRigidBody.btRigidBodyConstructionInfo(
mass,
null,
shape,
localInertia
)
val body: btRigidBody =
btRigidBody(constructionInfo)
val motion: MyMotionState =
MyMotionState()
init {
// for ray picking
calculateBoundingBox(bounds)
bounds.getCenter(center)
bounds.getDimensions(dimensions)
radius = dimensions.len() / 2f
// end ray picking
motion.transform = transform
if (mass > 0f)
shape.calculateLocalInertia(mass, localInertia)
else
localInertia.set(0f, 0f, 0f)
body.collisionShape = shape
body.motionState = motion
controller = AnimationController(this)
}
override fun dispose() {
body.dispose()
shape.dispose()
motion.dispose()
constructionInfo.dispose()
}
}
fun GameObject.transform(position: Vector3) {
// transform.setFromEulerAngles(MathUtils.random(360f), MathUtils.random(360f), MathUtils.random(360f))
transform.setTranslation(position)
body.proceedToTransform(transform)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment