erebus

changeset 1:59a72293f9bd

continuing
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 28 Apr 2014 05:58:22 +0300
parents 4abdce1361b9
children 474a0244f57d
files liberebus/liberebus.vcxproj liberebus/liberebus.vcxproj.filters liberebus/src/scene.cc liberebus/src/scene.h liberebus/src/snode.cc liberebus/src/snode.h
diffstat 6 files changed, 184 insertions(+), 6 deletions(-) [+]
line diff
     1.1 --- a/liberebus/liberebus.vcxproj	Sun Apr 27 16:02:47 2014 +0300
     1.2 +++ b/liberebus/liberebus.vcxproj	Mon Apr 28 05:58:22 2014 +0300
     1.3 @@ -30,6 +30,8 @@
     1.4      <ClCompile Include="src\camera.cc" />
     1.5      <ClCompile Include="src\erebus.cc" />
     1.6      <ClCompile Include="src\object.cc" />
     1.7 +    <ClCompile Include="src\scene.cc" />
     1.8 +    <ClCompile Include="src\snode.cc" />
     1.9    </ItemGroup>
    1.10    <ItemGroup>
    1.11      <None Include="src\image.inl" />
     2.1 --- a/liberebus/liberebus.vcxproj.filters	Sun Apr 27 16:02:47 2014 +0300
     2.2 +++ b/liberebus/liberebus.vcxproj.filters	Mon Apr 28 05:58:22 2014 +0300
     2.3 @@ -68,6 +68,12 @@
     2.4      <ClCompile Include="src\brdf.cc">
     2.5        <Filter>Source Files</Filter>
     2.6      </ClCompile>
     2.7 +    <ClCompile Include="src\scene.cc">
     2.8 +      <Filter>Source Files</Filter>
     2.9 +    </ClCompile>
    2.10 +    <ClCompile Include="src\snode.cc">
    2.11 +      <Filter>Source Files</Filter>
    2.12 +    </ClCompile>
    2.13    </ItemGroup>
    2.14    <ItemGroup>
    2.15      <None Include="src\image.inl">
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/liberebus/src/scene.cc	Mon Apr 28 05:58:22 2014 +0300
     3.3 @@ -0,0 +1,51 @@
     3.4 +#include "scene.h"
     3.5 +
     3.6 +Scene::Scene()
     3.7 +{
     3.8 +	active_cam = 0;
     3.9 +}
    3.10 +
    3.11 +Scene::~Scene()
    3.12 +{
    3.13 +	for(auto obj : objects) {
    3.14 +		delete obj;
    3.15 +	}
    3.16 +	for(auto node : nodes) {
    3.17 +		delete node;
    3.18 +	}
    3.19 +}
    3.20 +
    3.21 +void Scene::add_object(Object *obj)
    3.22 +{
    3.23 +	objects.push_back(obj);
    3.24 +}
    3.25 +
    3.26 +int Scene::get_object_count() const
    3.27 +{
    3.28 +	return (int)objects.size();
    3.29 +}
    3.30 +
    3.31 +Object *Scene::get_object(int idx) const
    3.32 +{
    3.33 +	return objects[idx];
    3.34 +}
    3.35 +
    3.36 +void Scene::add_node(SceneNode *node)
    3.37 +{
    3.38 +	nodes.push_back(node);
    3.39 +}
    3.40 +
    3.41 +int Scene::get_node_count() const
    3.42 +{
    3.43 +	return (int)nodes.size();
    3.44 +}
    3.45 +
    3.46 +SceneNode *Scene::get_node(int idx) const
    3.47 +{
    3.48 +	return nodes[idx];
    3.49 +}
    3.50 +
    3.51 +bool Scene::intersect(const Ray &ray, RayHit *hit) const
    3.52 +{
    3.53 +
    3.54 +}
    3.55 \ No newline at end of file
     4.1 --- a/liberebus/src/scene.h	Sun Apr 27 16:02:47 2014 +0300
     4.2 +++ b/liberebus/src/scene.h	Mon Apr 28 05:58:22 2014 +0300
     4.3 @@ -17,7 +17,14 @@
     4.4  	~Scene();
     4.5  
     4.6  	void add_object(Object *obj);
     4.7 -	Object *get_object(int idx);
     4.8 +	int get_object_count() const;
     4.9 +	Object *get_object(int idx) const;
    4.10 +
    4.11 +	void add_node(SceneNode *node);
    4.12 +	int get_node_count() const;
    4.13 +	SceneNode *get_node(int idx) const;
    4.14 +
    4.15 +	bool intersect(const Ray &ray, RayHit *hit) const;
    4.16  };
    4.17  
    4.18  #endif	// SCENE_H_
    4.19 \ No newline at end of file
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/liberebus/src/snode.cc	Mon Apr 28 05:58:22 2014 +0300
     5.3 @@ -0,0 +1,107 @@
     5.4 +#include <assert.h>
     5.5 +#include <algorithm>
     5.6 +#include "snode.h"
     5.7 +
     5.8 +void SceneNode::add_child(SceneNode *node)
     5.9 +{
    5.10 +	if(node->parent) {
    5.11 +		if(node->parent == this) {
    5.12 +			return;
    5.13 +		}
    5.14 +		node->parent->remove_child(node);
    5.15 +	}
    5.16 +
    5.17 +	children.push_back(node);
    5.18 +	node->parent = this;
    5.19 +}
    5.20 +
    5.21 +bool SceneNode::remove_child(SceneNode *node)
    5.22 +{
    5.23 +	auto it = std::find(children.begin(), children.end(), node);
    5.24 +	if(it != children.end()) {
    5.25 +		assert(node->parent == this);
    5.26 +		node->parent = 0;
    5.27 +	}
    5.28 +}
    5.29 +
    5.30 +int SceneNode::get_num_children() const
    5.31 +{
    5.32 +	return (int)children.size();
    5.33 +}
    5.34 +
    5.35 +SceneNode *SceneNode::get_child(int idx) const
    5.36 +{
    5.37 +	return children[idx];
    5.38 +}
    5.39 +
    5.40 +void SceneNode::set_position(const Vector3 &pos)
    5.41 +{
    5.42 +	this->pos = pos;
    5.43 +}
    5.44 +
    5.45 +void SceneNode::set_rotation(const Quaternion &rot)
    5.46 +{
    5.47 +	this->rot = rot;
    5.48 +}
    5.49 +
    5.50 +void SceneNode::set_scaling(const Vector3 &scale)
    5.51 +{
    5.52 +	this->scale = scale;
    5.53 +}
    5.54 +
    5.55 +
    5.56 +const Vector3 &SceneNode::get_node_position() const
    5.57 +{
    5.58 +	return pos;
    5.59 +}
    5.60 +
    5.61 +const Quaternion &SceneNode::get_node_rotation() const
    5.62 +{
    5.63 +	return rot;
    5.64 +}
    5.65 +
    5.66 +const Vector3 &SceneNode::get_node_scaling() const
    5.67 +{
    5.68 +	return scale;
    5.69 +}
    5.70 +
    5.71 +
    5.72 +Vector3 SceneNode::get_position() const
    5.73 +{
    5.74 +	return Vector3{0, 0, 0}.transformed(xform);
    5.75 +}
    5.76 +
    5.77 +Quaternion SceneNode::get_rotation() const
    5.78 +{
    5.79 +	return rot;	// TODO
    5.80 +}
    5.81 +
    5.82 +Vector3 SceneNode::get_scaling() const
    5.83 +{
    5.84 +	return scale;	// TODO
    5.85 +}
    5.86 +
    5.87 +
    5.88 +void SceneNode::update_node(long msec)
    5.89 +{
    5.90 +	node_xform.reset_identity();
    5.91 +	node_xform.translate(pos);
    5.92 +	node_xform.rotate(rot);
    5.93 +	node_xform.scale(scale);
    5.94 +
    5.95 +	xform = parent ? parent->xform * node_xform : node_xform;
    5.96 +}
    5.97 +
    5.98 +void SceneNode::update(long msec)
    5.99 +{
   5.100 +	update_node(msec);
   5.101 +
   5.102 +	for(size_t i=0; i<children.size(); i++) {
   5.103 +		children[i]->update(msec);
   5.104 +	}
   5.105 +}
   5.106 +
   5.107 +
   5.108 +bool SceneNode::intersect(const Ray &ray, RayHit *hit) const
   5.109 +{
   5.110 +}
   5.111 \ No newline at end of file
     6.1 --- a/liberebus/src/snode.h	Sun Apr 27 16:02:47 2014 +0300
     6.2 +++ b/liberebus/src/snode.h	Mon Apr 28 05:58:22 2014 +0300
     6.3 @@ -16,8 +16,11 @@
     6.4  	SceneNode *parent;
     6.5  	std::vector<SceneNode*> children;
     6.6  
     6.7 +	Matrix4x4 node_xform, xform;
     6.8 +
     6.9  public:
    6.10  	void add_child(SceneNode *node);
    6.11 +	bool remove_child(SceneNode *node);
    6.12  
    6.13  	int get_num_children() const;
    6.14  	SceneNode *get_child(int idx) const;
    6.15 @@ -30,12 +33,14 @@
    6.16  	const Quaternion &get_node_rotation() const;
    6.17  	const Vector3 &get_node_scaling() const;
    6.18  
    6.19 -	const Vector3 &get_position() const;
    6.20 -	const Quaternion &get_rotation() const;
    6.21 -	const Vector3 &get_scaling() const;
    6.22 +	Vector3 get_position() const;
    6.23 +	Quaternion get_rotation() const;
    6.24 +	Vector3 get_scaling() const;
    6.25  
    6.26 -	void update_node(long msec = 0) const;
    6.27 -	void update(long msec = 0) const;
    6.28 +	void update_node(long msec = 0);
    6.29 +	void update(long msec = 0);
    6.30 +
    6.31 +	bool intersect(const Ray &ray, RayHit *hit) const;
    6.32  };
    6.33  
    6.34  #endif	// SNODE_H_
    6.35 \ No newline at end of file