Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
45399c7a
Commit
45399c7a
authored
Jul 24, 2015
by
Viktor Lidholt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes formatting and abstraction in GameMath
parent
ab2b7918
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
39 deletions
+37
-39
sprites.dart
packages/flutter/example/game/lib/sprites.dart
+1
-0
util.dart
packages/flutter/example/game/lib/util.dart
+36
-39
No files found.
packages/flutter/example/game/lib/sprites.dart
View file @
45399c7a
...
...
@@ -7,6 +7,7 @@ library sprites;
import
'dart:async'
;
import
'dart:convert'
;
import
'dart:math'
as
math
;
import
'dart:typed_data'
;
import
'dart:sky'
;
import
'package:sky/animation/curves.dart'
;
...
...
packages/flutter/example/game/lib/util.dart
View file @
45399c7a
...
...
@@ -19,67 +19,64 @@ int randomInt(int max) {
// atan2
class
GameMath
{
static
bool
_inited
=
false
;
static
final
int
size
=
1024
;
static
final
double
stretch
=
math
.
PI
;
static
final
int
ezis
=
-
size
;
static
Float64List
atan2_table_ppy
=
new
Float64List
(
size
+
1
);
static
Float64List
atan2_table_ppx
=
new
Float64List
(
size
+
1
);
static
Float64List
atan2_table_pny
=
new
Float64List
(
size
+
1
);
static
Float64List
atan2_table_pnx
=
new
Float64List
(
size
+
1
);
static
Float64List
atan2_table_npy
=
new
Float64List
(
size
+
1
);
static
Float64List
atan2_table_npx
=
new
Float64List
(
size
+
1
);
static
Float64List
atan2_table_nny
=
new
Float64List
(
size
+
1
);
static
Float64List
atan2_table_nnx
=
new
Float64List
(
size
+
1
);
static
void
init
()
{
if
(
_inited
)
return
;
class
_Atan2Constants
{
_Atan2Constants
()
{
for
(
int
i
=
0
;
i
<=
size
;
i
++)
{
double
f
=
i
.
toDouble
()
/
size
.
toDouble
();
atan2_table_
ppy
[
i
]
=
math
.
atan
(
f
)
*
stretch
/
math
.
PI
;
atan2_table_ppx
[
i
]
=
stretch
*
0.5
-
atan2_table_
ppy
[
i
];
atan2_table_pny
[
i
]
=
-
atan2_table_
ppy
[
i
];
atan2_table_pnx
[
i
]
=
atan2_table_
ppy
[
i
]
-
stretch
*
0.5
;
atan2_table_npy
[
i
]
=
stretch
-
atan2_table_
ppy
[
i
];
atan2_table_npx
[
i
]
=
atan2_table_
ppy
[
i
]
+
stretch
*
0.5
;
atan2_table_nny
[
i
]
=
atan2_table_
ppy
[
i
]
-
stretch
;
atan2_table_nnx
[
i
]
=
-
stretch
*
0.5
-
atan2_table_
ppy
[
i
];
ppy
[
i
]
=
math
.
atan
(
f
)
*
stretch
/
math
.
PI
;
ppx
[
i
]
=
stretch
*
0.5
-
ppy
[
i
];
pny
[
i
]
=
-
ppy
[
i
];
pnx
[
i
]
=
ppy
[
i
]
-
stretch
*
0.5
;
npy
[
i
]
=
stretch
-
ppy
[
i
];
npx
[
i
]
=
ppy
[
i
]
+
stretch
*
0.5
;
nny
[
i
]
=
ppy
[
i
]
-
stretch
;
nnx
[
i
]
=
-
stretch
*
0.5
-
ppy
[
i
];
}
_inited
=
true
;
}
static
double
atan2
(
double
y
,
double
x
)
{
if
(!
_inited
)
init
();
static
const
int
size
=
1024
;
static
const
double
stretch
=
math
.
PI
;
static
const
int
ezis
=
-
size
;
final
Float64List
ppy
=
new
Float64List
(
size
+
1
);
final
Float64List
ppx
=
new
Float64List
(
size
+
1
);
final
Float64List
pny
=
new
Float64List
(
size
+
1
);
final
Float64List
pnx
=
new
Float64List
(
size
+
1
);
final
Float64List
npy
=
new
Float64List
(
size
+
1
);
final
Float64List
npx
=
new
Float64List
(
size
+
1
);
final
Float64List
nny
=
new
Float64List
(
size
+
1
);
final
Float64List
nnx
=
new
Float64List
(
size
+
1
);
}
class
GameMath
{
static
final
_Atan2Constants
_atan2
=
new
_Atan2Constants
();
static
double
atan2
(
double
y
,
double
x
)
{
if
(
x
>=
0
)
{
if
(
y
>=
0
)
{
if
(
x
>=
y
)
return
atan2_table_ppy
[(
size
*
y
/
x
+
0.5
).
toInt
()];
return
_atan2
.
ppy
[(
_Atan2Constants
.
size
*
y
/
x
+
0.5
).
floor
()];
else
return
atan2_table_ppx
[(
size
*
x
/
y
+
0.5
).
toInt
()];
return
_atan2
.
ppx
[(
_Atan2Constants
.
size
*
x
/
y
+
0.5
).
floor
()];
}
else
{
if
(
x
>=
-
y
)
return
atan2_table_pny
[(
ezis
*
y
/
x
+
0.5
).
toInt
()];
return
_atan2
.
pny
[(
_Atan2Constants
.
ezis
*
y
/
x
+
0.5
).
floor
()];
else
return
atan2_table_pnx
[(
ezis
*
x
/
y
+
0.5
).
toInt
()];
return
_atan2
.
pnx
[(
_Atan2Constants
.
ezis
*
x
/
y
+
0.5
).
floor
()];
}
}
else
{
if
(
y
>=
0
)
{
if
(-
x
>=
y
)
return
atan2_table_npy
[(
ezis
*
y
/
x
+
0.5
).
toInt
()];
return
_atan2
.
npy
[(
_Atan2Constants
.
ezis
*
y
/
x
+
0.5
).
floor
()];
else
return
atan2_table_npx
[(
ezis
*
x
/
y
+
0.5
).
toInt
()];
return
_atan2
.
npx
[(
_Atan2Constants
.
ezis
*
x
/
y
+
0.5
).
floor
()];
}
else
{
if
(
x
<=
y
)
return
atan2_table_nny
[(
size
*
y
/
x
+
0.5
).
toInt
()];
return
_atan2
.
nny
[(
_Atan2Constants
.
size
*
y
/
x
+
0.5
).
floor
()];
else
return
atan2_table_nnx
[(
size
*
x
/
y
+
0.5
).
toInt
()];
return
_atan2
.
nnx
[(
_Atan2Constants
.
size
*
x
/
y
+
0.5
).
floor
()];
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment