Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# see https://clang.llvm.org/docs/ClangFormatStyleOptions.html
---
BasedOnStyle: LLVM
Language: Cpp
Standard: Cpp11

ColumnLimit: 135

AccessModifierOffset: -4
IndentWidth: 4
UseTab: Never

BreakBeforeBraces: Linux
AlignEscapedNewlines: Left
AllowShortFunctionsOnASingleLine: Empty
AllowShortLambdasOnASingleLine: Empty
AlwaysBreakTemplateDeclarations: true
BreakConstructorInitializers: AfterColon
ConstructorInitializerAllOnOneLineOrOnePerLine: true
IndentPPDirectives: AfterHash
PointerAlignment: Left
45 changes: 45 additions & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Build

on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
compiler: [gcc, clang]
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y qt5-qmake qtbase5-dev build-essential clang clang-format

- name: Set compiler
run: |
if [ "${{ matrix.compiler }}" = "clang" ]; then
export CC=clang
export CXX=clang++
else
export CC=gcc
export CXX=g++
fi
echo "CC=$CC" >> $GITHUB_ENV
echo "CXX=$CXX" >> $GITHUB_ENV

- name: Build
run: |
cmake -S . -B build -DFSTL_CHECK_FORMAT=ON
cmake --build build --target fstl --config Release -- -j$(nproc)

- name: Check format
run: |
# Print the version for troubleshooting purposes
clang-format --version
cmake --build build --target check-format
42 changes: 39 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,51 @@
# Original Project Author: Matt Keeter Copyright 2014-2024
# Author: Paul Tsouchlos Copyright 2017-2024

cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.10)

project(fstl)

# Setting -std=c++11
# Setting -std=c++14
set(CMAKE_CXX_STANDARD 14)
# Setting standard to required, as requisted by DeveloperPaul123 on github
set(CXX_STANDARD_REQUIRED ON)

option(FSTL_CHECK_FORMAT "Check source code formatting with clang-format" OFF)
if(FSTL_CHECK_FORMAT)
find_program(CLANG_FORMAT_EXE NAMES clang-format-10 clang-format-9 clang-format-8 clang-format)
if(NOT CLANG_FORMAT_EXE)
message(FATAL_ERROR "Could not find clang-format executable!")
endif()

