-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'jp/textures' of github.com:JulioJPinto/CG-Project into …
…jp/textures
- Loading branch information
Showing
4 changed files
with
107 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#ifndef FRUSTSUM_CPP | ||
#define FRUSTSUM_CPP | ||
|
||
#include <math.h> | ||
|
||
#include <glm/glm.hpp> | ||
|
||
#include "model.hpp" | ||
#include "Camera.hpp" | ||
|
||
|
||
struct Plane { | ||
|
||
float distance = 0.f; | ||
glm::vec3 normal = { 0.f, 1.f, 0.f }; | ||
|
||
Plane() = default; | ||
Plane(const Plane& other) = default; | ||
Plane(const glm::vec3& normal, float distance) : normal(normal), distance(distance) {} | ||
|
||
float distanceToPoint(const glm::vec3& point) const { | ||
return glm::dot(normal, point) + distance; | ||
} | ||
|
||
|
||
}; | ||
|
||
struct Frustsum { | ||
Plane nearFace; | ||
Plane farFace; | ||
Plane rightFace; | ||
Plane leftFace; | ||
Plane topFace; | ||
Plane bottomFace; | ||
|
||
Frustsum() = default; | ||
Frustsum(const Frustsum& other) = default; | ||
Frustsum(const Plane& nearFace, const Plane& farFace, const Plane& rightFace, const Plane& leftFace, const Plane& topFace, const Plane& bottomFace) | ||
: nearFace(nearFace), farFace(farFace), rightFace(rightFace), leftFace(leftFace), topFace(topFace), bottomFace(bottomFace) {} | ||
|
||
Frustsum createFrustumFromCamera(const Camera& cam); | ||
|
||
bool isInsideFrustsum(const Model& model); | ||
}; | ||
|
||
|
||
#endif // FRUSTSUM_CPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,4 @@ | ||
#include <glm/glm.hpp> | ||
#include <glm/gtc/matrix_transform.hpp> | ||
#include "frustsum.hpp" | ||
|
||
// Frustum createFrustumFromCamera(const Camera& cam, float aspect, float fovY, | ||
// float zNear, | ||
// float zFar) | ||
// { | ||
// Frustum frustum; | ||
// const float halfVSide = zFar * tanf(fovY * .5f); | ||
// const float halfHSide = halfVSide * aspect; | ||
// const glm::vec3 frontMultFar = zFar * cam.Front; | ||
|
||
// frustum.nearFace = { cam.Position + zNear * cam.Front, cam.Front }; | ||
// frustum.farFace = { cam.Position + frontMultFar, -cam.Front }; | ||
// frustum.rightFace = { cam.Position, | ||
// glm::cross(frontMultFar - cam.Right * halfHSide, | ||
// cam.Up) }; | ||
// frustum.leftFace = { cam.Position, | ||
// glm::cross(cam.Up,frontMultFar + cam.Right * | ||
// halfHSide) }; | ||
// frustum.topFace = { cam.Position, | ||
// glm::cross(cam.Right, frontMultFar - cam.Up * | ||
// halfVSide) }; | ||
// frustum.bottomFace = { cam.Position, | ||
// glm::cross(frontMultFar + cam.Up * halfVSide, | ||
// cam.Right) }; | ||
|
||
// return frustum; | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from PIL import Image | ||
import sys | ||
|
||
def check_image_format(image_path): | ||
try: | ||
with Image.open(image_path) as img: | ||
mode = img.mode | ||
format = img.format | ||
size = img.size | ||
|
||
if mode == "L": | ||
num_channels = 1 # Grayscale | ||
opengl_format = "GL_RED" | ||
elif mode == "LA": | ||
num_channels = 2 # Grayscale + Alpha | ||
opengl_format = "GL_RG" | ||
elif mode == "RGB": | ||
num_channels = 3 # RGB | ||
opengl_format = "GL_RGB" | ||
elif mode == "RGBA": | ||
num_channels = 4 # RGBA | ||
opengl_format = "GL_RGBA" | ||
else: | ||
num_channels = len(mode) # Other modes like "CMYK" | ||
opengl_format = "Unknown or not directly supported" | ||
|
||
print(f"Image Format: {format}") | ||
print(f"Image Size: {size}") | ||
print(f"Number of Channels: {num_channels}") | ||
print(f"OpenGL Format: {opengl_format}") | ||
|
||
except IOError: | ||
print(f"Cannot open image file: {image_path}") | ||
|
||
if __name__ == "__main__": | ||
if len(sys.argv) != 2: | ||
print("Usage: python check_image_format.py <image_path>") | ||
else: | ||
image_path = sys.argv[1] | ||
check_image_format(image_path) |