Skip to content

Commit

Permalink
syncronizing with local version
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkOates committed Mar 23, 2015
1 parent c245224 commit 2d79955
Show file tree
Hide file tree
Showing 15 changed files with 126 additions and 53 deletions.
3 changes: 3 additions & 0 deletions include/allegro_flare/allegro_flare.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@



#define ALLEGRO_FLARE_VER "0.8.3"


#include <allegro5/allegro.h>
#include <allegro5/allegro_image.h>
Expand Down Expand Up @@ -63,6 +65,7 @@ class af
static ALLEGRO_TEXTLOG *textlog;
static ALLEGRO_JOYSTICK *joystick; // this needs some updating to allow for multiple joysticks
static ALLEGRO_EVENT_QUEUE *event_queue;
static ALLEGRO_FONT *builtin_font;
static ALLEGRO_TIMER *primary_timer;
static bool shutdown_program;
static Screen *current_screen;
Expand Down
20 changes: 17 additions & 3 deletions include/allegro_flare/camera3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@




struct camera_tracking_setting // TODO: <-this
{

};


class Camera3D
{
public:

enum camera_tracking_mode_t
{
CAMERA_VIEW_DIRECT,
CAMERA_VIEW_DIRECT = 0,
CAMERA_VIEW_THIRD_PERSON_HIGH,
CAMERA_VIEW_THIRD_PERSON,
CAMERA_VIEW_FRIST_PERSON,
Expand All @@ -26,6 +33,13 @@ class Camera3D
CAMERA_VIEW_LAST // for mod
};

bool is_fixed_on_axis; // so, the controls will change when the camera is fixed along an axis (CAMERA_VIEW_TRACK_ALONG_X, etc)
// When in first person (or in camera views where the camera is always behind the head of the player),
// then UP is forward, DOWN is backward, LEFT turns left and RIGHT turns right.
// When the camera is fixed on an axis, then the player's direction will be the direction that the
// input points.
int camera_tracking_mode;

vec3d position;
vec3d view_vector;
vec3d up_vector;
Expand All @@ -39,11 +53,11 @@ class Camera3D
vec3d stepback_rotation;


Camera3D(vec3d position, vec3d view_vector=vec3d(0, 0, 1), vec3d up_vector=vec3d(0, 1, 0));
Camera3D(vec3d position, vec3d view_vector=vec3d(0, 0, 1), vec3d up_vector=vec3d(0, 1, 0)); // yea, up vector should be positive
void set_frustum_as_camera(ALLEGRO_DISPLAY *d);

void look_at(vec3d target);
void update_camera_tracking(vec3d targets_position, vec3d targets_view_vector, camera_tracking_mode_t camera_tracking_mode);
void update_camera_tracking(vec3d targets_position, vec3d targets_view_vector);

Frustum get_frustum(ALLEGRO_DISPLAY *d);
};
Expand Down
4 changes: 2 additions & 2 deletions include/allegro_flare/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ class Display
static Display *find_display(ALLEGRO_DISPLAY *display);
ALLEGRO_COLOR _background_color;

Display(int width, int height, int display_flags); // you must use AllegroFlare::create_display

int _width, _height;

public:
Display(int width, int height, int display_flags); // you must use AllegroFlare::create_display

ALLEGRO_DISPLAY *display; // TODO: change this to al_display
virtual void display_close_func();

Expand Down
1 change: 1 addition & 0 deletions include/allegro_flare/music_notation.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class MusicNotation
void set_spacing_method(spacing_method_t method);

static float get_duration_fixed_width(int duration, float quarter_note_width, int num_dots);
char duration_denominator_to_char(int denominator);
};


Expand Down
5 changes: 5 additions & 0 deletions include/allegro_flare/useful3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ static void draw_3d_triangle(vec3d v1, vec3d v2, vec3d v3, ALLEGRO_COLOR col)
al_draw_prim(vtx, NULL, NULL, 0, 3, ALLEGRO_PRIM_TRIANGLE_FAN);
}

static bool basically_equal(const vec3d &first, const vec3d &other, float threshold)
{
return fabs(first.x - other.x) < threshold && fabs(first.y - other.y) < threshold && fabs(first.z - other.z) < threshold;
}




Expand Down
5 changes: 3 additions & 2 deletions include/allegro_flare/vec3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ class vec3d
return !(*this == other);
}