file(GLOB_RECURSE ALL_SOURCE_FILES CONFIGURE_DEPENDS
src/*.h
src/*.cpp
qt/*.h
qt/*.cpp
gl/*.h
gl/*.cpp
exe/*.h
exe/*.cpp
)

add_custom_target(check-format
COMMAND ${CLANG_FORMAT_EXE}
--Werror
--style=file
--dry-run
${ALL_SOURCE_FILES}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Checking source code formatting"
VERBATIM)
add_custom_target(fix-format
COMMAND ${CLANG_FORMAT_EXE}
--style=file
-i
${ALL_SOURCE_FILES}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Fixing source code formatting"
VERBATIM)
endif()

# Set the version number
set (FSTL_VERSION_MAJOR "0")
set (FSTL_VERSION_MINOR "11")
Expand Down
16 changes: 5 additions & 11 deletions src/app.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#include <QDebug>
#include <QFileOpenEvent>
#include <QDir>
#include <QFileOpenEvent>

#include "app.h"
#include "window.h"

App::App(int& argc, char *argv[]) :
QApplication(argc, argv), window(new Window())
App::App(int& argc, char* argv[]) : QApplication(argc, argv), window(new Window())
{
if (argc > 1) {
const auto args = QCoreApplication::arguments();
Expand All @@ -15,9 +14,7 @@ App::App(int& argc, char *argv[]) :
filename.replace(0, 1, QDir::homePath());
}
window->load_stl(filename);
}
else
{
} else {
window->load_stl(":gl/sphere.stl");
}
window->show();
Expand All @@ -30,13 +27,10 @@ App::~App()

bool App::event(QEvent* e)
{
if (e->type() == QEvent::FileOpen)
{
if (e->type() == QEvent::FileOpen) {
window->load_stl(static_cast<QFileOpenEvent*>(e)->file());
return true;
}
else
{
} else {
return QApplication::event(e);
}
}
7 changes: 4 additions & 3 deletions src/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ class App : public QApplication
{
Q_OBJECT
public:
explicit App(int& argc, char *argv[]);
~App();
explicit App(int& argc, char* argv[]);
~App();

protected:
bool event(QEvent* e) override;

private:
Window* const window;

};

#endif // APP_H
143 changes: 53 additions & 90 deletions src/axis.cpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,8 @@
#include "axis.h"

const float xLet[] = {
-0.1, -0.2, 0,
0.1, 0.2, 0,
0.1, -0.2, 0,
-0.1, 0.2, 0
};
const float yLet[] = {
0, -0.2, 0,
0, 0, 0,
0, 0, 0,
0.1, 0.2, 0,
0, 0, 0,
-0.1, 0.2, 0
};
const float zLet[] = {
-0.1, -0.2, 0,
0.1, -0.2, 0,
0.1, -0.2, 0,
-0.1, 0.2, 0,
-0.1, 0.2, 0,
0.1, 0.2, 0
};
const float xLet[] = {-0.1, -0.2, 0, 0.1, 0.2, 0, 0.1, -0.2, 0, -0.1, 0.2, 0};
const float yLet[] = {0, -0.2, 0, 0, 0, 0, 0, 0, 0, 0.1, 0.2, 0, 0, 0, 0, -0.1, 0.2, 0};
const float zLet[] = {-0.1, -0.2, 0, 0.1, -0.2, 0, 0.1, -0.2, 0, -0.1, 0.2, 0, -0.1, 0.2, 0, 0.1, 0.2, 0};
const int axisSegCount[] = {2, 3, 3};
const float* axisLabels[] = {xLet, yLet, zLet};

Expand All @@ -32,131 +13,113 @@ Axis::Axis()
shader.addShaderFromSourceFile(QOpenGLShader::Vertex, ":/gl/colored_lines.vert");
shader.addShaderFromSourceFile(QOpenGLShader::Fragment, ":/gl/colored_lines.frag");
shader.link();
const int ptSize = 6*sizeof(float);
for(int lIdx = 0; lIdx < 3; lIdx++)
{
const int ptSize = 6 * sizeof(float);
for (int lIdx = 0; lIdx < 3; lIdx++) {
const float* l = axisLabels[lIdx];
const int ptCount = axisSegCount[lIdx]*2;
const int ptCount = axisSegCount[lIdx] * 2;
float c[3] = {0.0};
c[lIdx] = 1.0;//set color
c[lIdx] = 1.0; // set color
QOpenGLBuffer b = flowerLabelVertices[lIdx];
b.create();
b.bind();
b.allocate(ptCount*ptSize);
for(int pIdx = 0; pIdx < ptCount; pIdx++)
{
b.write(pIdx*ptSize, &(l[pIdx*3]), ptSize/2);//write coords
b.write(pIdx*ptSize + ptSize/2, c, ptSize/2);//write color
b.allocate(ptCount * ptSize);
for (int pIdx = 0; pIdx < ptCount; pIdx++) {
b.write(pIdx * ptSize, &(l[pIdx * 3]), ptSize / 2); // write coords
b.write(pIdx * ptSize + ptSize / 2, c, ptSize / 2); // write color
}
b.release();
}
//Axis buffer: 6 floats per vertex, 2 vert per line, 3 lines
float aBuf[6*2*3] = {0.0};
for(int aIdx = 0; aIdx < 3; aIdx++)
{
aBuf[(2*aIdx)*6+3+aIdx] = 1.0;//Set color (last 3 floats)
aBuf[(2*aIdx+1)*6+3+aIdx] = 1.0;//Set color (last 3 floats)
aBuf[(2*aIdx+1)*6+aIdx] = 1.0;//Extend line in axis
// Axis buffer: 6 floats per vertex, 2 vert per line, 3 lines
float aBuf[6 * 2 * 3] = {0.0};
for (int aIdx = 0; aIdx < 3; aIdx++) {
aBuf[(2 * aIdx) * 6 + 3 + aIdx] = 1.0; // Set color (last 3 floats)
aBuf[(2 * aIdx + 1) * 6 + 3 + aIdx] = 1.0; // Set color (last 3 floats)
aBuf[(2 * aIdx + 1) * 6 + aIdx] = 1.0; // Extend line in axis
}
//The lines which form the 'axis-flower' in the corner
// The lines which form the 'axis-flower' in the corner
flowerAxisVertices.create();
flowerAxisVertices.bind();
flowerAxisVertices.allocate(aBuf, sizeof(aBuf));
flowerAxisVertices.release();
//The lines which form the model-space axes
// The lines which form the model-space axes
vertices.create();
vertices.bind();
vertices.allocate(aBuf, sizeof(aBuf));
vertices.release();
}
void Axis::setScale(QVector3D min, QVector3D max)
{
//Max function. not worth importing <algorithm> just for max
auto Max = [](float a, float b)
{
// Max function. not worth importing <algorithm> just for max
auto Max = [](float a, float b) {
return (a > b) ? a : b;
};
//This is how much the axes extend beyond the model
//We want it to be dependent on the model's size, but uniform on all axes.
const float axismargin = 0.25*Max(Max(max[0]-min[0], max[1]-min[1]), max[2]-min[2]);
// This is how much the axes extend beyond the model
// We want it to be dependent on the model's size, but uniform on all axes.
const float axismargin = 0.25 * Max(Max(max[0] - min[0], max[1] - min[1]), max[2] - min[2]);
vertices.bind();
//Manually rewrite coordinates to control axis draw lengths
// Manually rewrite coordinates to control axis draw lengths
float s = sizeof(float);
//aIdx*12+aIdx gets us to the set of 2 points of the axis line, plus the offset for that dimension
// aIdx*12+aIdx gets us to the set of 2 points of the axis line, plus the offset for that dimension
//+6 gets us to the other end of the line in that dimension
for(int aIdx = 0; aIdx < 3; aIdx++)
{
float t = min[aIdx]-axismargin;
vertices.write(s*(aIdx*12+aIdx), &t, s);
t = max[aIdx]+axismargin;
vertices.write(s*(aIdx*12+aIdx+6), &t, s);
for (int aIdx = 0; aIdx < 3; aIdx++) {
float t = min[aIdx] - axismargin;
vertices.write(s * (aIdx * 12 + aIdx), &t, s);
t = max[aIdx] + axismargin;
vertices.write(s * (aIdx * 12 + aIdx + 6), &t, s);
}
vertices.release();
}
void Axis::draw(QMatrix4x4 transMat, QMatrix4x4 viewMat,
QMatrix4x4 orientMat, QMatrix4x4 aspectMat, float aspectRatio)
void Axis::draw(QMatrix4x4 transMat, QMatrix4x4 viewMat, QMatrix4x4 orientMat, QMatrix4x4 aspectMat, float aspectRatio)
{
shader.bind();
vertices.bind();
// Load the transform and view matrices into the shader
auto loadMatrixUniforms = [&](QMatrix4x4 transform, QMatrix4x4 view)
{
glUniformMatrix4fv(
shader.uniformLocation("transform_matrix"),
1, GL_FALSE, transform.data());
glUniformMatrix4fv(
shader.uniformLocation("view_matrix"),
1, GL_FALSE, view.data());
auto loadMatrixUniforms = [&](QMatrix4x4 transform, QMatrix4x4 view) {
glUniformMatrix4fv(shader.uniformLocation("transform_matrix"), 1, GL_FALSE, transform.data());
glUniformMatrix4fv(shader.uniformLocation("view_matrix"), 1, GL_FALSE, view.data());
};
const GLuint vp = shader.attributeLocation("vertex_position");
const GLuint vc = shader.attributeLocation("vertex_color");
glEnableVertexAttribArray(vp);
glEnableVertexAttribArray(vc);
auto loadAttribPtr = [&]()
{
glVertexAttribPointer(vp, 3, GL_FLOAT, false,
6 * sizeof(GLfloat), 0);
glVertexAttribPointer(vc, 3, GL_FLOAT, false,
6 * sizeof(GLfloat),
(GLvoid*)(3 * sizeof(GLfloat)));
auto loadAttribPtr = [&]() {
glVertexAttribPointer(vp, 3, GL_FLOAT, false, 6 * sizeof(GLfloat), 0);
glVertexAttribPointer(vc, 3, GL_FLOAT, false, 6 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));
};
loadMatrixUniforms(transMat, viewMat);
loadAttribPtr();

glDrawArrays(GL_LINES, 0, 3*6);
glDrawArrays(GL_LINES, 0, 3 * 6);

vertices.release();
//Next, we draw the hud axis-flower
// Next, we draw the hud axis-flower
flowerAxisVertices.bind();
glClear(GL_DEPTH_BUFFER_BIT);//Ensure hud draws over everything
glClear(GL_DEPTH_BUFFER_BIT); // Ensure hud draws over everything
const float hudSize = 0.2;
QMatrix4x4 hudMat;
//Move the hud to the bottom left corner with margin
if (aspectRatio > 1.0)
{
hudMat.translate(aspectRatio-2*hudSize, -1.0+2*hudSize, 0);
// Move the hud to the bottom left corner with margin
if (aspectRatio > 1.0) {
hudMat.translate(aspectRatio - 2 * hudSize, -1.0 + 2 * hudSize, 0);
} else {
hudMat.translate(1.0 - 2 * hudSize, -1.0 / aspectRatio + 2 * hudSize, 0);
}
else
{
hudMat.translate(1.0-2*hudSize, -1.0/aspectRatio+2*hudSize, 0);
}
//Scale the hud to be small
// Scale the hud to be small
hudMat.scale(hudSize, hudSize, 1);
loadMatrixUniforms(orientMat, aspectMat*hudMat);
loadMatrixUniforms(orientMat, aspectMat * hudMat);
loadAttribPtr();
glDrawArrays(GL_LINES, 0, 3*6);
glDrawArrays(GL_LINES, 0, 3 * 6);
flowerAxisVertices.release();
for(int aIdx = 0; aIdx < 3; aIdx++){
for (int aIdx = 0; aIdx < 3; aIdx++) {
QVector3D transVec = QVector3D();
transVec[aIdx] = 1.25;//This is how far we want the letters to be extended out
transVec[aIdx] = 1.25; // This is how far we want the letters to be extended out
QOpenGLBuffer b = flowerLabelVertices[aIdx];
//The only transform we want is to translate the letters to the ends of the axis lines
// The only transform we want is to translate the letters to the ends of the axis lines
QMatrix4x4 labelTransMat = QMatrix4x4();
labelTransMat.translate(orientMat * transVec);
b.bind();
loadMatrixUniforms(labelTransMat, aspectMat * hudMat);
loadAttribPtr();
glDrawArrays(GL_LINES, 0, axisSegCount[aIdx]*2*6);
glDrawArrays(GL_LINES, 0, axisSegCount[aIdx] * 2 * 6);
b.release();
}
shader.release();
Expand Down
Loading