Skip to content
This repository was archived by the owner on Jun 11, 2025. It is now read-only.
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
Binary file added reports/RelatorioFase4.pdf
Binary file not shown.
500 changes: 353 additions & 147 deletions reports/RelatorioFase4.tex

Large diffs are not rendered by default.

Binary file added reports/res/phase4/Barrel.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added reports/res/phase4/BoxOrientation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed reports/res/phase4/IceCreamXYZ.png
Binary file not shown.
Binary file added reports/res/phase4/SphereUV.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added reports/res/phase4/results/BoxMultiTexture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added reports/res/phase4/results/BoxSingleTexture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added reports/res/phase4/results/Bunny.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added reports/res/phase4/results/Cow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added reports/res/phase4/results/Dragon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added reports/res/phase4/results/Plane.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added reports/res/phase4/results/Sphere.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added reports/res/phase4/results/Teapot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added reports/res/phase4/results/ThirdPerson.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added reports/res/phase4/results/Torus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 13 additions & 2 deletions res/scenes/bunny.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,20 @@
<up x="0" y="0.06" z="0" />
<projection fov="20" near="0.1" far="1000" />
</camera>
<lights>
<light type="directional" dirX="1" dirY="1" dirZ="1" />
</lights>
<group>
<models>
<model file="../models/bunny.obj" />
<model file="../models/bunny.obj">
<color>
<diffuse R="255" G="161" B="193"/>
<ambient R="145" G="91" B="109"/>
<specular R="0" G="0" B="0"/>
<emissive R="0" G="0" B="0"/>
<shininess value="0"/>
</color>
</model>
</models>
</group>
</world>
</world>
13 changes: 12 additions & 1 deletion res/scenes/cow.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,20 @@
<up x="0" y="1" z="0" />
<projection fov="60" near="1" far="1000" />
</camera>
<lights>
<light type="directional" dirX="1" dirY="1" dirZ="1" />
</lights>
<group>
<models>
<model file="../models/cow.obj" />
<model file="../models/cow.obj">
<color>
<diffuse R="54" G="24" B="8"/>
<ambient R="31" G="14" B="5"/>
<specular R="0" G="0" B="0"/>
<emissive R="0" G="0" B="0"/>
<shininess value="0"/>
</color>
</model>
</models>
</group>
</world>
15 changes: 13 additions & 2 deletions res/scenes/dragon.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,20 @@
<up x="0" y="1" z="0" />
<projection fov="50" near="1" far="100" />
</camera>
<lights>
<light type="directional" dirX="1" dirY="1" dirZ="1" />
</lights>
<group>
<models>
<model file="../models/dragon.obj" />
<model file="../models/dragon.obj">
<color>
<diffuse R="212" G="175" B="55"/>
<ambient R="77" G="63" B="20"/>
<specular R="255" G="215" B="0"/>
<emissive R="0" G="0" B="0"/>
<shininess value="100"/>
</color>
</model>
</models>
</group>
</world>
</world>
2 changes: 1 addition & 1 deletion res/scenes/gear.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
<model file="../models/gear.3d" />
</models>
</group>
</world>
</world>
15 changes: 13 additions & 2 deletions res/scenes/homer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,20 @@
<up x="0" y="0.06" z="0" />
<projection fov="19" near="0.1" far="100" />
</camera>
<lights>
<light type="directional" dirX="1" dirY="1" dirZ="1" />
</lights>
<group>
<models>
<model file="../models/homer.obj" />
<model file="../models/homer.obj">
<color>
<diffuse R="212" G="175" B="55"/>
<ambient R="77" G="63" B="20"/>
<specular R="0" G="0" B="0"/>
<emissive R="0" G="0" B="0"/>
<shininess value="0"/>
</color>
</model>
</models>
</group>
</world>
</world>
File renamed without changes.
8 changes: 0 additions & 8 deletions res/scenes/plane.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@
/>
</lights>
<group>
<transform>
<translate time="10">
<point x = "2" y = "0" z = "0" />
<point x = "0" y = "0" z = "2" />
<point x = "-2" y = "0" z = "0" />
<point x = "0" y = "0" z = "-2" />
</translate>
</transform>
<models>
<model file="../models/plane.3d">
<texture file="../textures/planeOrientation.jpg" />
Expand Down
19 changes: 17 additions & 2 deletions res/scenes/thirdPerson.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,31 @@
<translate x="-0.503" y="-0.153" z="-0.471" />
</transform>
<models>
<model file="../models/homer.obj" />
<model file="../models/homer.obj">
<color>
<diffuse R="212" G="175" B="55"/>
<ambient R="77" G="63" B="20"/>
<specular R="0" G="0" B="0"/>
<emissive R="0" G="0" B="0"/>
<shininess value="0"/>
</color>
</model>
</models>
</group>
</camera>

