SHARE
TWEET
Untitled
a guest
Jan 29th, 2018
53
in 364 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- package com.dkstrong.transport.g3d.shape;
- import com.badlogic.gdx.math.Intersector;
- import com.badlogic.gdx.math.MathUtils;
- import com.badlogic.gdx.math.Matrix4;
- import com.badlogic.gdx.math.Quaternion;
- import com.badlogic.gdx.math.Vector3;
- import com.badlogic.gdx.math.collision.BoundingBox;
- import com.badlogic.gdx.math.collision.Ray;
- public class BoxTest {
- public static void main(String[] args) {
- // transform for when the box isnt rotated
- Matrix4 identitydTransform = new Matrix4(
- new Vector3(),
- new Quaternion(),
- new Vector3(1,1,1)
- );
- // tranform for when box is rotated 90 degress (this is the problem!)
- Matrix4 rotatedTransform = new Matrix4(
- new Vector3(),
- new Quaternion().setFromAxisRad(new Vector3(0,1,0), MathUtils.PI/2f),
- new Vector3(1,1,1)
- );
- Matrix4 identityTransformInverse = identitydTransform.cpy().inv();
- Matrix4 rotatedTransformInverse = rotatedTransform.cpy().inv();
- // bounding box is a rectangle shape, so rotating creates problems
- BoundingBox bb = new BoundingBox(
- new Vector3(-5,-10,-10),
- new Vector3(5, 10, 10)
- );
- // ray goes from top of world and goes down
- Ray ray = new Ray(
- new Vector3(0,20,9), // the ray position means its going to hit the long end of the rectangle
- new Vector3(0,-1,0));
- Ray rayForIdentiy = ray.cpy().mul(identityTransformInverse);
- Ray rayForRotated = ray.cpy().mul(rotatedTransformInverse);
- Vector3 bbCenter = bb.getCenter(new Vector3());
- Vector3 bbDimensions = bb.getDimensions(new Vector3());
- boolean isHit;
- isHit = Intersector.intersectRayBoundsFast(rayForIdentiy, bbCenter, bbDimensions);
- System.out.println("works if transform is identity: "+isHit);
- isHit = Intersector.intersectRayBoundsFast(rayForRotated, bbCenter, bbDimensions);
- System.out.println("works if transform is rotated: "+isHit);
- }
- }
RAW Paste Data

