erebus

diff liberebus/src/erebus.cc @ 18:09028848f276

- implemented Box object intersection - implemented interactive camera manipulation
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 26 May 2014 23:34:12 +0300
parents e9da2916bc79
children 6204e4d3f445
line diff
     1.1 --- a/liberebus/src/erebus.cc	Mon May 26 05:41:28 2014 +0300
     1.2 +++ b/liberebus/src/erebus.cc	Mon May 26 23:34:12 2014 +0300
     1.3 @@ -210,13 +210,13 @@
     1.4  	ctx->scn->add_object(sph);
     1.5  	ctx->scn->add_node(sph_node);
     1.6  
     1.7 -	sph = new Sphere;
     1.8 -	sph->mtl.set_attrib("diffuse", Color(0.3, 0.4, 1.0));
     1.9 -	sph_node = new SceneNode(sph);
    1.10 -	sph_node->set_position(Vector3(0, -251.0, 0));
    1.11 -	sph_node->set_scaling(Vector3(250.0, 250.0, 250.0));
    1.12 -	ctx->scn->add_object(sph);
    1.13 -	ctx->scn->add_node(sph_node);
    1.14 +	Box *box = new Box;
    1.15 +	box->mtl.set_attrib("diffuse", Color(0.9, 0.8, 0.75));
    1.16 +	SceneNode *box_node = new SceneNode(box);
    1.17 +	box_node->set_position(Vector3(0, -1.25, 0));
    1.18 +	box_node->set_scaling(Vector3(5, 0.5, 5));
    1.19 +	ctx->scn->add_object(box);
    1.20 +	ctx->scn->add_node(box_node);
    1.21  
    1.22  	Sphere *lt = new Sphere;
    1.23  	lt->mtl.set_attrib("emissive", Color(10, 10, 10));
    1.24 @@ -304,11 +304,38 @@
    1.25  
    1.26  bool erb_input_mouse_motion(struct erebus *ctx, int x, int y)
    1.27  {
    1.28 -	if(!ctx) return false;
    1.29 +	bool res = false;
    1.30 +
    1.31 +	if(!ctx) return res;
    1.32 +
    1.33 +	int dx = x - ctx->mouse_pos[0];
    1.34 +	int dy = y - ctx->mouse_pos[1];
    1.35 +
    1.36 +	if(dx || dy) {
    1.37 +		TargetCamera *cam = (TargetCamera*)ctx->scn->get_active_camera();
    1.38 +		if(cam && ctx->bnstate[0]) {
    1.39 +			Vector3 cpos = cam->get_position();
    1.40 +			float mag = cpos.length();
    1.41 +
    1.42 +			float theta = atan2(cpos.z / mag, cpos.x / mag) + DEG_TO_RAD(dx * 0.5);
    1.43 +			float phi = acos(cpos.y / mag) + DEG_TO_RAD(dy * 0.5);
    1.44 +
    1.45 +			if(phi < 0) phi = 0;
    1.46 +			if(phi > M_PI) phi = M_PI;
    1.47 +
    1.48 +			cpos.x = cos(theta) * sin(phi) * mag;
    1.49 +			cpos.y = cos(phi) * mag;
    1.50 +			cpos.z = sin(theta) * sin(phi) * mag;
    1.51 +			cam->set_position(cpos);
    1.52 +
    1.53 +			erb_begin_frame(ctx, 0);
    1.54 +			res = true;
    1.55 +		}
    1.56 +	}
    1.57  
    1.58  	ctx->mouse_pos[0] = x;
    1.59  	ctx->mouse_pos[1] = y;
    1.60 -	return false;
    1.61 +	return res;
    1.62  }
    1.63  
    1.64  bool erb_input_6dof_button(struct erebus *ctx, int bn, bool pressed)