Skip to content

Commit

Permalink
Merge branch 'refs/heads/dev' into cpp20
Browse files Browse the repository at this point in the history
  • Loading branch information
markaren committed Jun 20, 2024
2 parents cd81914 + d8a50c8 commit 4dde90d
Show file tree
Hide file tree
Showing 58 changed files with 447 additions and 224 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ An example is provided [here](tests/threepp_vcpkg_test).
![Shadows](doc/screenshots/Shadows.PNG)
![FlyControls](doc/screenshots/fly.PNG)
![Crane](doc/screenshots/crane.png)
![Optimization](doc/screenshots/Optimization.PNG)
![Physics](doc/screenshots/instanced_physics.PNG)
![Water](doc/screenshots/OlympicOctopus.PNG)
![MotorController](doc/screenshots/motor_controller.PNG)
Binary file added doc/screenshots/Optimization.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion examples/animation/simple_skinning.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "threepp/helpers/SkeletonHelper.hpp"
#include "threepp/lights/LightShadow.hpp"
#include "threepp/loaders/AssimpLoader.hpp"
#include "threepp/materials/LineBasicMaterial.hpp"
#include "threepp/threepp.hpp"
Expand Down
6 changes: 5 additions & 1 deletion examples/controls/drag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "threepp/controls/DragControls.hpp"
#include "threepp/threepp.hpp"

#include <iostream>

using namespace threepp;

int main() {
Expand Down Expand Up @@ -86,7 +88,7 @@ int main() {
controls.addEventListener("hoveron", &hoverListener);
controls.addEventListener("hoveroff", &hoverListener);

KeyAdapter keyAdapter(KeyAdapter::Mode::KEY_PRESSED, [&](KeyEvent evt){
KeyAdapter keyAdapter(KeyAdapter::Mode::KEY_PRESSED, [&](KeyEvent evt) {
if (evt.key == Key::M) {
if (controls.mode == DragControls::Mode::Translate) {
controls.mode = DragControls::Mode::Rotate;
Expand All @@ -104,6 +106,8 @@ int main() {
renderer.setSize(size);
});

std::cout << "Press 'm' to switch between translate and rotate mode" << std::endl;

canvas.animate([&] {
renderer.render(scene, camera);
});
Expand Down
2 changes: 1 addition & 1 deletion examples/external/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

add_library(imgui OBJECT)
add_library(imgui STATIC)
add_library(imgui::imgui ALIAS imgui)
target_sources(imgui PRIVATE
"imgui/imgui.cpp"
Expand Down
2 changes: 1 addition & 1 deletion examples/extras/core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

add_example(NAME "fonts" LINK_IMGUI WEB WEB_EMBED
"../data/fonts@data/fonts"
"../data/fonts@data/fonts"
)
2 changes: 1 addition & 1 deletion examples/extras/physics/RigidbodyInfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace threepp {

struct MaterialInfo {
float friction;
float restitution ;
float restitution;

MaterialInfo(float friction, float restitution)
: friction(friction), restitution(restitution) {}
Expand Down
2 changes: 1 addition & 1 deletion examples/extras/physics/physx_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ int main() {
renderer.invokeLater([&, obj] {
scene.remove(*obj);
},
2);// remove after 2 seconds
2);// remove after 2 seconds
} else if (evt.key == Key::D) {
engine.debugVisualisation = !engine.debugVisualisation;
}
Expand Down
1 change: 0 additions & 1 deletion examples/geometries/geometries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ namespace {

private:
float scale;

};

auto createBox(const std::shared_ptr<Material>& m1, const std::shared_ptr<LineBasicMaterial>& m2) {
Expand Down
6 changes: 3 additions & 3 deletions examples/libs/geo/MapView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ MapProvider* MapView::getProvider() const {

void MapView::reload() {
traverse([&](Object3D& object) {
if (auto node = object.as<MapNode>()) {
node->initialize();
}
if (auto node = object.as<MapNode>()) {
node->initialize();
}
});
}
2 changes: 1 addition & 1 deletion examples/libs/geo/nodes/MapNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ bool MapNode::simplify() {
this->layers.enable(0);
this->nodesLoaded = 0;

return true; //signals that node needs clearing. Can't do it while traversing
return true;//signals that node needs clearing. Can't do it while traversing
}

void MapNode::loadData() {
Expand Down
1 change: 0 additions & 1 deletion examples/libs/optimization/Optimizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
class Optimizer {

public:

[[nodiscard]] virtual size_t size() const = 0;

[[nodiscard]] virtual const Candidate& getCandiateAt(size_t index) const = 0;
Expand Down
6 changes: 3 additions & 3 deletions examples/libs/optimization/Problem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#define THREEPP_PROBLEM_HPP

#include <cassert>
#include <utility>
#include <vector>
#include <cmath>
#include <random>
#include <utility>
#include <vector>

class Constraint {

Expand Down Expand Up @@ -139,7 +139,7 @@ class Problem {
value = dis(gen);
}

return {candidate, eval(candidate)};
return {candidate, eval(candidate)};
}

[[nodiscard]] virtual std::vector<std::vector<float>> solutions() const = 0;
Expand Down
12 changes: 6 additions & 6 deletions examples/libs/pathfinding/Path.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

#include "Coordinate.hpp"

#include <algorithm>
#include <ostream>
#include <stdexcept>
#include <string>
#include <vector>
#include <algorithm>

/**
* A path determined by some path finding algorithm. A series of steps from
Expand All @@ -36,7 +36,7 @@ class Path {
*
* @return The step information, the position on the map.
*/
const Coordinate &operator[](size_t index) const {
const Coordinate& operator[](size_t index) const {

if (index >= steps_.size()) {
throw std::runtime_error("Index out of bounds: " + std::to_string(index));
Expand All @@ -49,17 +49,17 @@ class Path {
*
* @param c The coordinate of the new step
*/
void prependStep(const Coordinate &c) {
void prependStep(const Coordinate& c) {

steps_.insert(steps_.begin(), c);
}

[[nodiscard]] const Coordinate &start() const {
[[nodiscard]] const Coordinate& start() const {

return steps_.front();
}

[[nodiscard]] const Coordinate &target() const {
[[nodiscard]] const Coordinate& target() const {

return steps_.back();
}
Expand All @@ -70,7 +70,7 @@ class Path {
*
* @return True if contains the coordinate, false otherwise
*/
[[nodiscard]] bool contains(const Coordinate &c) {
[[nodiscard]] bool contains(const Coordinate& c) {

return std::find(steps_.begin(), steps_.end(), c) != std::end(steps_);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/libs/pathfinding/algorithm/AStar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ class AStar: public Pathfinder {
*/
float getHeuristicCost(const Coordinate& s, const Coordinate& t) {

if (!heuristic) return 0; // Dijkstra's
if (!heuristic) return 0;// Dijkstra's

return heuristic->getCost(*map, s, t);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/lights/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

add_example(NAME "hemi_light" WEB)
add_example(NAME "point_light" WEB )
add_example(NAME "point_light" WEB)
add_example(NAME "spot_light" WEB)
add_example(NAME "directional" WEB)
1 change: 0 additions & 1 deletion examples/misc/morphtargets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ int main() {

Raycaster raycaster;
canvas.animate([&] {

box.setFromObject(*mesh);

raycaster.setFromCamera(mouse, *camera);
Expand Down
2 changes: 1 addition & 1 deletion examples/misc/morphtargets_sphere.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ int main() {

if (influence <= 0 || influence >= 1) {
sign *= -1;
influence = std::clamp(influence, 0.01f, 0.99f); // avoid "locking"
influence = std::clamp(influence, 0.01f, 0.99f);// avoid "locking"
}

renderer.render(scene, camera);
Expand Down
2 changes: 1 addition & 1 deletion examples/objects/bones.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ namespace {
Sizing sizing{segmentHeight, segmentCount, height, halfHeight};

auto geometry = createGeometry(sizing);
geometry->applyMatrix4(Matrix4().makeTranslation(0,halfHeight,0));
geometry->applyMatrix4(Matrix4().makeTranslation(0, halfHeight, 0));
auto bones = createBones(sizing);

auto mesh = createMesh(geometry, bones);
Expand Down
8 changes: 4 additions & 4 deletions examples/projects/Crane3R/Crane3R.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ namespace {

auto cyl1 = Mesh::create(geometry, material);
auto cyl2 = Mesh::create(geometry, material);
cyl1->position.x = sep/2;
cyl2->position.x = -sep/2;
cyl1->position.x = sep / 2;
cyl2->position.x = -sep / 2;
group->add(cyl1);
group->add(cyl2);

Expand All @@ -50,8 +50,8 @@ namespace {

auto cyl1 = Mesh::create(geometry, material);
auto cyl2 = Mesh::create(geometry, material);
cyl1->position.x = sep/2;
cyl2->position.x = -sep/2;
cyl1->position.x = sep / 2;
cyl2->position.x = -sep / 2;
group->add(cyl1);
group->add(cyl2);

Expand Down
2 changes: 0 additions & 2 deletions examples/projects/InvertedPendulum/InvertedPendulum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
class InvertedPendulum {

public:

// Function to simulate the system for a certain duration
void simulate(double duration, double externalForce, Regulator* regulator = nullptr) {
int steps = static_cast<int>(duration / internalTimeStep);
Expand All @@ -34,7 +33,6 @@ class InvertedPendulum {
}

private:

double cartPosition{0}; // Position of the cart
double pendulumAngle{threepp::math::degToRad(5)};// Angle of the pendulum
double cartVelocity{0}; // Velocity of the cart
Expand Down
2 changes: 1 addition & 1 deletion examples/projects/MapView/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

if (TARGET geothreepp)

add_example(NAME "MapView" SOURCES "main.cpp")
if (TARGET "MapView")
target_link_libraries("MapView" PRIVATE geothreepp)
Expand Down
2 changes: 1 addition & 1 deletion examples/projects/MotorControl/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ int main() {
ImGui::Begin("Motor Controller");

ImGui::Text("Target position");
if(ImGui::SliderFloat("deg", &targetPosition, 0, 180)) {
if (ImGui::SliderFloat("deg", &targetPosition, 0, 180)) {
targetText->setText("Target position: " + std::to_string(targetPosition), opts);
}
ImGui::Text("PID gains");
Expand Down
4 changes: 2 additions & 2 deletions examples/projects/Optimization/optimization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ int main() {

Lut::addColorMap("rainbow", {{0.f, 0x0000ff}, {0.001f, 0x00ffff}, {0.02f, 0xffff00}, {0.2f, 0xff0000}, {1.f, Color::darkred}});

Canvas canvas("Lut", {{"aa", 6}});
Canvas canvas("Optimization", {{"aa", 6}});
GLRenderer renderer(canvas.size());

Scene scene;
Expand Down Expand Up @@ -158,7 +158,7 @@ int main() {
changeFunction(functions.begin()->first);


auto changeAlgorithm = [&](const std::string& name){
auto changeAlgorithm = [&](const std::string& name) {
selectedAlgorithm = name;

auto& algorithm = algorithms[name];
Expand Down
2 changes: 1 addition & 1 deletion examples/projects/Pathfinding/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ int main() {
};

Raycaster raycaster;
raycaster.layers.set(1); // ignore grid
raycaster.layers.set(1);// ignore grid
Vector2 mouse{-Infinity<float>, -Infinity<float>};
MouseUpListener mouseListener([&](int button, Vector2 pos) {
if (start && target) return;
Expand Down
66 changes: 66 additions & 0 deletions examples/projects/Youbot/KeyController.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@

#ifndef THREEPP_KEYCONTROLLER_HPP
#define THREEPP_KEYCONTROLLER_HPP

#include "threepp/input/KeyListener.hpp"

#include "Youbot.hpp"

class KeyController: public threepp::KeyListener {

public:
KeyController(Youbot& youbot)
: youbot_(&youbot) {}

void onKeyPressed(KeyEvent evt) override {
if (evt.key == Key::W) {
keyState_.up = true;
} else if (evt.key == Key::S) {
keyState_.down = true;
} else if (evt.key == Key::D) {
keyState_.right = true;
} else if (evt.key == Key::A) {
keyState_.left = true;
}
}

void onKeyReleased(KeyEvent evt) override {
if (evt.key == Key::W) {
keyState_.up = false;
} else if (evt.key == Key::S) {
keyState_.down = false;
} else if (evt.key == Key::D) {
keyState_.right = false;
} else if (evt.key == Key::A) {
keyState_.left = false;
}
}

void update(float dt) {

if (keyState_.up) {
youbot_->driveForwards(dt);
}
if (keyState_.down) {
youbot_->driveBackwards(dt);
}
if (keyState_.right) {
youbot_->driveRight(dt);
}
if (keyState_.left) {
youbot_->driveLeft(dt);
}
}

private:
Youbot* youbot_;

struct KeyState {
bool left = false;
bool right = false;
bool up = false;
bool down = false;
} keyState_;
};

#endif//THREEPP_KEYCONTROLLER_HPP
Loading

0 comments on commit 4dde90d

Please sign in to comment.