My favorites
▼
|
Sign in
hxcpp
Runtime files for c++ backend for haxe
Project Home
Wiki
Issues
Source
Export to GitHub
READ-ONLY: This project has been
archived
. For more information see
this post
.
Search
Search within:
All issues
Open issues
New issues
Issues to verify
for
Advanced search
Search tips
Subscriptions
Issue
241
attachment: Main.hx
(2.9 KB)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package ;
import flash.geom.Matrix;
import nme.display.Sprite;
import nme.events.Event;
import nme.Lib;
/**
> windows :
Main.hx:55: a:-7.846216259 b:4.758861713 c:-1.939691333 d:-0.9539112819 tx:-4156.556546 ty:3215.633234
Main.hx:55: a:-2.603800168 b:2.205347492 c:14.87864923 d:-2.51779341 tx:-5619.205618 ty:3465.634975
> flash:
Main.hx:51: a:-7.846216259435015 b:4.75886171337419 c:-0.37082039324993715 d:-2.130366596501144 tx:-507.76752397725187 ty:1384.5380043199248
Main.hx:51: a:-3.0648797685111755 b:2.5510990336999413 c:23.57707297724791 d:-5.1536925696119855 tx:-482.4740211408821 ty:1600.151510254845
* @author
*/
class Main extends Sprite
{
var inited:Bool;
/* ENTRY POINT */
function resize(e)
{
if (!inited) init();
// else (resize or orientation change)
}
/** Prepends a matrix to 'base' by multiplying it with another matrix. */
function prependMatrix(base:Matrix, prep:Matrix):Matrix
{
setTo( base,
base.a * prep.a + base.c * prep.b,
base.b * prep.a + base.d * prep.b,
base.a * prep.c + base.c * prep.d,
base.b * prep.c + base.d * prep.d,
base.tx + base.a * prep.tx + base.c * prep.ty,
base.ty + base.b * prep.tx + base.d * prep.ty);
return base;
}
inline function setTo(m:Matrix, a:Float, b:Float, c:Float, d:Float, tx:Float, ty:Float )
{
m.a = a;
m.b = b;
m.c = c;
m.d = d;
m.tx = tx;
m.ty = ty;
}
function traceM(m:Matrix)
{
trace("a:" + m.a + " b:" + m.b + " c:" + m.c + " d:" + m.d + " tx:" + m.tx + " ty:" + m.ty);
}
function getM( m :Matrix, rotation:Float, scaleX:Float, scaleY:Float, dx : Float, dy:Float, pivotX:Float, pivotY:Float )
{
var cos = Math.cos(rotation);
var sin = Math.sin(rotation);
var a = scaleX * cos;
var b = scaleX * sin;
var c = scaleY * -sin;
var d = scaleY * cos;
var tx = dx - pivotX * a - pivotY * c;
var ty = dy - pivotX * b - pivotY * d;
setTo(m, a, b, c, d, tx, ty);
}
function init()
{
if (inited) return;
inited = true;
var ma = new Matrix();
getM(ma, Math.PI, 1.5, -2.8, 200, 800, 50, -35);
var mb = new Matrix();
getM(mb, Math.PI * 0.1, 5.5, -.8, 0, 0, -100, 5);
var mc = new Matrix();
getM(mc, -1.2 * Math.PI, -.5, 4.8, 0, -100, 0, 0.5);
trace("Complete:");
traceM(prependMatrix(ma, mb));
traceM(prependMatrix(ma, mc));
}
/* SETUP */
public function new()
{
super();
addEventListener(Event.ADDED_TO_STAGE, added);
}
function added(e)
{
removeEventListener(Event.ADDED_TO_STAGE, added);
stage.addEventListener(Event.RESIZE, resize);
#if ios
haxe.Timer.delay(init, 100); // iOS 6
#else
init();
#end
}
public static function main()
{
// static entry point
Lib.current.stage.align = nme.display.StageAlign.TOP_LEFT;
Lib.current.stage.scaleMode = nme.display.StageScaleMode.NO_SCALE;
Lib.current.addChild(new Main());
}
}
Powered by
Google Project Hosting