Angle between normal of adjacent faces using the dot product:
dot(n1,n2)=∣n1∣⋅∣n2∣⋅cos(θ)
dot(n1,n2)=∣n1∣⋅∣n2∣⋅cos(θ)
Dot Product and Angle - https://mathinsight.org/search/?q=dot+product
Vector Normalization - https://en.wikipedia.org/wiki/Unit_vector
OpenGL: Normals - https://learnopengl.com/Lighting/Basic-Lighting
Wikipedia: Normal - https://en.wikipedia.org/wiki/Normal_(geometry)
OpenGL : Smooth Shading - https://www.opengl.org/archives/resources/faq/technical/
Blender Manual: Auto Smooth - https://docs.blender.org/manual/en/latest/modeling/modifiers/normals/smooth_by_angle.html
glm::vec3 n1(1.0f, 0.0f, 0.0f); // Normal vector 1
glm::vec3 n2(0.0f, 1.0f, 0.0f); // Normal vector 2
float dotProduct = glm::dot(n1, n2); // Dot product
float magnitudeN1 = glm::length(n1); // Magnitudes
float magnitudeN2 = glm::length(n2);
float cosTheta = dotProduct / (magnitudeN1 * magnitudeN2);// Cosine of the angle
float angle = glm::degrees(std::acos(cosTheta));// Angle in degrees
Nath's digital art blog of tests, experiments, notes and practice sessions.
Monday, 9 December 2024
Added a Smooth Normals Slide Bar
Added Some MAYA Style Navigation Functionality
Added some "Maya Style" Navigation control:
# mousePressEvent = True
# mouseReleaseEvent = False
# Rotate camera
camera_rotation[0] += delta.y() * 0.2
camera_rotation[1] += delta.x() * 0.2
# Pan camera
camera_translation[0] += delta.x() * 0.01
camera_translation[1] -= delta.y() * 0.01
# Zoom camera
camera_translation[2] += delta.y() * 0.05
3D App Creation - A learning exercise
Learning exercise - making a 3d app of some sort. Not sure what sort. c++ and python combo.
So far I've learnt about:
PyOpenGL = http://pyopengl.sourceforge.net/documentation/
GLFW = https://www.glfw.org/docs/latest/build_guide.html
vcpkg = automate dependency setup for GLFW and other libraries
vcpkg and CMake = https://vcpkg.io/en/getting-started.html
CMake Script FindGLFW3.cmake = https://cmake.org/cmake/help/latest/command/find_package.html
Wavefront OBJ = Details https://en.wikipedia.org/wiki/Wavefront_.obj_file
Lighting & Materials- OpenGL = https://learnopengl.com/Lighting/Basic-Lighting
Transformations - OpenGL = https://learnopengl.com/Getting-started/Transformations
Triangle Normal Calculation in OpenGL = https://learnopengl.com/Lighting/Basic-Lighting
OBJ Preprocessing for Compatibility = https://github.com/pywavefront/PyWavefront
Hardest part to solve - Exploding Vertices after obj import
Face Def / Quad Handling -
- OBJ files contain non-standard face definitions + use quads .
- Needed to convert quads to triangles = face definitions standardized.
- Had to remove unnecessary lines \ smoothing groups - simplify parsing.
Vertex Normalization -
- Needed to sort incorrect scaling or positioning due to varying coordinate extents = calculate (normalize) the center and maximum extent of the model
- needed to reposition and scaling vertices to fit within a view.
Missing Vertices -
- needed to use checks to skip invalid data = avoid crashing
Incomplete Triangles -
- The `pywavefront` library was, on my first attempt, returning only partial vertex data.
- Had to force triangles to adhered to a set length - for example the common graphics issue - avoiding malformed geometry.
Labels:
3D,
C++,
CMake,
code,
GLFW,
Lighting & Materials,
OBJ,
OpenGL,
Programming,
PyOpenGL,
Python,
rendering,
vcpkg,
Visual Studio,
Wavefront OBJ
Subscribe to:
Posts (Atom)