Skip to content

Commit

Permalink
update GLM definitions and code accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitre committed Feb 15, 2025
1 parent 039a6e5 commit c2da2ca
Show file tree
Hide file tree
Showing 42 changed files with 815 additions and 867 deletions.
7 changes: 3 additions & 4 deletions addons/ofxAssimpModelLoader/src/ofxAssimpMeshHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
#include "ofxAssimpTexture.h"
#include "ofVbo.h"
#include "ofMesh.h"
#define GLM_FORCE_CTOR_INIT
#define GLM_ENABLE_EXPERIMENTAL
#include "glm/mat4x4.hpp"

#include <glm/mat4x4.hpp>

struct aiMesh;

Expand Down Expand Up @@ -50,7 +49,7 @@ class ofxAssimpMeshHelper {
ofMesh cachedMesh;
bool validCache = false;

glm::mat4 matrix;
glm::mat4 matrix { 1.0f };

protected:
//for normal, specular, etc - we include the diffuse too with a null deleter
Expand Down
3 changes: 2 additions & 1 deletion addons/ofxAssimpModelLoader/src/ofxAssimpModelLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "ofMesh.h"
#include "ofMath.h"
#include "ofConstants.h"

#include <assimp/Importer.hpp>
#include <unordered_map>
#include <map>
Expand Down Expand Up @@ -187,7 +188,7 @@ class ofxAssimpModelLoader{
std::vector<glm::vec3> rotAxis;
glm::vec3 scale {1.0,1.0,1.0};
glm::vec3 pos {0.0,0.0,0.0};
glm::mat4 modelMatrix; // { glm::mat4() }
glm::mat4 modelMatrix { 1.0f }; // { glm::mat4() }

std::vector<ofLight> lights;
std::map<
Expand Down
5 changes: 1 addition & 4 deletions libs/openFrameworks/3d/of3dUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#include "ofAppRunner.h"
#include "ofGraphicsBaseTypes.h"

#define GLM_FORCE_CTOR_INIT
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/vec3.hpp>

//--------------------------------------------------------------
Expand All @@ -29,6 +27,5 @@ void ofDrawArrow(const glm::vec3& start, const glm::vec3& end, float headSize) {
//--------------------------------------------------------------
void ofDrawRotationAxes(float radius, float stripWidth, int circleRes){
ofGetCurrentRenderer()->drawRotationAxes(radius,stripWidth,circleRes);

}

}
2 changes: 0 additions & 2 deletions libs/openFrameworks/3d/ofCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#include "ofGraphics.h"
#include "of3dGraphics.h"

#define GLM_FORCE_CTOR_INIT
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/transform.hpp>
#include <glm/gtc/quaternion.hpp>

Expand Down
1 change: 0 additions & 1 deletion libs/openFrameworks/3d/ofEasyCam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include "ofUtils.h"
#include "ofGraphicsBaseTypes.h"

#define GLM_FORCE_CTOR_INIT
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/vector_angle.hpp>
#include <limits>
Expand Down
2 changes: 0 additions & 2 deletions libs/openFrameworks/3d/ofEasyCam.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ class ofEventListeners;
class ofEventArgs;
class ofRectangle;

#define GLM_FORCE_CTOR_INIT
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtc/quaternion.hpp>

/// \brief A super simple camera for interacting with objects in 3D space.
Expand Down
58 changes: 29 additions & 29 deletions libs/openFrameworks/3d/ofMesh.inl
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ template<class V, class N, class C, class T>
V ofMesh_<V,N,C,T>::getCentroid() const {
if(vertices.size() == 0) {
ofLogWarning("ofMesh") << "getCentroid(): mesh has no vertices, returning glm::vec3(0, 0, 0)";
return glm::vec3(0, 0, 0);
return glm::vec3(0.0f, 0.0f, 0.0f);
}

V sum;
Expand Down Expand Up @@ -1108,7 +1108,7 @@ void ofMesh_<V,N,C,T>::load(const of::filesystem::path& path){
ofIndexType currentFace = 0;

bool colorTypeIsUChar = false; /// flag to distinguish between uchar (more common) and float (less common) color format in ply file

enum State{
Header,
VertexDef,
Expand All @@ -1118,16 +1118,16 @@ void ofMesh_<V,N,C,T>::load(const of::filesystem::path& path){
Faces
};


enum Attribute {
Position,
Color,
Normal,
TexCoord,
};

std::vector<Attribute> meshDefinition;

data.clear();
State state = Header;

Expand Down Expand Up @@ -1238,7 +1238,7 @@ void ofMesh_<V,N,C,T>::load(const of::filesystem::path& path){
goto clean;
}
std::stringstream sline(lineStr);

// read in a line of vertex elements
// and split it into attributes,
// based attribute order specified in file header
Expand Down Expand Up @@ -1274,7 +1274,7 @@ void ofMesh_<V,N,C,T>::load(const of::filesystem::path& path){
error = "attribute data does not match definition in header";
goto clean;
}

currentVertex++;
if(currentVertex==data.getNumVertices()){
if(orderVertices<orderIndices){
Expand Down Expand Up @@ -1785,7 +1785,7 @@ void ofMesh_<V,N,C,T>::smoothNormals( float angle ) {
std::vector<ofMeshFace_<V,N,C,T>> triangles = getUniqueFaces();
std::vector<V> verts;
verts.reserve( triangles.size() * 3 );

for(ofIndexType i = 0; i < triangles.size(); i++) {
for(ofIndexType j = 0; j < 3; j++) {
verts.emplace_back( triangles[i].getVertex(j) );
Expand Down Expand Up @@ -1822,7 +1822,7 @@ void ofMesh_<V,N,C,T>::smoothNormals( float angle ) {
"y"+ofToString(verts[i].y==-0?0:verts[i].y) +
"z"+ofToString(verts[i].z==-0?0:verts[i].z)
};

if(vertHash.find(vstring) == vertHash.end()) {
for(ofIndexType j = 0; j < triangles.size(); j++) {
for(ofIndexType k = 0; k < 3; k++) {
Expand Down Expand Up @@ -1856,7 +1856,7 @@ void ofMesh_<V,N,C,T>::smoothNormals( float angle ) {
"y"+ofToString(vert.y==-0?0:vert.y) +
"z"+ofToString(vert.z==-0?0:vert.z)
};

numNormals=0;
normal = {0.f,0.f,0.f};
if(vertHash.find(vstring) != vertHash.end()) {
Expand Down Expand Up @@ -1886,40 +1886,40 @@ void ofMesh_<V,N,C,T>::smoothNormals( float angle ) {
template<class V, class N, class C, class T>
void ofMesh_<V,N,C,T>::flatNormals() {
if( getMode() == OF_PRIMITIVE_TRIANGLES) {

// get copy original mesh data
auto indices = getIndices();
auto verts = getVertices();
auto texCoords = getTexCoords();
auto colors = getColors();

// remove all data to start from scratch
clear();

// add mesh data back, duplicating vertices and recalculating normals
N normal;
for(ofIndexType i = 0; i < indices.size(); i++) {
ofIndexType indexCurr = indices[i];

if(i % 3 == 0) {
ofIndexType indexNext1 = indices[i + 1];
ofIndexType indexNext2 = indices[i + 2];
auto e1 = verts[indexCurr] - verts[indexNext1];
auto e2 = verts[indexNext2] - verts[indexNext1];
normal = glm::normalize(glm::cross(e1, e2));
}

addIndex(i);
addNormal(normal);

if(indexCurr < texCoords.size()) {
addTexCoord(texCoords[indexCurr]);
}

if(indexCurr < verts.size()) {
addVertex(verts[indexCurr]);
}

if(indexCurr < colors.size()) {
addColor(colors[indexCurr]);
}
Expand Down Expand Up @@ -1949,7 +1949,7 @@ ofMesh_<V,N,C,T> ofMesh_<V,N,C,T>::plane(float width, float height, int columns,
// the origin of the plane is at the center //
float halfW = width * 0.5f;
float halfH = height * 0.5f;

// add the vertexes //
for(int iy = 0; iy != rows; iy++) {
for(int ix = 0; ix != columns; ix++) {
Expand Down Expand Up @@ -2094,21 +2094,21 @@ ofMesh_<V,N,C,T> ofMesh_<V,N,C,T>::sphere( float radius, int res, ofPrimitiveMod
/*
-----------------------------------------------------------------------------
This source file is part of ogre-procedural
For the latest info, see http://code.google.com/p/ogre-procedural/
Copyright (c) 2010 Michael Broutin
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down Expand Up @@ -2143,7 +2143,7 @@ ofMesh_<V,N,C,T> ofMesh_<V,N,C,T>::icosphere(float radius, std::size_t iteration
const float phi = (1.0f + sqrt5) * 0.5f;
const float invnorm = 1/std::sqrt(phi*phi+1);


// FIXME: addvertices XAXA
sphere.addVertex(invnorm * V(-1, phi, 0));//0
sphere.addVertex(invnorm * V( 1, phi, 0));//1
Expand All @@ -2157,7 +2157,7 @@ ofMesh_<V,N,C,T> ofMesh_<V,N,C,T>::icosphere(float radius, std::size_t iteration
sphere.addVertex(invnorm * V(0, -1, phi));//9
sphere.addVertex(invnorm * V(-1, -phi,0));//10
sphere.addVertex(invnorm * V( 1, -phi,0));//11

ofIndexType firstFaces[] = {
0,1,2,
0,3,1,
Expand All @@ -2184,7 +2184,7 @@ ofMesh_<V,N,C,T> ofMesh_<V,N,C,T>::icosphere(float radius, std::size_t iteration
for(ofIndexType i = 0; i < 60; i+=3) {
sphere.addTriangle(firstFaces[i], firstFaces[i+1], firstFaces[i+2]);
}

auto& vertices = sphere.getVertices();
auto& faces = sphere.getIndices();

Expand Down Expand Up @@ -2243,7 +2243,7 @@ ofMesh_<V,N,C,T> ofMesh_<V,N,C,T>::icosphere(float radius, std::size_t iteration
u = alpha/glm::two_pi<float>()+.5f;
v = atan2f(vec.y, r0)/glm::pi<float>() + .5f;
// reverse the u coord, so the default is texture mapped left to
// right on the outside of a sphere
// right on the outside of a sphere
// reverse the v coord, so that texture origin is at top left
texCoords.push_back(T(1.0-u,1.f-v));
}
Expand Down Expand Up @@ -2309,7 +2309,7 @@ ofMesh_<V,N,C,T> ofMesh_<V,N,C,T>::icosphere(float radius, std::size_t iteration
// tig: flip face(=triangle) winding order, so that we are consistent with all other ofPrimitives.
// i wish there was a more elegant way to do this, but anything happening before "split vertices"
// makes things very, very complicated.

for (ofIndexType i = 0; i < faces.size(); i+=3) {
std::swap(faces[i+1], faces[i+2]);
}
Expand Down
25 changes: 9 additions & 16 deletions libs/openFrameworks/3d/ofNode.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include "ofNode.h"
#include "of3dGraphics.h"

#define GLM_FORCE_CTOR_INIT
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/mat4x4.hpp>

//----------------------------------------
Expand Down Expand Up @@ -435,9 +433,9 @@ void ofNode::rotateAround(const glm::quat& q, const glm::vec3& point) {
// glm::mat4 m = getLocalTransformMatrix();
// m.setTranslation(point);
// m.rotate(q);

setGlobalPosition(q * (getGlobalPosition() - point) + point);

onOrientationChanged();
onPositionChanged();
}
Expand Down Expand Up @@ -479,10 +477,7 @@ void ofNode::lookAt(const glm::vec3& lookAtPosition, glm::vec3 upVector) {
if (glm::length(zaxis) > 0) {
auto xaxis = glm::normalize(glm::cross(upVector, zaxis));
auto yaxis = glm::cross(zaxis, xaxis);
glm::mat3 m;
m[0] = xaxis;
m[1] = yaxis;
m[2] = zaxis;
glm::mat3 m { xaxis, yaxis, zaxis };

setGlobalOrientation(glm::toQuat(m));
}
Expand Down Expand Up @@ -625,15 +620,15 @@ void ofNode::orbitDeg(float longitude, float latitude, float radius, ofNode& cen

//----------------------------------------
void ofNode::orbitDeg(float longitude, float latitude, float radius, const glm::vec3& centerPoint) {
glm::quat q =
glm::quat q =
glm::angleAxis(glm::radians(longitude), glm::vec3(0, 1, 0))
* glm::angleAxis(glm::radians(latitude), glm::vec3(1, 0, 0));

glm::vec4 p { 0.f, 0.f, 1.f, 0.f }; // p is a direction, not a position, so .w == 0

p = q * p; // rotate p on unit sphere based on quaternion
p = p * radius; // scale p by radius from its position on unit sphere

// setGlobalPosition(centerPoint + p);
setGlobalPosition(centerPoint + glm::vec3{p.x, p.y, p.z} );
setOrientation(q);
Expand All @@ -649,12 +644,12 @@ void ofNode::orbitRad(float longitude, float latitude, float radius, ofNode& cen

//----------------------------------------
void ofNode::orbitRad(float longitude, float latitude, float radius, const glm::vec3& centerPoint) {
glm::quat q =
glm::angleAxis(longitude, glm::vec3(0, 1, 0))
glm::quat q =
glm::angleAxis(longitude, glm::vec3(0, 1, 0))
* glm::angleAxis(latitude, glm::vec3(1, 0, 0));

glm::vec4 p { 0.f, 0.f, 1.f, 0.f }; // p is a direction, not a position, so .w == 0

p = q * p; // rotate p on unit sphere based on quaternion
p = p * radius; // scale p by radius from its position on unit sphere

Expand Down Expand Up @@ -721,5 +716,3 @@ void ofNode::createMatrix() {

updateAxis();
}


Loading

0 comments on commit c2da2ca

Please sign in to comment.