diff --git a/cruft/graphics/Camera2D.js b/cruft/graphics/Camera2D.js index 1379394..3768284 100644 --- a/cruft/graphics/Camera2D.js +++ b/cruft/graphics/Camera2D.js @@ -2,7 +2,7 @@ import Actor from "engine/core/Actor"; import Renderer from "engine/graphics/Renderer" import SpriteRenderer from "engine/graphics/plugins/SpriteRenderer"; import Transform2D from "engine/components/Transform2D"; -import {vec2} from "engine/lib/gl-matrix"; +import {vec2} from "../math/math"; import engine, {scheduler} from "engine/engine"; import Script from "engine/processes/Script"; @@ -15,7 +15,7 @@ export default class Camera2D extends Actor {//todo set/get widht//height this._renderer.registerPlugin(new SpriteRenderer()); document.body.appendChild(this._renderer.canvas);//not sure how want to manage access to the dom right now. so tmp here. this.addComponent(new Transform2D()); //think about using a height variable or somthing? :/ Hmm idk. - this.getComponent("transform").scale = [width/2, height/2] //might want to make variables to like set zoom and stuff idk. + this.getComponent("transform").scale = new vec2(width/2, height/2) //might want to make variables to like set zoom and stuff idk. //todo track that script so we can delete it. //also its not in update because I want it to be the last thing that happens @@ -40,12 +40,11 @@ export default class Camera2D extends Actor {//todo set/get widht//height var position = transform.position; var scale = transform.scale; - var tmp = vec2.create(); - tmp[0] = (mouse[0] - window.innerWidth/2); - tmp[1] = (window.innerHeight - mouse[1] - window.innerHeight/2); + var tmp = vec2.zero(); + tmp.x = (mouse.x - window.innerWidth/2); + tmp.y = (window.innerHeight - mouse.y - window.innerHeight/2); - tmp[0] += position[0]; - tmp[1] += position[1]; + tmp.add(position); return tmp; } @@ -56,14 +55,13 @@ export default class Camera2D extends Actor {//todo set/get widht//height var transform = this.getComponent("transform"); var world = target.getComponent("transform").getWorldPosition(); var selfWorld = transform.getWorldPosition(); - var dif = vec2.create(); - vec2.sub(dif, world, selfWorld); - var len = vec2.len(dif); - var scale = (len < 900)? .002:.05; - vec2.scale(dif, dif, .07); + var dif = vec2.subtract(world, selfWorld); + var len = dif.length(); + var scale = (len < 900) ? 0.002 : 0.05; + dif.scale(0.07); var pos = transform.position; - vec2.add(pos, pos, dif); + pos.add(dif) transform.position = pos;