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);
|
||||
}
|
||||
|
||||
public override function isIntersectedByRay(rayOrigin:Vector, rayDirection:Vector, intersectionPoint:Vector, intersectionNormal:Vector):Bool {
|
||||
public override function rayCast(rayOrigin:Vector, rayDirection:Vector) {
|
||||
// TEMP cause bruh
|
||||
return false;
|
||||
return boundingBox.rayIntersection(Ray.fromValues(rayOrigin.x, rayOrigin.y, rayOrigin.z, rayDirection.x, rayDirection.y, rayDirection.z), true) != -1;
|
||||
return [];
|
||||
}
|
||||
|
||||
public override function sphereIntersection(collisionEntity:SphereCollisionEntity, timeState:TimeState) {
|
||||
|
|
|
|||
|
|
@ -59,22 +59,21 @@ class CollisionEntity implements IOctreeObject {
|
|||
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();
|
||||
invMatrix.invert();
|
||||
var rStart = rayOrigin.clone();
|
||||
rStart.transform(invMatrix);
|
||||
var rDir = rayDirection.transformed3x3(invMatrix);
|
||||
var intersections = octree.raycast(rStart, rDir);
|
||||
var iData:Array<RayIntersectionData> = [];
|
||||
for (i in intersections) {
|
||||
i.point.transform(transform);
|
||||
i.normal.transform3x3(transform);
|
||||
i.normal.normalize();
|
||||
iData.push({point: i.point, normal: i.normal});
|
||||
}
|
||||
if (intersections.length > 0) {
|
||||
intersectionPoint.load(intersections[0].point);
|
||||
intersectionNormal.load(intersections[0].normal);
|
||||
}
|
||||
return intersections.length > 0;
|
||||
return iData;
|
||||
}
|
||||
|
||||
public function getElementType() {
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ class CollisionSurface implements IOctreeObject {
|
|||
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 i = 0;
|
||||
while (i < indices.length) {
|
||||
|
|
@ -89,18 +89,12 @@ class CollisionSurface implements IOctreeObject {
|
|||
var t = -(rayOrigin.dot(n) + d) / (rayDirection.dot(n));
|
||||
var ip = rayOrigin.add(rayDirection.multiply(t));
|
||||
ip.w = 1;
|
||||
if (Collision.PointInTriangle(ip, p1, p2, p3)) {
|
||||
intersections.push({pt: ip, n: n});
|
||||
if (t >= 0 && Collision.PointInTriangle(ip, p1, p2, p3)) {
|
||||
intersections.push({point: ip, normal: n});
|
||||
}
|
||||
i += 3;
|
||||
}
|
||||
intersections.sort((a,
|
||||
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;
|
||||
return intersections;
|
||||
}
|
||||
|
||||
public function support(direction:Vector, transform:Matrix) {
|
||||
|
|
|
|||
|
|
@ -26,10 +26,9 @@ class SphereCollisionEntity extends CollisionEntity {
|
|||
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
|
||||
return false;
|
||||
return boundingBox.rayIntersection(Ray.fromValues(rayOrigin.x, rayOrigin.y, rayOrigin.z, rayDirection.x, rayDirection.y, rayDirection.z), true) != -1;
|
||||
return [];
|
||||
}
|
||||
|
||||
public override function sphereIntersection(collisionEntity:SphereCollisionEntity, timeState:TimeState) {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,12 @@ package octree;
|
|||
import h3d.Vector;
|
||||
import h3d.col.Bounds;
|
||||
|
||||
typedef RayIntersectionData = {
|
||||
var point:Vector;
|
||||
var normal:Vector;
|
||||
}
|
||||
|
||||
interface IOctreeObject extends IOctreeElement {
|
||||
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;
|
||||
|
||||
for (obj in this.objects) {
|
||||
var iSec = new Vector();
|
||||
var iNorm = new Vector();
|
||||
if (obj.isIntersectedByRay(rayOrigin, rayDirection, iSec, iNorm)) {
|
||||
var iSecs = obj.rayCast(rayOrigin, rayDirection);
|
||||
for (intersection in iSecs) {
|
||||
var intersectionData = new OctreeIntersection();
|
||||
intersectionData.distance = rayOrigin.distance(iSec);
|
||||
intersectionData.distance = rayOrigin.distance(intersection.point);
|
||||
intersectionData.object = obj;
|
||||
intersectionData.point = iSec;
|
||||
intersectionData.normal = iNorm;
|
||||
intersectionData.point = intersection.point;
|
||||
intersectionData.normal = intersection.normal;
|
||||
intersections.push(intersectionData);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue