erebus

diff liberebus/src/erebus.cc @ 4:93894c232d65

more changes across the board
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 29 Apr 2014 07:38:40 +0300
parents 474a0244f57d
children 9621beb22694
line diff
     1.1 --- a/liberebus/src/erebus.cc	Mon Apr 28 15:44:59 2014 +0300
     1.2 +++ b/liberebus/src/erebus.cc	Tue Apr 29 07:38:40 2014 +0300
     1.3 @@ -5,6 +5,8 @@
     1.4  #include "erebus.h"
     1.5  #include "vmath/vector.h"
     1.6  #include "image.h"
     1.7 +#include "scene.h"
     1.8 +#include "geomobj.h"
     1.9  
    1.10  using namespace std::chrono;
    1.11  
    1.12 @@ -18,6 +20,8 @@
    1.13  #define INVALID_RECT	Rect{0, 0, 0, 0}
    1.14  
    1.15  struct erebus {
    1.16 +	Scene *scn;
    1.17 +
    1.18  	Image<float> fbimg;
    1.19  	Vector4 options[ERB_NUM_OPTIONS];
    1.20  
    1.21 @@ -43,6 +47,7 @@
    1.22  		return 0;
    1.23  	}
    1.24  
    1.25 +	ctx->scn = 0;
    1.26  	ctx->cur_time = 0;
    1.27  	ctx->cur_rect = INVALID_RECT;
    1.28  	return ctx;
    1.29 @@ -89,6 +94,11 @@
    1.30  void erb_begin_frame(struct erebus *ctx, long ms)
    1.31  {
    1.32  	ctx->cur_time = ms;
    1.33 +
    1.34 +	int xsz = ctx->options[ERB_OPT_WIDTH].x;
    1.35 +	int ysz = ctx->options[ERB_OPT_HEIGHT].x;
    1.36 +
    1.37 +	ctx->fbimg.create(xsz, ysz);
    1.38  }
    1.39  
    1.40  int erb_render(struct erebus *ctx, long timeout)
    1.41 @@ -107,6 +117,8 @@
    1.42  		ctx->cur_pixel_y = y;
    1.43  	}
    1.44  
    1.45 +	ctx->scn->update();
    1.46 +
    1.47  	if(timeout > 0) {
    1.48  		auto start_time = steady_clock::now();
    1.49  		while(duration_cast<milliseconds>(steady_clock::now() - start_time).count() < timeout) {
    1.50 @@ -137,10 +149,20 @@
    1.51  
    1.52  int erb_load_scene(struct erebus *ctx, const char *fname)
    1.53  {
    1.54 -	//delete ctx->scene;
    1.55 -	//ctx->scene = new Scene;
    1.56 +	delete ctx->scn;
    1.57 +	ctx->scn = new Scene;
    1.58  
    1.59 -	return false;	// TODO
    1.60 +	// XXX for now just create a test scene here
    1.61 +	Sphere *sph = new Sphere;
    1.62 +	SceneNode *sph_node = new SceneNode(sph);
    1.63 +	ctx->scn->add_object(sph);
    1.64 +	ctx->scn->add_node(sph_node);
    1.65 +
    1.66 +	TargetCamera *cam = new TargetCamera(Vector3(0, 0, -10), Vector3(0, 0, 0));
    1.67 +	//ctx->scn->add_object(cam);
    1.68 +	ctx->scn->use_camera(cam);
    1.69 +
    1.70 +	return 0;
    1.71  }
    1.72  
    1.73  }	// extern "C"