-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
198 additions
and
68 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,4 +58,6 @@ export default class Outside { | |
|
||
} | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,81 @@ | ||
import {Vector2, Vector3, Vector4} from "math.gl"; | ||
import {Matrix4, Vector2, Vector3, Vector4} from "math.gl"; | ||
import Camera from "./Camera"; | ||
import Renderer from "./Renderer"; | ||
|
||
export default class Ray{ | ||
export default class Ray { | ||
public hit: boolean = false; | ||
public hitPos: Vector3 = new Vector3(); | ||
private renderer: Renderer; | ||
private rayStart: Vector3 =new Vector3(); | ||
private rayDir: Vector3 =new Vector3(); | ||
public hit:boolean=false; | ||
public hitPos:Vector3 =new Vector3(); | ||
constructor(renderer:Renderer) { | ||
this.renderer =renderer; | ||
private rayStart: Vector3 = new Vector3(); | ||
private rayDir: Vector3 = new Vector3(); | ||
|
||
constructor(renderer: Renderer) { | ||
this.renderer = renderer; | ||
|
||
} | ||
|
||
clone() { | ||
let r = new Ray(this.renderer) | ||
r.rayStart = this.rayStart; | ||
r.rayDir = this.rayDir; | ||
return r; | ||
} | ||
setFromCamera(camera:Camera,mousePosIn:Vector2) | ||
{ | ||
|
||
setFromCamera(camera: Camera, mousePosIn: Vector2) { | ||
let mousePos = mousePosIn.clone().scale(new Vector2(2 / (this.renderer.width / this.renderer.pixelRatio), 2 / (this.renderer.height / this.renderer.pixelRatio))) | ||
let pos = new Vector4(mousePos.x - 1, (mousePos.y - 1) * -1, 1, 1); | ||
if (camera.viewProjectionInv) { | ||
pos.transform(camera.viewProjectionInv); | ||
this.rayStart = camera.cameraWorld.clone() | ||
this.rayDir = new Vector3(pos.x - this.rayStart.x, pos.y - this.rayStart.y, pos.z - this.rayStart.z).normalize() | ||
} | ||
|
||
pos.transform(camera.viewProjectionInv); | ||
this.rayStart = camera.cameraWorld.clone() | ||
this.rayDir = new Vector3(pos.x - this.rayStart.x, pos.y - this.rayStart.y, pos.z - this.rayStart.z).normalize() | ||
|
||
} | ||
|
||
intersectPlane(position:Vector3,normal:Vector3){ | ||
intersectPlane(position: Vector3, normal: Vector3) { | ||
|
||
let denom = normal.dot(this.rayDir); | ||
if (Math.abs(denom) > 0.0001) // your favorite epsilon | ||
{ | ||
|
||
let t = (position.clone().subtract(this.rayStart)).dot(normal) / denom; | ||
if (t < 0) { | ||
this.hit = false; | ||
return; | ||
let t = (position.clone().subtract(this.rayStart)).dot(normal) / denom; | ||
if (t < 0) { | ||
this.hit = false; | ||
return; | ||
} else { | ||
this.hit = true; | ||
this.rayDir.clone().scale(t); | ||
this.hitPos = this.rayStart.clone().add(this.rayDir.clone().scale(t)).subtract(position); | ||
} | ||
|
||
} else { | ||
this.hit =true; | ||
this.rayDir.clone().scale(t); | ||
this.hitPos = this.rayStart.clone().add( this.rayDir.clone().scale(t)).subtract(position); | ||
this.hit = false; | ||
} | ||
|
||
} | ||
|
||
intersectsBox(min: Vector3, max: Vector3) { | ||
|
||
} | ||
const t1 = (min.x - this.rayStart.x) / this.rayDir.x; | ||
const t2 = (max.x - this.rayStart.x) / this.rayDir.x; | ||
const t3 = (min.y - this.rayStart.y) / this.rayDir.y; | ||
const t4 = (max.y - this.rayStart.y) / this.rayDir.y; | ||
const t5 = (min.z - this.rayStart.z) / this.rayDir.z; | ||
const t6 = (max.z - this.rayStart.z) / this.rayDir.z; | ||
|
||
const tmin = Math.max(Math.max(Math.min(t1, t2), Math.min(t3, t4)), Math.min(t5, t6)); | ||
const tmax = Math.min(Math.min(Math.max(t1, t2), Math.max(t3, t4)), Math.max(t5, t6)); | ||
|
||
} else { | ||
this.hit = false; | ||
if (tmax < 0) return false; | ||
if (tmin > tmax) return false; | ||
return true; | ||
} | ||
|
||
transform(invModel: Matrix4) { | ||
|
||
} | ||
this.rayDir.add(this.rayStart); | ||
this.rayDir.transform(invModel); | ||
this.rayStart.transform(invModel); | ||
this.rayDir.subtract(this.rayStart); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,51 @@ | ||
|
||
import Renderer from "../Renderer"; | ||
import Material from "../core/Material"; | ||
import Mesh from "../core/Mesh"; | ||
import Object3D from "../core/Object3D"; | ||
import ModelTransform from "./ModelTransform"; | ||
import HitTestObject from "../meshes/HitTestObject"; | ||
import Ray from "../Ray"; | ||
import GameModel from "../../GameModel"; | ||
|
||
|
||
export default class Model extends Object3D | ||
{ | ||
export default class Model extends Object3D { | ||
material!: Material; | ||
mesh!:Mesh | ||
mesh!: Mesh | ||
|
||
public modelTransform: ModelTransform; | ||
public visible: boolean =true; | ||
public visible: boolean = true; | ||
public hitTestObject: HitTestObject; | ||
public canHitTest: boolean =false; | ||
public canHitTest: boolean = false; | ||
|
||
constructor(renderer:Renderer,label:string) { | ||
super(renderer,label); | ||
this.modelTransform =new ModelTransform(renderer,label+"_transform") | ||
constructor(renderer: Renderer, label: string) { | ||
super(renderer, label); | ||
this.modelTransform = new ModelTransform(renderer, label + "_transform") | ||
|
||
this.renderer.addModel(this); | ||
} | ||
public update() | ||
{ | ||
if(!this._dirty)return; | ||
this.updateMatrices() | ||
|
||
} | ||
protected updateMatrices(){ | ||
super.updateMatrices(); | ||
public update() { | ||
if (!this._dirty) return; | ||
this.updateMatrices() | ||
|
||
this.modelTransform.setWorldMatrix(this.worldMatrix); | ||
} | ||
public checkHit(ray:Ray) | ||
{ | ||
this.hitTestObject.checkHit(ray,this.worldMatrixInv) | ||
|
||
public checkHit(ray: Ray) { | ||
if(!this.visible) return false; | ||
if(this.hitTestObject.checkHit(ray, this.worldMatrixInv)){ | ||
GameModel.hitObjectLabel =this.label; | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
destroy() { | ||
if(this.parent)this.parent.removeChild(this); | ||
if (this.parent) this.parent.removeChild(this); | ||
} | ||
|
||
protected updateMatrices() { | ||
super.updateMatrices(); | ||
|
||
this.modelTransform.setWorldMatrix(this.worldMatrix); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import Trigger from "./Trigger"; | ||
import GameModel, {Scenes} from "../GameModel"; | ||
import UI from "../lib/UI/UI"; | ||
|
||
export default class HitTrigger extends Trigger{ | ||
private objectLabel: string; | ||
constructor(scene:Scenes,objectLabel:string) { | ||
super(scene); | ||
this.objectLabel =objectLabel; | ||
|
||
} | ||
check() { | ||
if(!super.check())return false; | ||
if(!GameModel.hitStateChange)return | ||
if(GameModel.hitObjectLabel ==this.objectLabel) { | ||
this.over() | ||
return true; | ||
} | ||
if(GameModel.hitObjectLabelPrev ==this.objectLabel) { | ||
this.out() | ||
return true; | ||
} | ||
|
||
|
||
|
||
|
||
} | ||
|
||
private over() { | ||
//UI.logEvent("Over", this.objectLabel); | ||
} | ||
|
||
private out() { | ||
// UI.logEvent("Out", this.objectLabel); | ||
} | ||
} |
Oops, something went wrong.