-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from hamaluik/normalizing_shape_api
Normalize Shape API
- Loading branch information
Showing
15 changed files
with
313 additions
and
220 deletions.
There are no files selected for viewing
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
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,50 @@ | ||
package headbutt.shapes; | ||
|
||
using glm.Vec2; | ||
import headbutt.Shape2D; | ||
|
||
class Line2D implements Shape2D { | ||
/** | ||
Start is in global coordinates | ||
*/ | ||
public var start: Vec2; | ||
|
||
/** | ||
End is in global coordinates | ||
*/ | ||
public var end: Vec2; | ||
|
||
private var _origin: Vec2 = new Vec2(0, 0); | ||
public var origin(get, set): Vec2; | ||
|
||
public function new(start: Vec2, end: Vec2) { | ||
this.start = start; | ||
this.end = end; | ||
} | ||
|
||
function get_origin(): Vec2 { | ||
_origin.x = (start.x + end.x) / 2; | ||
_origin.y = (start.y + end.y) / 2; | ||
return _origin; | ||
} | ||
|
||
function set_origin(origin: Vec2): Vec2 { | ||
var dx: Float = origin.x - _origin.x; | ||
var dy: Float = origin.y - _origin.y; | ||
start.x += dx; | ||
end.x += dx; | ||
start.y += dy; | ||
end.y += dy; | ||
|
||
return _origin = origin; | ||
} | ||
|
||
public function support(direction: Vec2): Vec2 { | ||
if(Vec2.dot(start, direction) > Vec2.dot(end, direction)) { | ||
return start; | ||
} | ||
else { | ||
return end; | ||
} | ||
} | ||
} |
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,52 @@ | ||
package headbutt.shapes; | ||
|
||
using glm.Vec2; | ||
import headbutt.Shape2D; | ||
|
||
class Polygon implements Shape2D { | ||
private var _origin: Vec2; | ||
/** | ||
The origin of the polygon in global coordinate space | ||
*/ | ||
public var origin(get, set): Vec2; | ||
|
||
/** | ||
The vertices in the local coordinate space | ||
*/ | ||
public var vertices:Array<Vec2>; | ||
|
||
/** | ||
Create a new polygon | ||
@param origin The location of the polygon in global coordinates | ||
@param vertices The locations of the vertices in local coordinates | ||
*/ | ||
public function new(origin: Vec2, vertices: Array<Vec2>) { | ||
this.origin = origin; | ||
this.vertices = vertices; | ||
} | ||
|
||
function get_origin(): Vec2 { | ||
return _origin; | ||
} | ||
|
||
function set_origin(origin: Vec2): Vec2 { | ||
return _origin = origin; | ||
} | ||
|
||
public function support(direction: Vec2): Vec2 { | ||
var furthestDistance: Float = Math.NEGATIVE_INFINITY; | ||
var furthestVertex: Vec2 = new Vec2(0, 0); | ||
|
||
var vo: Vec2 = new Vec2(); | ||
for(v in vertices) { | ||
vo = v.addVec(origin, vo); | ||
var distance: Float = Vec2.dot(vo, direction); | ||
if(distance > furthestDistance) { | ||
furthestDistance = distance; | ||
furthestVertex = vo.copy(furthestVertex); | ||
} | ||
} | ||
|
||
return furthestVertex; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package headbutt.shapes; | ||
|
||
using glm.Vec3; | ||
import headbutt.Shape3D; | ||
|
||
class Polyhedron implements Shape3D { | ||
private var _origin: Vec3; | ||
/** | ||
The origin of the polygon in global coordinate space | ||
*/ | ||
public var origin(get, set): Vec3; | ||
|
||
/** | ||
The vertices in the local coordinate space | ||
*/ | ||
public var vertices:Array<Vec3>; | ||
|
||
/** | ||
Create a new polygon | ||
@param origin The location of the polygon in global coordinates | ||
@param vertices The locations of the vertices in local coordinates | ||
*/ | ||
public function new(origin: Vec3, vertices: Array<Vec3>) { | ||
this.origin = origin; | ||
this.vertices = vertices; | ||
} | ||
|
||
function get_origin(): Vec3 { | ||
return _origin; | ||
} | ||
|
||
function set_origin(origin: Vec3): Vec3 { | ||
return _origin = origin; | ||
} | ||
|
||
public function support(direction: Vec3): Vec3 { | ||
var furthestDistance: Float = Math.NEGATIVE_INFINITY; | ||
var furthestVertex: Vec3 = new Vec3(0, 0, 0); | ||
|
||
var vo: Vec3 = new Vec3(); | ||
for(v in vertices) { | ||
vo = v.addVec(origin, vo); | ||
var distance: Float = Vec3.dot(vo, direction); | ||
if(distance > furthestDistance) { | ||
furthestDistance = distance; | ||
furthestVertex = vo.copy(furthestVertex); | ||
} | ||
} | ||
|
||
return furthestVertex; | ||
} | ||
} |
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,58 @@ | ||
package headbutt.shapes; | ||
|
||
using glm.Vec2; | ||
import headbutt.Shape2D; | ||
import haxe.ds.Vector; | ||
|
||
class Rectangle implements Shape2D { | ||
private var _origin: Vec2; | ||
public var origin(get, set): Vec2; | ||
|
||
var vertices: Vector<Vec2>; | ||
|
||
public function new(origin: Vec2, halfsize: Vec2) { | ||
this.origin = origin; | ||
this.vertices = new Vector<Vec2>(4); | ||
this.vertices[0] = new Vec2(); | ||
this.vertices[1] = new Vec2(); | ||
this.vertices[2] = new Vec2(); | ||
this.vertices[3] = new Vec2(); | ||
resize(halfsize); | ||
} | ||
|
||
function get_origin(): Vec2 { | ||
return _origin; | ||
} | ||
|
||
function set_origin(origin: Vec2): Vec2 { | ||
return _origin = origin; | ||
} | ||
|
||
public function resize(halfsize: Vec2): Void { | ||
this.vertices[0].x = -1 * halfsize.x; | ||
this.vertices[0].y = -1 * halfsize.y; | ||
this.vertices[1].x = 1 * halfsize.x; | ||
this.vertices[1].y = -1 * halfsize.y; | ||
this.vertices[2].x = 1 * halfsize.x; | ||
this.vertices[2].y = 1 * halfsize.y; | ||
this.vertices[3].x = -1 * halfsize.x; | ||
this.vertices[3].y = 1 * halfsize.y; | ||
} | ||
|
||
public function support(direction: Vec2): Vec2 { | ||
var furthestDistance: Float = Math.NEGATIVE_INFINITY; | ||
var furthestVertex: Vec2 = new Vec2(); | ||
|
||
var vo: Vec2 = new Vec2(); | ||
for(v in vertices) { | ||
vo = v.addVec(origin, vo); | ||
var distance: Float = Vec2.dot(vo, direction); | ||
if(distance > furthestDistance) { | ||
furthestDistance = distance; | ||
furthestVertex = vo.copy(furthestVertex); | ||
} | ||
} | ||
|
||
return furthestVertex; | ||
} | ||
} |
Oops, something went wrong.