inline std::string ToString() const {
inline std::string ToString(int precision=5) const {
std::ostringstream str;
str << "( " << x << ", " << y << ", " << z << " )";
str.precision(precision);
str << "( " << std::fixed << x << ", " << std::fixed << y << ", " << std::fixed << z << " )";
return str.str();
}

Expand Down
11 changes: 5 additions & 6 deletions src/allegro_flare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,10 @@ void af::initialize(std::string config_filename)
primary_timer = al_create_timer(ALLEGRO_BPS_TO_SECS(60));

al_set_new_bitmap_flags(ALLEGRO_MIN_LINEAR | ALLEGRO_MAG_LINEAR | ALLEGRO_MIPMAP);
al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 2, ALLEGRO_SUGGEST);
al_set_new_display_option(ALLEGRO_DEPTH_SIZE, 256, ALLEGRO_SUGGEST); // hmm... not sure about this one either
al_set_new_display_option(ALLEGRO_SAMPLES, 4, ALLEGRO_SUGGEST);
al_set_new_display_flags(ALLEGRO_OPENGL);

al_init_user_event_source(&_user_event_src_for_faking_events); /////
builtin_font = al_create_builtin_font();

al_init_user_event_source(&_user_event_src_for_faking_events); ///// TODO: didn't work, take this one out and it's infesting(!) code

event_queue = al_create_event_queue();
al_register_event_source(event_queue, &_user_event_src_for_faking_events); /////
Expand Down Expand Up @@ -204,7 +202,7 @@ void af::run_loop()
case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN:
Screen::mouse_down_funcs();
break;
case ALLEGRO_EVENT_MOUSE_WARPED: // hmm, now adding mouse_warped events to mouse_axes for joystick-as-mouse emulation
//case ALLEGRO_EVENT_MOUSE_WARPED: // hmm, now adding mouse_warped events to mouse_axes for joystick-as-mouse emulation
case ALLEGRO_EVENT_MOUSE_AXES:
Screen::mouse_axes_funcs();
break;
Expand Down Expand Up @@ -285,6 +283,7 @@ ALLEGRO_TEXTLOG *af::textlog = NULL;
ALLEGRO_JOYSTICK *af::joystick = NULL;
ALLEGRO_EVENT_QUEUE *af::event_queue = NULL;
ALLEGRO_TIMER *af::primary_timer = NULL;
ALLEGRO_FONT *af::builtin_font = NULL;
bool af::shutdown_program = false;
Screen *af::current_screen = NULL;
double af::time_now = 0;
Expand Down
41 changes: 25 additions & 16 deletions src/camera3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,48 +16,53 @@ Camera3D::Camera3D(vec3d position, vec3d view_vector, vec3d up_vector)
, stepback(0)
, stepback_pitch(0)
, stepback_rotation(0)
, camera_tracking_mode(Camera3D::CAMERA_VIEW_THIRD_PERSON_HIGH)
{}




void Camera3D::update_camera_tracking(vec3d targets_position, vec3d targets_view_vector, camera_tracking_mode_t camera_tracking_mode)
void Camera3D::update_camera_tracking(vec3d targets_position, vec3d targets_view_vector)
{
vec3d view_vec(0, 0, 0);

switch(camera_tracking_mode)
{
case CAMERA_VIEW_THIRD_PERSON:
// a nice third person view:
case CAMERA_VIEW_THIRD_PERSON_HIGH:
// a nice, semi angled birds eye view:
is_fixed_on_axis = false;
position = targets_position;
stepback = targets_view_vector * -3;
stepback += vec3d(0, 2, 0); // ascent
stepback_pitch = -0.05;
stepback += vec3d(0, 5, 0); // ascent
stepback_pitch = -0.6;
pitch = 0;
view_vector = targets_view_vector;
break;
case CAMERA_VIEW_THIRD_PERSON_HIGH:
// a nice, semi angled birds eye view:
case CAMERA_VIEW_THIRD_PERSON:
// a nice third person view:
is_fixed_on_axis = false;
position = targets_position;
stepback = targets_view_vector * -3;
stepback += vec3d(0, 5, 0); // ascent
stepback_pitch = -0.6;
stepback += vec3d(0, 2, 0); // ascent
stepback_pitch = -0.05;
pitch = 0;
view_vector = targets_view_vector;
break;
case CAMERA_VIEW_FRIST_PERSON:
// a first person view:
is_fixed_on_axis = false;
position = targets_position;
stepback = 0;
stepback += vec3d(0, 1.25, 0); // ascent
stepback_pitch = -0.03;
stepback_pitch = 0.2;
//pitch = 0; // in first person, pitch is controlled by the mouse
view_vector = targets_view_vector;
break;
case CAMERA_VIEW_TRACK_ALONG_X:
// a first person view:
is_fixed_on_axis = true;
position = targets_position;
view_vec = vec3d(1, 0, 0);
view_vec = vec3d(0, 0, -1);
stepback = view_vec * -10;
stepback += vec3d(0, 5, 0); // ascent
stepback_pitch = -0.05;
Expand All @@ -66,8 +71,9 @@ void Camera3D::update_camera_tracking(vec3d targets_position, vec3d targets_view
break;
case CAMERA_VIEW_TRACK_ALONG_X_HIGH:
// a first person view:
is_fixed_on_axis = true;
position = targets_position;
view_vec = vec3d(1, 0, 0);
view_vec = vec3d(0, 0, -1);
stepback = view_vec * -12;
stepback += vec3d(0, 10, 0); // ascent
pitch = 0;
Expand All @@ -76,8 +82,9 @@ void Camera3D::update_camera_tracking(vec3d targets_position, vec3d targets_view
break;
case CAMERA_VIEW_TRACK_ALONG_X_BIRD:
// a first person view:
is_fixed_on_axis = true;
position = targets_position;
view_vec = vec3d(1, 0, 0);
view_vec = vec3d(0, 0, -1);
stepback = view_vec * -8;
stepback += vec3d(0, 12, 0); // ascent
pitch = 0;
Expand Down Expand Up @@ -120,7 +127,7 @@ void Camera3D::set_frustum_as_camera(ALLEGRO_DISPLAY *d)
// the view vector, maybe something with ALLEGRO doing pixel coordinates,
// but I'm a little unsure, hopefully this line will be resolved properly somewherre else and
// not needed in the future:
al_translate_transform_3d(&transform, 0.5, 0.5, 0);
//al_translate_transform_3d(&transform, 0.5, 0.5, 0); // HHHHAAAAAALLLLLEEELULAAHH! o:D

al_translate_transform_3d(&transform, -position.x-stepback.x, -position.y-stepback.y, -position.z-stepback.z); // hmm, using negatives is new
//al_translate_transform_3d(&transform, , , ); // hmm, using negatives is new
Expand All @@ -132,21 +139,23 @@ void Camera3D::set_frustum_as_camera(ALLEGRO_DISPLAY *d)
// This one is not correct:
// al_rotate_transform_3d(&transform, 0, 0, 1, 0.1 * TAU); // tilt the camera to look downward slightly
// I believe this one is correct:

al_rotate_transform_3d(&transform, 0, 1, 0, thing.get_angle() + TAU/4);//(al_get_time()*0.2));

// This one, *might* be correct:
//al_rotate_transform_3d(&transform, 1, 0, 0, vec2d(view_vector.y, view_vector.z).get_angle() - TAU/4);



// this is the vector for roll
al_rotate_transform_3d(&transform, 0, 0, 1, (TAU/2)); // flip the world ... ? // maybe this messes with the strafe and up vectors
//al_rotate_transform_3d(&transform, 0, 0, 1, (TAU/2)); // flip the world ... ? // maybe this messes with the strafe and up vectors



al_rotate_transform_3d(&transform, 0, 1, 0, stepback_rotation.y); // tilt the camera to look downward slightly
//al_rotate_transform_3d(&transform, 1, 0, 0, pitch); // tilt the camera to look downward slightly
//al_translate_transform_3d(&transform, stepback.x, stepback.y, stepback.z); // hmm, using negatives is new
al_rotate_transform_3d(&transform, 1, 0, 0, stepback_pitch + pitch); // the up-down tilt of the camera
al_rotate_transform_3d(&transform, -1, 0, 0, stepback_pitch + pitch); // the up-down tilt of the camera



Expand Down
13 changes: 8 additions & 5 deletions src/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ Display *Display::find_display(ALLEGRO_DISPLAY *display)


Display::Display(int width, int height, int display_flags)
: _background_color(color::darkgoldenrod)
: _background_color(color::hex("6ca3fe"))
, _width(width)
, _height(height)
{
//if (fullscreen) al_set_new_display_flags(ALLEGRO_FULLSCREEN);
al_set_new_display_flags(display_flags);
//al_set_new_display_flags(display_flags | ALLEGRO_PROGRAMMABLE_PIPELINE);
//al_set_new_display_option(ALLEGRO_VSYNC, 2, ALLEGRO_REQUIRE); // requires vsync to be OFF
al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 2, ALLEGRO_SUGGEST);
al_set_new_display_option(ALLEGRO_DEPTH_SIZE, 256, ALLEGRO_SUGGEST); // hmm... not sure about this one either
al_set_new_display_option(ALLEGRO_SAMPLES, 4, ALLEGRO_SUGGEST);
al_set_new_display_flags(display_flags | ALLEGRO_OPENGL); // At this time, OpenGL is requied for AllegroFlare
// as there are certain features that are not working
// in Direct3d mode

display = al_create_display(width, height);
displays.push_back(this);
}
Expand Down
8 changes: 4 additions & 4 deletions src/frustum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
Frustum::Frustum(int width, int height, int znear, float multiplier)
: znear(znear * multiplier)
, zfar(30000)
, top(-height/2 * multiplier)
, left(-width/2 * multiplier)
, bottom(height/2 * multiplier)
, right(width/2 * multiplier)
, top(height/2 * multiplier) //+ //- <-previously
, left(-width/2 * multiplier) //- //-
, bottom(-height/2 * multiplier) //- //+
, right(width/2 * multiplier) //+ //+
{}


Expand Down
30 changes: 18 additions & 12 deletions src/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ void Model::Object::draw(ALLEGRO_BITMAP *texture, ALLEGRO_COLOR col)
for (unsigned i=0; i<face_index_lists.size(); i++)
{
//texture = textures.get_texture(i);

if (has_uv_coordinates && texture && !uv_index_lists.empty())
{
// reset the uv coordinates
Expand All @@ -154,7 +155,7 @@ void Model::Object::draw(ALLEGRO_BITMAP *texture, ALLEGRO_COLOR col)
al_draw_indexed_prim(&parent->vertexes[0], NULL, has_uv_coordinates ? texture : NULL, &face_index_lists[i][0], face_index_lists[i].size(), prim_type);

// draw lines
//al_draw_indexed_prim(&parent->vertexes[0], NULL, NULL, &face_index_lists[i][0], face_index_lists[i].size(), ALLEGRO_PRIM_LINE_LOOP);
//al_draw_indexed_prim(&parent->vertexes[0], NULL, NULL, &face_index_lists[i][0], face_index_lists[i].size(), ::ALLEGRO_PRIM_TRIANGLE_LIST);

// draw colored prim
//al_draw_indexed_prim(&parent->vertexes[0], NULL, NULL, &face_index_lists[i][0], face_index_lists[i].size(), ALLEGRO_PRIM_LINE_LOOP);
Expand Down Expand Up @@ -466,7 +467,9 @@ bool Model::load_obj_file(std::string filename, ALLEGRO_COLOR color)
{
clear();

std::cout << "Loading Model..." << std::endl; // filename << "\"" << std::endl;
bool verbose = false;

if (verbose) std::cout << "Loading Model..." << std::endl; // filename << "\"" << std::endl;


std::ifstream in(filename, std::ios::in);
Expand Down Expand Up @@ -501,7 +504,7 @@ bool Model::load_obj_file(std::string filename, ALLEGRO_COLOR color)

line_count++;

if (line_count%10000 == 0) std::cout << "..." << line_count;
if (verbose) if (line_count%10000 == 0) std::cout << "..." << line_count;

// std::cout << ".";

Expand Down Expand Up @@ -559,7 +562,7 @@ bool Model::load_obj_file(std::string filename, ALLEGRO_COLOR color)
{
if (objects.empty()) // this statement and its contents was recenty revised, though it may cause some problems with backward compatib
{
std::cout << " ! Object not explicitly declared (auto-creating)" << std::endl;
if (verbose) std::cout << " ! Object not explicitly declared (auto-creating)" << std::endl;
objects.push_back(Object(this));
objects.back().prim_type = ALLEGRO_PRIM_TRIANGLE_FAN;
objects.back().name = "[INTERNALLY_CREATED_UNNAMED_INITIAL_GROUP]";
Expand Down Expand Up @@ -612,15 +615,18 @@ bool Model::load_obj_file(std::string filename, ALLEGRO_COLOR color)
// std::cout << "<5>";
}

std::cout << " Loaded Successfully" << std::endl;
std::cout << " objects.size(): " << objects.size() << std::endl;
std::cout << " uvs.size(): " << uvs.size() << std::endl;
std::cout << " vertexes.size(): " << vertexes.size() << std::endl;
for (unsigned i=0; i<objects.size(); i++)
if (verbose)
{
std::cout << " + object " << i << " (" << objects[i].name << ")" << std::endl;
std::cout << " face_index_lists.size(): " << objects[i].face_index_lists.size() << std::endl;
std::cout << " uv_index_lists.size(): " << objects[i].uv_index_lists.size() << std::endl;
std::cout << " Loaded Successfully" << std::endl;
std::cout << " objects.size(): " << objects.size() << std::endl;
std::cout << " uvs.size(): " << uvs.size() << std::endl;
std::cout << " vertexes.size(): " << vertexes.size() << std::endl;
for (unsigned i=0; i<objects.size(); i++)
{
std::cout << " + object " << i << " (" << objects[i].name << ")" << std::endl;
std::cout << " face_index_lists.size(): " << objects[i].face_index_lists.size() << std::endl;
std::cout << " uv_index_lists.size(): " << objects[i].uv_index_lists.size() << std::endl;
}
}

return true;
Expand Down
Loading

0 comments on commit 2d79955

Please sign in to comment.