mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-10-30 08:11:25 +00:00
attempt jank camera fix
This commit is contained in:
parent
2319360908
commit
16b18da90c
7 changed files with 24 additions and 29 deletions
BIN
marblegame.hl
BIN
marblegame.hl
Binary file not shown.
|
|
@ -23,10 +23,9 @@ class BoxCollisionEntity extends CollisionEntity {
|
||||||
this.boundingBox.transform(this.transform);
|
this.boundingBox.transform(this.transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override function isIntersectedByRay(rayOrigin:Vector, rayDirection:Vector, intersectionPoint:Vector, intersectionNormal:Vector):Bool {
|
public override function rayCast(rayOrigin:Vector, rayDirection:Vector) {
|
||||||
// TEMP cause bruh
|
// TEMP cause bruh
|
||||||
return false;
|
return [];
|
||||||
return boundingBox.rayIntersection(Ray.fromValues(rayOrigin.x, rayOrigin.y, rayOrigin.z, rayDirection.x, rayDirection.y, rayDirection.z), true) != -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override function sphereIntersection(collisionEntity:SphereCollisionEntity, timeState:TimeState) {
|
public override function sphereIntersection(collisionEntity:SphereCollisionEntity, timeState:TimeState) {
|
||||||
|
|
|
||||||
|
|
@ -59,22 +59,21 @@ class CollisionEntity implements IOctreeObject {
|
||||||
this.boundingBox = boundingBox;
|
this.boundingBox = boundingBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isIntersectedByRay(rayOrigin:Vector, rayDirection:Vector, intersectionPoint:Vector, intersectionNormal:Vector):Bool {
|
public function rayCast(rayOrigin:Vector, rayDirection:Vector):Array<RayIntersectionData> {
|
||||||
var invMatrix = transform.clone();
|
var invMatrix = transform.clone();
|
||||||
invMatrix.invert();
|
invMatrix.invert();
|
||||||
var rStart = rayOrigin.clone();
|
var rStart = rayOrigin.clone();
|
||||||
rStart.transform(invMatrix);
|
rStart.transform(invMatrix);
|
||||||
var rDir = rayDirection.transformed3x3(invMatrix);
|
var rDir = rayDirection.transformed3x3(invMatrix);
|
||||||
var intersections = octree.raycast(rStart, rDir);
|
var intersections = octree.raycast(rStart, rDir);
|
||||||
|
var iData:Array<RayIntersectionData> = [];
|
||||||
for (i in intersections) {
|
for (i in intersections) {
|
||||||
i.point.transform(transform);
|
i.point.transform(transform);
|
||||||
i.normal.transform3x3(transform);
|
i.normal.transform3x3(transform);
|
||||||
|
i.normal.normalize();
|
||||||
|
iData.push({point: i.point, normal: i.normal});
|
||||||
}
|
}
|
||||||
if (intersections.length > 0) {
|
return iData;
|
||||||
intersectionPoint.load(intersections[0].point);
|
|
||||||
intersectionNormal.load(intersections[0].normal);
|
|
||||||
}
|
|
||||||
return intersections.length > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getElementType() {
|
public function getElementType() {
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ class CollisionSurface implements IOctreeObject {
|
||||||
this.priority = priority;
|
this.priority = priority;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isIntersectedByRay(rayOrigin:Vector, rayDirection:Vector, intersectionPoint:Vector, intersectionNormal:Vector):Bool {
|
public function rayCast(rayOrigin:Vector, rayDirection:Vector):Array<RayIntersectionData> {
|
||||||
var intersections = [];
|
var intersections = [];
|
||||||
var i = 0;
|
var i = 0;
|
||||||
while (i < indices.length) {
|
while (i < indices.length) {
|
||||||
|
|
@ -89,18 +89,12 @@ class CollisionSurface implements IOctreeObject {
|
||||||
var t = -(rayOrigin.dot(n) + d) / (rayDirection.dot(n));
|
var t = -(rayOrigin.dot(n) + d) / (rayDirection.dot(n));
|
||||||
var ip = rayOrigin.add(rayDirection.multiply(t));
|
var ip = rayOrigin.add(rayDirection.multiply(t));
|
||||||
ip.w = 1;
|
ip.w = 1;
|
||||||
if (Collision.PointInTriangle(ip, p1, p2, p3)) {
|
if (t >= 0 && Collision.PointInTriangle(ip, p1, p2, p3)) {
|
||||||
intersections.push({pt: ip, n: n});
|
intersections.push({point: ip, normal: n});
|
||||||
}
|
}
|
||||||
i += 3;
|
i += 3;
|
||||||
}
|
}
|
||||||
intersections.sort((a,
|
return intersections;
|
||||||
b) -> (a.pt.distance(rayOrigin) == b.pt.distance(rayOrigin)) ? 0 : (a.pt.distance(rayOrigin) > b.pt.distance(rayOrigin) ? 1 : -1));
|
|
||||||
if (intersections.length > 0) {
|
|
||||||
intersectionPoint.load(intersections[0].pt);
|
|
||||||
intersectionNormal.load(intersections[0].n);
|
|
||||||
}
|
|
||||||
return intersections.length > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function support(direction:Vector, transform:Matrix) {
|
public function support(direction:Vector, transform:Matrix) {
|
||||||
|
|
|
||||||
|
|
@ -26,10 +26,9 @@ class SphereCollisionEntity extends CollisionEntity {
|
||||||
this.boundingBox = boundingBox;
|
this.boundingBox = boundingBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override function isIntersectedByRay(rayOrigin:Vector, rayDirection:Vector, intersectionPoint:Vector, intersectionNormal:Vector):Bool {
|
public override function rayCast(rayOrigin:Vector, rayDirection:Vector) {
|
||||||
// TEMP cause bruh
|
// TEMP cause bruh
|
||||||
return false;
|
return [];
|
||||||
return boundingBox.rayIntersection(Ray.fromValues(rayOrigin.x, rayOrigin.y, rayOrigin.z, rayDirection.x, rayDirection.y, rayDirection.z), true) != -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override function sphereIntersection(collisionEntity:SphereCollisionEntity, timeState:TimeState) {
|
public override function sphereIntersection(collisionEntity:SphereCollisionEntity, timeState:TimeState) {
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,12 @@ package octree;
|
||||||
import h3d.Vector;
|
import h3d.Vector;
|
||||||
import h3d.col.Bounds;
|
import h3d.col.Bounds;
|
||||||
|
|
||||||
|
typedef RayIntersectionData = {
|
||||||
|
var point:Vector;
|
||||||
|
var normal:Vector;
|
||||||
|
}
|
||||||
|
|
||||||
interface IOctreeObject extends IOctreeElement {
|
interface IOctreeObject extends IOctreeElement {
|
||||||
var boundingBox:Bounds;
|
var boundingBox:Bounds;
|
||||||
function isIntersectedByRay(rayOrigin:Vector, rayDirection:Vector, intersectionPoint:Vector, intersectionNormal:Vector):Bool;
|
function rayCast(rayOrigin:Vector, rayDirection:Vector):Array<RayIntersectionData>;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -139,14 +139,13 @@ class OctreeNode implements IOctreeElement {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (obj in this.objects) {
|
for (obj in this.objects) {
|
||||||
var iSec = new Vector();
|
var iSecs = obj.rayCast(rayOrigin, rayDirection);
|
||||||
var iNorm = new Vector();
|
for (intersection in iSecs) {
|
||||||
if (obj.isIntersectedByRay(rayOrigin, rayDirection, iSec, iNorm)) {
|
|
||||||
var intersectionData = new OctreeIntersection();
|
var intersectionData = new OctreeIntersection();
|
||||||
intersectionData.distance = rayOrigin.distance(iSec);
|
intersectionData.distance = rayOrigin.distance(intersection.point);
|
||||||
intersectionData.object = obj;
|
intersectionData.object = obj;
|
||||||
intersectionData.point = iSec;
|
intersectionData.point = intersection.point;
|
||||||
intersectionData.normal = iNorm;
|
intersectionData.normal = intersection.normal;
|
||||||
intersections.push(intersectionData);
|
intersections.push(intersectionData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue