Skip to content

Instantly share code, notes, and snippets.

@Makman2
Last active June 4, 2016 06:59
Show Gist options
  • Save Makman2/53c1ef0ee9ea69d887c6fa45b8c7dcb7 to your computer and use it in GitHub Desktop.
Save Makman2/53c1ef0ee9ea69d887c6fa45b8c7dcb7 to your computer and use it in GitHub Desktop.
An animated cube in CE3D2!!!

Compile with

g++ -lCE3D2 --std=c++11 anim.cpp -o anim

Install CE3D2 before! :D

#include <chrono>
#include <thread>
#include <iostream>
#include <memory>
#include <CE3D2/models/LineModel.h>
#include <CE3D2/render/TextRenderer.h>
#include <CE3D2/render/TextSurface.h>
#include <CE3D2/transformation/OrthogonalProjection.h>
#include <CE3D2/transformation/Rotation.h>
#include <CE3D2/transformation/Scale.h>
#include <CE3D2/transformation/Translation.h>
#include <CE3D2/Vector.h>
using namespace CE3D2;
int main()
{
auto model = std::make_shared<Models::LineModel>(Models::LineModel::cube());
model->transform(Transformation::Scale(create_vector(10.0f, 10.0f, 10.0f)));
Transformation::OrthogonalProjection ortho_projection;
std::vector<Vector> projection_vecs;
projection_vecs.push_back(create_vector(0.7f, 0.3f, 0.0f));
projection_vecs.push_back(create_vector(0.0f, 0.3f, 0.7f));
ortho_projection.set_projection_vectors(projection_vecs);
Transformation::Rotation rotation(create_vector(1.0f, 0.0f, 0.0f),
create_vector(0.0f, 1.0f, 0.0f));
auto translation = Transformation::Translation(create_vector(10.0f, 10.0f));
Render::TextRenderer renderer;
renderer.set_target(std::make_shared<Render::TextSurface>(50, 30));
auto screenscale = Transformation::Scale(create_vector(2.0f, 1.0f));
for (unsigned int i = 0; i < 200; i++)
{
renderer.line_models().clear();
auto modelcopy = std::make_shared<Models::LineModel>(*model);
renderer.line_models().push_back(modelcopy);
renderer.get_target()->clear();
rotation.set_angle(rotation.get_angle() + 0.04f);
modelcopy->transform(rotation);
modelcopy->transform(ortho_projection);
modelcopy->transform(translation);
modelcopy->transform(screenscale);
renderer.render();
std::cout << *renderer.get_target();
std::this_thread::sleep_for(std::chrono::milliseconds(40)); // 25 FPS
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment