mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-05 23:40:02 +01:00
Cleanup Scene and Primitives. Add comments.
This commit is contained in:
@@ -778,3 +778,4 @@ void ToggleButton( const char* label, bool& toggle )
|
||||
if( ImGui::Button( label ) ) toggle = !toggle;
|
||||
if( active ) ImGui::PopStyleColor( 3 );
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ void ImGuiVisitor::visit(Group &n)
|
||||
if (ImGuiToolkit::ButtonIcon(4, 15))
|
||||
n.rotation_.z = 0.f;
|
||||
ImGui::SameLine(0, 10);
|
||||
ImGui::SliderAngle("slider angle", &(n.rotation_.z), -180.f, 180.f) ;
|
||||
ImGui::SliderAngle("angle", &(n.rotation_.z), -180.f, 180.f) ;
|
||||
|
||||
if (ImGuiToolkit::ButtonIcon(3, 15)) {
|
||||
n.scale_.x = 1.f;
|
||||
@@ -114,6 +114,20 @@ void ImGuiVisitor::visit(Shader &n)
|
||||
|
||||
void ImGuiVisitor::visit(ImageShader &n)
|
||||
{
|
||||
ImGui::PushID(n.id());
|
||||
|
||||
if (ImGuiToolkit::ButtonIcon(2, 1)) {
|
||||
n.brightness = 0.f;
|
||||
n.contrast = 0.f;
|
||||
}
|
||||
ImGui::SameLine(0, 10);
|
||||
float bc[2] = { n.brightness, n.contrast};
|
||||
if ( ImGui::SliderFloat2("filter", bc, -1.0, 1.0) )
|
||||
{
|
||||
n.brightness = bc[0];
|
||||
n.contrast = bc[1];
|
||||
}
|
||||
ImGui::PopID();
|
||||
}
|
||||
|
||||
void ImGuiVisitor::visit(LineStrip &n)
|
||||
|
||||
5
Mesh.cpp
5
Mesh.cpp
@@ -373,8 +373,3 @@ void Mesh::accept(Visitor& v)
|
||||
Primitive::accept(v);
|
||||
v.visit(*this);
|
||||
}
|
||||
|
||||
//void Mesh::update( float dt )
|
||||
//{
|
||||
// scale_.x = scale_.y;
|
||||
//}
|
||||
|
||||
1
Mesh.h
1
Mesh.h
@@ -22,7 +22,6 @@ public:
|
||||
void init () override;
|
||||
void draw (glm::mat4 modelview, glm::mat4 projection) override;
|
||||
void accept (Visitor& v) override;
|
||||
// void update (float dt) override;
|
||||
|
||||
inline std::string getResource() const { return resource_; }
|
||||
inline std::string getTexture() const { return texturefilename_; }
|
||||
|
||||
@@ -98,9 +98,9 @@ void ImageSurface::accept(Visitor& v)
|
||||
v.visit(*this);
|
||||
}
|
||||
|
||||
MediaSurface::MediaSurface(const std::string& path) : ImageSurface()
|
||||
MediaSurface::MediaSurface(const std::string& uri) : ImageSurface()
|
||||
{
|
||||
resource_ = path;
|
||||
resource_ = uri;
|
||||
mediaplayer_ = new MediaPlayer;
|
||||
}
|
||||
|
||||
@@ -140,12 +140,12 @@ void MediaSurface::update( float dt )
|
||||
if ( mediaplayer_->isOpen() ) {
|
||||
mediaplayer_->update();
|
||||
|
||||
if (parent_ != nullptr) {
|
||||
parent_->transform_ = parent_->transform_ * glm::scale(glm::identity<glm::mat4>(), glm::vec3(mediaplayer_->aspectRatio(), 1.f, 1.f));
|
||||
scale_.x = 1.0;
|
||||
}
|
||||
else
|
||||
scale_.x = mediaplayer_->aspectRatio();
|
||||
// if (parent_ != nullptr) {
|
||||
// parent_->transform_ = parent_->transform_ * glm::scale(glm::identity<glm::mat4>(), glm::vec3(mediaplayer_->aspectRatio(), 1.f, 1.f));
|
||||
// scale_.x = 1.0;
|
||||
// }
|
||||
// else
|
||||
scale_.x = mediaplayer_->aspectRatio();
|
||||
}
|
||||
|
||||
Primitive::update( dt );
|
||||
|
||||
48
Primitives.h
48
Primitives.h
@@ -4,8 +4,14 @@
|
||||
#include <string>
|
||||
|
||||
#include "Scene.h"
|
||||
class MediaPlayer;
|
||||
|
||||
// Draw a Rectangle (triangle strip) with a texture
|
||||
/**
|
||||
* @brief The ImageSurface class is a Primitive to draw an image
|
||||
*
|
||||
* Image is read from the Ressouces (not an external file)
|
||||
* Height = 1.0, Width is set by the aspect ratio of the image
|
||||
*/
|
||||
class ImageSurface : public Primitive {
|
||||
|
||||
void deleteGLBuffers_() override {}
|
||||
@@ -26,15 +32,18 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
// Draw a Rectangle with a media as animated texture
|
||||
class MediaPlayer;
|
||||
|
||||
/**
|
||||
* @brief The MediaSurface class is an ImageSurface to draw a video
|
||||
*
|
||||
* URI is passed to a Media Player to handle the video playback
|
||||
* Height = 1.0, Width is set by the aspect ratio of the image
|
||||
*/
|
||||
class MediaSurface : public ImageSurface {
|
||||
|
||||
MediaPlayer *mediaplayer_;
|
||||
|
||||
public:
|
||||
MediaSurface(const std::string& path);
|
||||
MediaSurface(const std::string& uri);
|
||||
~MediaSurface();
|
||||
|
||||
void init () override;
|
||||
@@ -45,22 +54,10 @@ public:
|
||||
MediaPlayer *getMediaPlayer() { return mediaplayer_; }
|
||||
};
|
||||
|
||||
//// Draw a Frame Buffer
|
||||
//class FrameBufferSurface : public Primitive {
|
||||
|
||||
// void deleteGLBuffers_() {}
|
||||
|
||||
//public:
|
||||
// FrameBufferSurface();
|
||||
|
||||
// void init () override;
|
||||
// void draw(glm::mat4 modelview, glm::mat4 projection) override;
|
||||
// void accept(Visitor& v) override;
|
||||
|
||||
//};
|
||||
|
||||
|
||||
// Draw a Point
|
||||
/**
|
||||
* @brief The Points class is a Primitive to draw Points
|
||||
*/
|
||||
class Points : public Primitive {
|
||||
|
||||
uint pointsize_;
|
||||
@@ -80,7 +77,10 @@ public:
|
||||
inline uint getPointSize() const { return pointsize_; }
|
||||
};
|
||||
|
||||
// Draw a line strip
|
||||
|
||||
/**
|
||||
* @brief The LineStrip class is a Primitive to draw lines
|
||||
*/
|
||||
class LineStrip : public Primitive {
|
||||
|
||||
uint linewidth_;
|
||||
@@ -101,6 +101,9 @@ public:
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief The LineSquare class is a square LineStrip (width & height = 1.0)
|
||||
*/
|
||||
class LineSquare : public LineStrip {
|
||||
|
||||
void deleteGLBuffers_() override {}
|
||||
@@ -113,6 +116,9 @@ public:
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief The LineCircle class is a circular LineStrip (diameter = 1.0)
|
||||
*/
|
||||
class LineCircle : public LineStrip {
|
||||
|
||||
void deleteGLBuffers_() override {}
|
||||
|
||||
@@ -164,6 +164,7 @@ void Primitive::deleteGLBuffers_()
|
||||
glDeleteVertexArrays ( 1, &vao_);
|
||||
}
|
||||
|
||||
|
||||
// Group
|
||||
|
||||
Group::~Group()
|
||||
|
||||
74
Scene.h
74
Scene.h
@@ -16,8 +16,27 @@ glm::mat4 transform(glm::vec3 translation, glm::vec3 rotation, glm::vec3 scale);
|
||||
class Shader;
|
||||
class Visitor;
|
||||
|
||||
// Base virtual class for all Node types
|
||||
// Manages modelview transformations and culling
|
||||
|
||||
/**
|
||||
* @brief The Node class is the base virtual class for all Node types
|
||||
*
|
||||
* Every Node is given a unique id at instanciation
|
||||
*
|
||||
* Every Node has geometric operations for translation,
|
||||
* scale and rotation. The update() function computes the
|
||||
* transform_ matrix from these components.
|
||||
*
|
||||
* draw() shall be defined by the subclass.
|
||||
* The visible flag can be used to show/hide a Node.
|
||||
* To apply geometrical transformation, draw() can multiplying the
|
||||
* modelview by the transform_ matrix.
|
||||
*
|
||||
* init() shall be called on the first call of draw():
|
||||
* if ( !initialized() )
|
||||
* init();
|
||||
*
|
||||
* accept() allows visitors to parse the graph.
|
||||
*/
|
||||
class Node {
|
||||
|
||||
int id_;
|
||||
@@ -51,7 +70,22 @@ public:
|
||||
glm::vec3 scale_, rotation_, translation_;
|
||||
};
|
||||
|
||||
// Leaf Nodes are primitives that can be rendered
|
||||
|
||||
|
||||
/**
|
||||
* @brief The Primitive class is a leaf Node that can be rendered
|
||||
*
|
||||
* Primitive generates a STATIC vertex array object from
|
||||
* a list of points, colors and texture coordinates.
|
||||
* The vertex array is deleted in the Primitive destructor.
|
||||
*
|
||||
* Primitive class itself does not define any geometry: subclasses
|
||||
* should fill the points, colors and texture coordinates
|
||||
* in their constructor.
|
||||
*
|
||||
* Primitive can be given a shader that is used during draw.
|
||||
*
|
||||
*/
|
||||
class Primitive : public Node {
|
||||
|
||||
public:
|
||||
@@ -75,8 +109,9 @@ protected:
|
||||
virtual void deleteGLBuffers_();
|
||||
};
|
||||
|
||||
// Other Nodes establish hierarchy with a group of nodes
|
||||
|
||||
//
|
||||
// Other Nodes establish hierarchy with a set of nodes
|
||||
//
|
||||
struct z_comparator
|
||||
{
|
||||
inline bool operator () (const Node *a, const Node *b) const
|
||||
@@ -97,7 +132,19 @@ private:
|
||||
};
|
||||
typedef std::multiset<Node*, z_comparator> NodeSet;
|
||||
|
||||
|
||||
/**
|
||||
* @brief The Group class contains a list of pointers to Nodes.
|
||||
*
|
||||
* A Group defines the hierarchy in the scene graph.
|
||||
*
|
||||
* The list of Nodes* is a NodeSet, a depth-sorted set
|
||||
* accepting multiple nodes at the same depth (multiset)
|
||||
*
|
||||
* update() will update all children
|
||||
* draw() will draw all children
|
||||
*
|
||||
* When a group is deleted, the children are NOT deleted.
|
||||
*/
|
||||
class Group : public Node {
|
||||
|
||||
public:
|
||||
@@ -119,6 +166,13 @@ protected:
|
||||
NodeSet children_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The Switch class is a Group to selectively update & draw ONE selected child
|
||||
*
|
||||
* update() will update only the active child
|
||||
* draw() will draw only the active child
|
||||
*
|
||||
*/
|
||||
class Switch : public Group {
|
||||
|
||||
public:
|
||||
@@ -142,7 +196,13 @@ protected:
|
||||
NodeSet::iterator active_;
|
||||
};
|
||||
|
||||
// Animation Nodes
|
||||
/**
|
||||
* @brief The Animation class is a Group with an update() function
|
||||
*
|
||||
* The update() computes a transformation of the Group to apply a movement
|
||||
* which is applied to all children.
|
||||
*
|
||||
*/
|
||||
class Animation : public Group {
|
||||
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user