package com.windpoweredgames.mocha.util; import java.util.Collection; import org.lwjgl.opengl.GL11; import org.lwjgl.util.vector.Vector3f; import com.windpoweredgames.mocha.GameEngine; import com.windpoweredgames.mocha.component.TextComponent; import com.windpoweredgames.mocha.model.Model; import com.windpoweredgames.mocha.model.matrix.ModelMatrix; public class RayCastUtil { public static TextComponent rayStartComp = new TextComponent("RayStart"); public static TextComponent rayDirComp = new TextComponent("RayDir"); public static TextComponent dotComp = new TextComponent("DOT"); public static TextComponent tComp = new TextComponent("T"); public static TextComponent intersectionComp = new TextComponent("IntPoint"); public static TextComponent hitComp = new TextComponent("HitPoint"); public static TextComponent fullAreaComp = new TextComponent("Full Area"); public static TextComponent area1Comp = new TextComponent("Area1"); public static TextComponent area2Comp = new TextComponent("Area2"); public static TextComponent area3Comp = new TextComponent("Area3"); public static TextComponent areaTotalComp = new TextComponent("Total Area"); public static Vector3f triag1 = new Vector3f(); public static Vector3f triag2 = new Vector3f(); public static Vector3f triag3 = new Vector3f(); public static Vector3f normal = new Vector3f(); public static Vector3f rayTest(Vector3f rayOrigin, Vector3f rayDirection, Collection models){ Vector3f result = null; for(Model model : models){ result = rayTest(rayOrigin, rayDirection, model); if(result!=null){ return result; } } return result; } public static Vector3f rayTest(Vector3f rayOrigin, Vector3f rayDirection, Model model){ float[] vertexes = new float[model.getVertexBuffer().limit()]; float[] normals = new float[model.getNormalBuffer().limit()]; model.getVertexBuffer().rewind(); model.getVertexBuffer().get(vertexes); model.getNormalBuffer().rewind(); model.getNormalBuffer().get(normals); Vector3f pos = model.getModelMatrix().getPosition(); Vector3f result = null; boolean hit = false; for(int i=0;i