Skip to content

Commit 30ca5fd

Browse files
committed
Added Vector2::SetFromAngleDegrees. Renamed Random::Range to Random::Int and Random::RangeFloat to Random::Float. Added rotation to Graphic.
1 parent e7264a6 commit 30ca5fd

File tree

6 files changed

+27
-8
lines changed

6 files changed

+27
-8
lines changed

Core/Graphics.h

+3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ namespace Monocle
3535
class Graphic
3636
{
3737
public:
38+
Graphic() : rotation(0.0f)
39+
{}
3840
Vector2 position;
41+
float rotation;
3942
//virtual void Update()=0;
4043
virtual void Render(Entity *entity)=0;
4144
virtual void GetWidthHeight(int *width, int *height)=0;

Core/Graphics/Sprite.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ namespace Monocle
114114
{
115115
Graphics::PushMatrix();
116116
Graphics::Translate(position.x, position.y, 0.0f);
117+
Graphics::Rotate(rotation, 0, 0, 0);
117118

118119
if (Debug::selectedEntity == entity)
119120
Graphics::SetColor(Color::orange);

Core/Random.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,20 @@ namespace Monocle
1414
srand(seed);
1515
}
1616

17-
int Random::Range(int start, int end)
17+
int Random::Int(int start, int end)
1818
{
1919
return start + (rand() % (end-start));
2020
}
2121

22-
float Random::Percent()
22+
float Random::Float(float start, float end)
2323
{
24-
return ((float) rand()) / (float) RAND_MAX;
24+
return ((((float) rand()) / (float) RAND_MAX) * (end-start)) + start;
2525
}
2626

27-
float Random::RangeFloat(float start, float end)
27+
float Random::Percent()
2828
{
29-
return ((((float) rand()) / (float) RAND_MAX) * (end-start)) + start;
29+
return ((float) rand()) / (float) RAND_MAX;
3030
}
31+
32+
3133
}

Core/Random.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ namespace Monocle
77
public:
88
Random();
99
static void Seed(unsigned int seed);
10-
static int Range(int start, int end);
10+
static int Int(int start, int end);
11+
static float Float(float start, float end);
1112
static float Percent();
12-
static float RangeFloat(float start, float end);
13+
1314
private:
1415
//static Random *instance;
1516
};

Core/Vector2.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ namespace Monocle
3434

3535
Vector2 Vector2::Random()
3636
{
37-
float rad = (Random::Range(0,360)) * Monocle::deg2Rad;
37+
float rad = (Random::Int(0,360)) * Monocle::deg2Rad;
38+
//x = sin(rad);
39+
//y = cos(rad);
3840
return Vector2(sin(rad), cos(rad));
3941
}
4042

@@ -71,6 +73,14 @@ namespace Monocle
7173
return Vector2(y, -x);
7274
}
7375

76+
void Vector2::SetFromAngleDegrees(float angle)
77+
{
78+
x = sin(angle * Monocle::deg2Rad);
79+
y = cos(angle * Monocle::deg2Rad);
80+
81+
printf("angle %f x,y (%f, %f)\n", angle, x, y);
82+
}
83+
7484
void Vector2::Clamp(float max)
7585
{
7686
if ((pow(x, 2) + pow(y, 2)) > pow(max, 2))

Core/Vector2.h

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ namespace Monocle
4343
//! return angle in radians
4444
float GetAngleRadians();
4545
float GetAngleDegrees();
46+
//! initialize x and y from the passed angle in degrees
47+
void SetFromAngleDegrees(float angle);
4648

4749
/*
4850
static Vector2 Add(Vector2 a, Vector2 b);

0 commit comments

Comments
 (0)