forked from HeapsIO/heaps
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-svn-id: http://hq.motion-twin.com/svn/galaxy55/fla/engine@18 ebaa5d33-9041-4c07-8396-3622ceb66f44
- Loading branch information
ncannasse
committed
Feb 9, 2012
0 parents
commit 13d10b9
Showing
24 changed files
with
2,025 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-cp samples | ||
-swf engine.swf | ||
-swf-header 800:600:30:FFFFFF | ||
--flash-strict | ||
-swf-version 11 | ||
-main Test | ||
-lib format |
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,55 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<project version="2"> | ||
<!-- Output SWF options --> | ||
<output> | ||
<movie outputType="Application" /> | ||
<movie input="" /> | ||
<movie path="engine.swf" /> | ||
<movie fps="30" /> | ||
<movie width="800" /> | ||
<movie height="600" /> | ||
<movie version="11" /> | ||
<movie minorVersion="0" /> | ||
<movie platform="Flash Player" /> | ||
<movie background="#FFFFFF" /> | ||
</output> | ||
<!-- Other classes to be compiled into your SWF --> | ||
<classpaths> | ||
<class path="samples" /> | ||
</classpaths> | ||
<!-- Build options --> | ||
<build> | ||
<option directives="" /> | ||
<option flashStrict="True" /> | ||
<option mainClass="Test" /> | ||
<option enabledebug="False" /> | ||
<option additional="-lib format" /> | ||
</build> | ||
<!-- haxelib libraries --> | ||
<haxelib> | ||
<!-- example: <library name="..." /> --> | ||
</haxelib> | ||
<!-- Class files to compile (other referenced classes will automatically be included) --> | ||
<compileTargets> | ||
<!-- example: <compile path="..." /> --> | ||
</compileTargets> | ||
<!-- Assets to embed into the output SWF --> | ||
<library> | ||
<!-- example: <asset path="..." id="..." update="..." glyphs="..." mode="..." place="..." sharepoint="..." /> --> | ||
</library> | ||
<!-- Paths to exclude from the Project Explorer tree --> | ||
<hiddenPaths> | ||
<hidden path="engine.hxml" /> | ||
</hiddenPaths> | ||
<!-- Executed before build --> | ||
<preBuildCommand /> | ||
<!-- Executed after build --> | ||
<postBuildCommand alwaysRun="False" /> | ||
<!-- Other project options --> | ||
<options> | ||
<option showHiddenPaths="False" /> | ||
<option testMovie="Default" /> | ||
</options> | ||
<!-- Plugin storage --> | ||
<storage /> | ||
</project> |
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,100 @@ | ||
package h3d; | ||
|
||
// use left-handed coordinate system, more suitable for 2D games X=0,Y=0 at screen top-left and Z towards user | ||
|
||
class Camera { | ||
|
||
public var zoom : Float; | ||
public var ratio : Float; | ||
public var fov : Float; | ||
public var zNear : Float; | ||
public var zFar : Float; | ||
|
||
public var mproj : Matrix; | ||
public var mcam : Matrix; | ||
public var m : Matrix; | ||
|
||
public var pos : Vector; | ||
public var up : Vector; | ||
public var target : Vector; | ||
|
||
public function new( fov = 60., zoom = 1., ratio = 1.333333, zNear = 0.02, zFar = 4000. ) { | ||
this.fov = fov; | ||
this.zoom = zoom; | ||
this.ratio = ratio; | ||
this.zNear = zNear; | ||
this.zFar = zFar; | ||
pos = new Vector(2, 3, 4); | ||
up = new Vector(0, 0, -1); | ||
target = new Vector(0, 0, 0); | ||
m = new Matrix(); | ||
mcam = new Matrix(); | ||
update(); | ||
} | ||
|
||
public function update() { | ||
var az = pos.sub(target); | ||
az.normalize(); | ||
var ax = up.cross(az); | ||
ax.normalize(); | ||
if( ax.length() == 0 ) { | ||
ax.x = az.y; | ||
ax.y = az.z; | ||
ax.z = az.x; | ||
} | ||
var ay = az.cross(ax); | ||
mcam._11 = ax.x; | ||
mcam._12 = ay.x; | ||
mcam._13 = az.x; | ||
mcam._14 = 0; | ||
mcam._21 = ax.y; | ||
mcam._22 = ay.y; | ||
mcam._23 = az.y; | ||
mcam._24 = 0; | ||
mcam._31 = ax.z; | ||
mcam._32 = ay.z; | ||
mcam._33 = az.z; | ||
mcam._34 = 0; | ||
mcam._41 = -ax.dot3(pos); | ||
mcam._42 = -ay.dot3(pos); | ||
mcam._43 = -az.dot3(pos); | ||
mcam._44 = 1; | ||
mproj = makeFrustumMatrix(); | ||
m.multiply4x4(mcam, mproj); | ||
} | ||
|
||
public function lostUp() { | ||
var p2 = pos.copy(); | ||
p2.normalize(); | ||
return Math.abs(p2.dot3(up)) > 0.999; | ||
} | ||
|
||
public function movePosAxis( dx : Float, dy : Float, dz = 0. ) { | ||
var p = new Vector(dx, dy, dz); | ||
p.project3x3(mcam); | ||
pos.x += p.x; | ||
pos.y += p.y; | ||
pos.z += p.z; | ||
} | ||
|
||
public function moveTargetAxis( dx : Float, dy : Float, dz = 0. ) { | ||
var p = new Vector(dx, dy, dz); | ||
p.project3x3(mcam); | ||
target.x += p.x; | ||
target.y += p.y; | ||
target.z += p.z; | ||
} | ||
|
||
function makeFrustumMatrix() { | ||
var scale = zoom / Math.tan(fov * Math.PI / 360.0); | ||
var m = new Matrix(); | ||
m.zero(); | ||
m._11 = scale; | ||
m._22 = -scale * ratio; | ||
m._33 = zFar / (zNear - zFar); | ||
m._34 = -1; | ||
m._43 = (zNear * zFar) / (zNear - zFar); | ||
return m; | ||
} | ||
|
||
} |
Oops, something went wrong.