<lights>
<light type="directional" dirX="1" dirY="1" dirZ="1" />
</lights>

<group>
<transform>
<scale x="3.0" y ="1.0" z="3.0" />
</transform>
<models>
<model file="../models/plane.3d" />
<model file="../models/plane.3d">
<texture file="../textures/relva.jpg" />
</model>
</models>
</group>
</world>
Binary file added res/textures/relva.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions src/generator/figures/Cone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ Cone::Cone(float radius, float height, int slices, int stacks) {
for (int iStack = 0; iStack <= stacks; iStack++) {
const float y = iStack * stackStep;
const float stackRadius = ((height - y) * radius) / height;
const float v = static_cast<float>(iStack) / stacks;
const float t = static_cast<float>(iStack) / stacks;

for (int jSlice = 0; jSlice <= slices; jSlice++) {
const float angle = jSlice * sliceStep;
const float x = stackRadius * cosf(angle);
const float z = stackRadius * sinf(angle);
this->positions.push_back(glm::vec4(x, y, z, 1.0f));

const float u = static_cast<float>(jSlice) / slices;
this->textureCoordinates.push_back(glm::vec2(u, v));
const float s = static_cast<float>(jSlice) / slices;
this->textureCoordinates.push_back(glm::vec2(s, t));
}
}

Expand Down
18 changes: 9 additions & 9 deletions src/generator/figures/Cylinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ Cylinder::Cylinder(float radius, float height, int slices, int stacks, bool mult
this->positions.push_back(glm::vec4(x, 0, z, 1.0f));
this->normals.push_back(glm::vec3(0.0f, -1.0f, 0.0f));

float u = multiTextured ? (x / (2 * radius)) * 0.35f + 0.8125f : x / (2 * radius) + 0.5f;
float v = multiTextured ? (z / (2 * radius)) * 0.35f + 0.1875f : z / (2 * radius) + 0.5f;
this->textureCoordinates.push_back(glm::vec2(u, v));
float s = multiTextured ? (x / (2 * radius)) * 0.35f + 0.8125f : x / (2 * radius) + 0.5f;
float t = multiTextured ? (z / (2 * radius)) * 0.35f + 0.1875f : z / (2 * radius) + 0.5f;
this->textureCoordinates.push_back(glm::vec2(s, t));
}

for (int jSlice = 0; jSlice < slices; jSlice++) {
Expand All @@ -65,19 +65,19 @@ Cylinder::Cylinder(float radius, float height, int slices, int stacks, bool mult
for (int iStack = 0; iStack <= stacks; iStack++) {
float y = iStack * stackStep;

float v = multiTextured ? 0.375f + (static_cast<float>(iStack) / stacks) * (1.0f - 0.375f) :
float t = multiTextured ? 0.375f + (static_cast<float>(iStack) / stacks) * (1.0f - 0.375f) :
static_cast<float>(iStack) / stacks;

for (int jSlice = 0; jSlice <= slices; jSlice++) {
float phi = jSlice * sliceStep;
float x = radius * cos(phi);
float z = radius * sin(phi);

float u = 1.0f - static_cast<float>(jSlice) / slices;
float s = 1.0f - static_cast<float>(jSlice) / slices;

this->positions.push_back(glm::vec4(x, y, z, 1.0f));
this->normals.push_back(glm::normalize(glm::vec3(x, 0.0f, z)));
this->textureCoordinates.push_back(glm::vec2(u, v));
this->textureCoordinates.push_back(glm::vec2(s, t));
}
}

Expand Down Expand Up @@ -123,9 +123,9 @@ Cylinder::Cylinder(float radius, float height, int slices, int stacks, bool mult
this->positions.push_back(glm::vec4(x, height, z, 1.0f));
this->normals.push_back(glm::vec3(0.0f, 1.0f, 0.0f));

float u = multiTextured ? (x / (2 * radius)) * 0.35f + 0.4375f : x / (2 * radius) + 0.5f;
float v = multiTextured ? (z / (2 * radius)) * 0.35f + 0.1875f : z / (2 * radius) + 0.5f;
this->textureCoordinates.push_back(glm::vec2(u, v));
float s = multiTextured ? (x / (2 * radius)) * 0.35f + 0.4375f : x / (2 * radius) + 0.5f;
float t = multiTextured ? (z / (2 * radius)) * 0.35f + 0.1875f : z / (2 * radius) + 0.5f;
this->textureCoordinates.push_back(glm::vec2(s, t));
}

for (int jSlice = 0; jSlice < slices; jSlice++) {
Expand Down
16 changes: 7 additions & 9 deletions src/generator/figures/Sphere.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,26 @@ Sphere::Sphere(float radius, int slices, int stacks) {
this->positions.push_back(glm::vec4(0.0f, radius, 0.0f, 1.0f));
this->normals.push_back(glm::normalize(glm::vec3(0.0f, 1.0f, 0.0f)));
for (int jSlice = 0; jSlice < slices; jSlice++) {
const float u = jSlice * textureSliceStep + textureSliceStep / 2;

this->textureCoordinates.push_back(glm::vec2(u, 1.0f));
const float s = jSlice * textureSliceStep + textureSliceStep / 2;
this->textureCoordinates.push_back(glm::vec2(s, 1.0f));
}

// Generate center
for (int iStack = 1; iStack < stacks; iStack++) {
const float theta = iStack * stackStep;
const float y = radius * cosf(theta);
const float xz = radius * sinf(theta);
const float v = 1.0f - static_cast<float>(iStack) / stacks;
const float t = 1.0f - static_cast<float>(iStack) / stacks;

for (int jSlice = 0; jSlice <= slices; jSlice++) {
const float phi = jSlice * sliceStep;
const float x = xz * sinf(phi);
const float z = xz * cosf(phi);
const float u = static_cast<float>(jSlice) / slices;
const float s = static_cast<float>(jSlice) / slices;

this->positions.push_back(glm::vec4(x, y, z, 1.0f));
this->normals.push_back(glm::normalize(glm::vec3(x, y, z)));
this->textureCoordinates.push_back(glm::vec2(u, v));
this->textureCoordinates.push_back(glm::vec2(s, t));
}
}

Expand All @@ -65,9 +64,8 @@ Sphere::Sphere(float radius, int slices, int stacks) {
this->normals.push_back(glm::normalize(glm::vec3(0.0f, -1.0f, 0.0f)));

for (int jSlice = 0; jSlice < slices; jSlice++) {
const float u = jSlice * textureSliceStep + textureSliceStep / 2;

this->textureCoordinates.push_back(glm::vec2(u, 0.0f));
const float s = jSlice * textureSliceStep + textureSliceStep / 2;
this->textureCoordinates.push_back(glm::vec2(s, 0.0f));
}

for (int jSlice = 0; jSlice < slices; jSlice++) {
Expand Down
6 changes: 3 additions & 3 deletions src/generator/figures/Torus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ Torus::Torus(float majorRadius, float minorRadius, int slices, int sides) {
this->positions.push_back(glm::vec4(vertex, 1.0f));
this->normals.push_back(normal);

const float u = static_cast<float>(iSlice) / slices;
const float v = static_cast<float>(jSide) / sides;
this->textureCoordinates.push_back(glm::vec2(u, v));
const float s = static_cast<float>(iSlice) / slices;
const float t = static_cast<float>(jSide) / sides;
this->textureCoordinates.push_back(glm::vec2(s, t));
}
}

Expand Down
9 changes: 1 addition & 8 deletions src/utils/WavefrontOBJ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ std::tuple<std::vector<glm::vec4>,

void WavefrontOBJ::generateNormals() {
std::unordered_map<glm::vec4, glm::vec3> averageNormals;
std::unordered_map<glm::vec4, float> averageWeights;

for (const TriangleFace &face : this->faces) {
// Get points and sides of the triangle
Expand All @@ -281,20 +280,14 @@ void WavefrontOBJ::generateNormals() {

// Calculate weighted average
const glm::vec3 normal = glm::normalize(glm::cross(v0, v1)) * area;

averageNormals[p0] += normal;
averageWeights[p0] += area;
averageNormals[p1] += normal;
averageWeights[p1] += area;
averageNormals[p2] += normal;
averageWeights[p2] += area;
}

for (const glm::vec4 &position : this->positions) {
const glm::vec3 perpendicular = averageNormals[position];
const float weight = averageWeights[position];

this->normals.push_back(glm::normalize(perpendicular / weight));
this->normals.push_back(glm::normalize(perpendicular));
}
}

Expand Down