mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-10-30 08:11:25 +00:00
implemented lame friction support for dts
This commit is contained in:
parent
8ba4cb396d
commit
81e728e168
5 changed files with 62 additions and 7 deletions
|
|
@ -31,6 +31,18 @@ import src.Util;
|
|||
|
||||
var DROP_TEXTURE_FOR_ENV_MAP = ['shapes/items/superjump.dts', 'shapes/items/antigravity.dts'];
|
||||
|
||||
var dtsMaterials = [
|
||||
"oilslick" => {friction: 0.05, restitution: 0.5, force: 0.0},
|
||||
"base.slick" => {friction: 0.05, restitution: 0.5, force: 0.0},
|
||||
"ice.slick" => {friction: 0.05, restitution: 0.5, force: 0.0},
|
||||
"bumper-rubber" => {friction: 0.5, restitution: 0.0, force: 15.0},
|
||||
"triang-side" => {friction: 0.5, restitution: 0.0, force: 15.0},
|
||||
"triang-top" => {friction: 0.5, restitution: 0.0, force: 15.0},
|
||||
"pball-round-side" => {friction: 0.5, restitution: 0.0, force: 15.0},
|
||||
"pball-round-top" => {friction: 0.5, restitution: 0.0, force: 15.0},
|
||||
"pball-round-bottm" => {friction: 0.5, restitution: 0.0, force: 15.0}
|
||||
];
|
||||
|
||||
typedef GraphNode = {
|
||||
var index:Int;
|
||||
var node:Node;
|
||||
|
|
@ -312,6 +324,13 @@ class DtsObject extends Object {
|
|||
for (primitive in dtsMesh.primitives) {
|
||||
var k = 0;
|
||||
var geometrydata = surfaces[primitive.matIndex];
|
||||
var material = this.dts.matNames[primitive.matIndex];
|
||||
if (dtsMaterials.exists(material)) {
|
||||
var data = dtsMaterials.get(material);
|
||||
geometrydata.friction = data.friction;
|
||||
geometrydata.force = data.force;
|
||||
geometrydata.restitution = data.restitution;
|
||||
}
|
||||
|
||||
for (i in primitive.firstElement...(primitive.firstElement + primitive.numElements - 2)) {
|
||||
var i1 = dtsMesh.indices[i];
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class Main extends hxd.App {
|
|||
var loader = new Loader(fileSystem);
|
||||
|
||||
dtsObj = new DtsObject();
|
||||
dtsObj.dtsPath = "data/shapes/items/timetravel.dts";
|
||||
dtsObj.dtsPath = "data/shapes/bumpers/pball_tri.dts";
|
||||
dtsObj.isCollideable = false;
|
||||
dtsObj.isTSStatic = false;
|
||||
dtsObj.fs = loader;
|
||||
|
|
@ -46,7 +46,7 @@ class Main extends hxd.App {
|
|||
DifBuilder.loadDif("data/interiors/beginner/training_friction.dif", loader, db);
|
||||
world.addInterior(db);
|
||||
var tform = db.getTransform();
|
||||
tform.setPosition(new Vector(0, 0, 7));
|
||||
tform.setPosition(new Vector(0, 0, 7.5));
|
||||
db.setTransform(tform);
|
||||
|
||||
// var pi = new PathedInterior();
|
||||
|
|
|
|||
|
|
@ -110,6 +110,32 @@ class Marble extends Object {
|
|||
function getExternalForces(m:Move, dt:Float) {
|
||||
var gWorkGravityDir = gravityDir;
|
||||
var A = gWorkGravityDir.multiply(this._gravity);
|
||||
if (contacts.length != 0) {
|
||||
var contactForce = 0.0;
|
||||
var contactNormal = new Vector();
|
||||
var forceObjectCount = 0;
|
||||
|
||||
for (contact in contacts) {
|
||||
if (contact.force != 0) {
|
||||
forceObjectCount++;
|
||||
contactNormal = contactNormal.add(contact.normal);
|
||||
contactForce += contact.force;
|
||||
}
|
||||
}
|
||||
|
||||
if (forceObjectCount != 0) {
|
||||
contactNormal.normalize();
|
||||
|
||||
var a = contactForce / this._mass;
|
||||
var dot = this.velocity.dot(contactNormal);
|
||||
if (a > dot) {
|
||||
if (dot > 0)
|
||||
a -= dot;
|
||||
|
||||
A = A.add(contactNormal.multiply(a / dt));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (contacts.length == 0) {
|
||||
var axes = this.getMarbleAxis();
|
||||
var sideDir = axes[0];
|
||||
|
|
|
|||
|
|
@ -30,8 +30,10 @@ class CollisionEntity implements IOctreeObject {
|
|||
}
|
||||
|
||||
public function addSurface(surface:CollisionSurface) {
|
||||
this.octree.insert(surface);
|
||||
this.surfaces.push(surface);
|
||||
if (surface.points.length > 0) {
|
||||
this.octree.insert(surface);
|
||||
this.surfaces.push(surface);
|
||||
}
|
||||
}
|
||||
|
||||
public function setTransform(transform:Matrix) {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,9 @@ import h3d.Vector;
|
|||
|
||||
class CollisionHull extends CollisionEntity {
|
||||
var hull:ConvexHull;
|
||||
var friction = 1.0;
|
||||
var restitution = 1.0;
|
||||
var force = 0.0;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
|
|
@ -39,9 +42,9 @@ class CollisionHull extends CollisionEntity {
|
|||
cinfo.point = sph.position.sub(pt);
|
||||
cinfo.velocity = velocity;
|
||||
cinfo.contactDistance = sph.radius + pt.length();
|
||||
cinfo.restitution = 1;
|
||||
cinfo.friction = 1;
|
||||
cinfo.force = 0;
|
||||
cinfo.restitution = restitution;
|
||||
cinfo.friction = friction;
|
||||
cinfo.force = force;
|
||||
return [cinfo];
|
||||
}
|
||||
}
|
||||
|
|
@ -53,5 +56,10 @@ class CollisionHull extends CollisionEntity {
|
|||
if (hull == null)
|
||||
hull = new ConvexHull([]);
|
||||
hull.vertices = hull.vertices.concat(surface.points);
|
||||
if (surface.points.length != 0) {
|
||||
this.force = surface.force;
|
||||
this.friction = surface.friction;
|
||||
this.restitution = surface.restitution;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue