Skip to content

Commit d89c01c

Browse files
author
Ekaterina Altunina
committed
DONE
1 parent 74fc276 commit d89c01c

8 files changed

Lines changed: 78 additions & 57 deletions

File tree

src/App/Camera.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,10 @@ QVector3D Camera::getWorldCoord(float screenX, float screenY, float width, float
128128
return QVector3D(wx, wy, wz);
129129
}
130130

131-
void Camera::zoom(const QVector3D & mouseData, float width, float height, float)
131+
void Camera::zoom(const QVector3D & mouseData, float, float, float)
132132
{
133133

134-
QVector3D before = getWorldCoord(mouseData.x(), mouseData.y(), width, height, mouseData.z());
135-
fov_ = fov_ * std::pow(1.1f, -mouseData.z());
136-
setToPerspective(fov_, width / height, nearPlane_, farPlane_);
137-
QVector3D after = getWorldCoord(mouseData.x(), mouseData.y(), width, height, mouseData.z());
138-
QVector3D delta = before - after;
139-
position_ += delta;
134+
position_.setZ(position_.z() - mouseData.z());
140135
updateCameraVectors();
141136
}
142137

src/App/EntityModel.cpp

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -116,20 +116,6 @@ std::vector<std::unique_ptr<QOpenGLTexture>> EntityModel::loadTextures(const tin
116116
}
117117
}
118118

119-
for (size_t i = 0; i < textures_.size(); ++i)
120-
{
121-
if (textures_[i])
122-
{
123-
qDebug() << "Texture" << i
124-
<< "ID:" << textures_[i]->textureId()
125-
<< "Created:" << textures_[i]->isCreated()
126-
<< "Size:" << textures_[i]->width() << "x" << textures_[i]->height();
127-
}
128-
else
129-
{
130-
qDebug() << "Texture" << i << "is null";
131-
}
132-
}
133119
return textures_;
134120
}
135121

@@ -141,8 +127,7 @@ std::vector<ModelMesh> EntityModel::loadMeshes(const tinygltf::Model & model)
141127
for (const auto & primitive: mesh.primitives)
142128
{
143129
ModelMesh meshData;
144-
// std::cout << primitive.indices << "\n";
145-
// filling vertices
130+
146131
for (const auto & attributeName: {"POSITION", "NORMAL", "TEXCOORD_0"})
147132
{
148133
if (primitive.attributes.count(attributeName) == 0)
@@ -221,7 +206,6 @@ std::vector<ModelMesh> EntityModel::loadMeshes(const tinygltf::Model & model)
221206
meshData.textureIndex = material.pbrMetallicRoughness.baseColorTexture.index;
222207
}
223208
}
224-
std::cout << meshData.textureIndex << "\n";
225209
meshes_.push_back(std::move(meshData));
226210
}
227211
}

src/App/Light.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#pragma once
22

3-
#include <GL/gl.h>
43
#include <QMatrix4x4>
54
#include <QOpenGLShaderProgram>
65
#include <QVector3D>

src/App/SceneRenderer.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ void SceneRenderer::initUniformValues()
4545
uniformDirectional_ = program_->uniformLocation("hasDirectional");
4646
uniformProjection_ = program_->uniformLocation("hasProjection");
4747
uniformViewPos_ = program_->uniformLocation("viewPos");
48+
uniformRadius_ = program_->uniformLocation("sphereRadius");
4849
uniformMorph_ = program_->uniformLocation("morphIntensity");
4950
}
5051

@@ -57,14 +58,16 @@ void SceneRenderer::initLights()
5758
void SceneRenderer::setUniformValues(const QMatrix4x4 & mvp,
5859
bool directional_,
5960
bool projection_,
60-
float morph)
61+
float morph,
62+
float radius)
6163
{
6264
if (entityModel)
6365
program_->setUniformValue(entityModel->mvpUniform_, mvp);
6466

6567
program_->setUniformValue(uniformDirectional_, directional_);
6668
program_->setUniformValue(uniformProjection_, projection_);
6769
program_->setUniformValue(uniformMorph_, morph);
70+
program_->setUniformValue(uniformRadius_, radius);
6871
program_->setUniformValue(uniformViewPos_, camera->position());
6972
}
7073

@@ -79,6 +82,7 @@ bool SceneRenderer::onInit(fgl::GLWidget * window)
7982
entityModel = new EntityModel(program_);
8083
entityModel->setScale(QVector3D(0.1f, 0.1f, 0.1f));
8184
entityModel->setPosition(QVector3D(0.0f, 0.0f, -1.0f));
85+
entityModel->setRotation({180.0f, 180.0f, 0.0f});
8286

8387
initUniformValues();
8488
initLights();
@@ -106,7 +110,7 @@ bool SceneRenderer::onRender(SlidersGroup * window, const QMatrix4x4 & mvp)
106110
setUniformValues(mvp,
107111
window->hasDirectional,
108112
window->hasProjection,
109-
window->morph);
113+
window->morph, window->circleRadius);
110114

111115
if (dirLight)
112116
{
@@ -124,9 +128,9 @@ bool SceneRenderer::onRender(SlidersGroup * window, const QMatrix4x4 & mvp)
124128
window->getVector(2),
125129
window->projectionLightColor,
126130
camera->y(),
127-
window->ambient,
128-
window->diffuse,
129-
window->specular,
131+
window->ambientP,
132+
window->diffuseP,
133+
window->specularP,
130134
window->projCutOff,
131135
window->projOuterCutOff, program_);
132136
}

src/App/SceneRenderer.h

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ struct SceneRenderer {
2525
void setUniformValues(const QMatrix4x4 & mvp,
2626
bool directional_,
2727
bool projection_,
28-
float morph);
28+
float morph,
29+
float radius);
2930

3031
void rotateObj(const QVector2D & rotation);
3132

@@ -46,21 +47,9 @@ struct SceneRenderer {
4647
EntityModel * entityModel = nullptr;
4748

4849
GLfloat uniformMorph_ = 0.0f;
50+
GLfloat uniformRadius_ = 1.0f;
4951
GLboolean uniformDirectional_ = true;
5052
GLboolean uniformProjection_ = true;
5153

5254
GLint uniformViewPos_ = 1.0f;
53-
// GLint uniformLightPosition_ = 1.0f;
54-
// GLint uniformLightColor_ = 1.0f;
55-
56-
// GLint uniformProjLightPosition_ = 1.0f;
57-
// GLint uniformProjLightColor_ = 1.0f;
58-
// GLint uniformProjCutOff_ = 1.0f;
59-
// GLint uniformProjOuterCutOff_ = 1.0f;
60-
// GLint uniformProjLightDir_ = 1.0f;
61-
62-
// GLint uniformViewPos_ = 1.0f;
63-
// GLfloat uniformAmbient_ = 1.0f;
64-
// GLfloat uniformDiffuse_ = 1.0f;
65-
// GLfloat uniformSpecular_ = 1.0f;
6655
};

src/App/SliderGroup.cpp

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@ void SlidersGroup::createSliders()
3838
// morph
3939
morphLayout = new QVBoxLayout(morphGroup);
4040
morph_ = addSlider(0, 100, morph, 0.01, "Morph intensity", morphLayout);
41+
circleRadius_ = addSlider(0, 1000, ambientP, 0.01f, "Radius:", morphLayout);
4142
// positions
42-
lightLayout = new QVBoxLayout(lightGroup);
43-
diffuse_ = addSlider(0, 100, diffuse, 0.01f, "Diffuse:", lightLayout);
44-
specular_ = addSlider(0, 100, specular, 0.01f, "Specular:", lightLayout);
45-
ambient_ = addSlider(0, 100, ambient, 0.01f, "Ambient:", lightLayout);
46-
43+
4744
// colors
4845
directionLayout = new QVBoxLayout(directionGroup);
4946
hasDirectional_ = addToggle("Has Directional", directionLayout);
5047
directionalLightPosition_ = addInputs("Light Position", directionLayout, directionalLightPosition);
5148
directionalLightColor_ = addColorButton("", directionalLightColor, directionLayout);
49+
diffuse_ = addSlider(0, 100, diffuse, 0.01f, "Diffuse:", directionLayout);
50+
specular_ = addSlider(0, 100, specular, 0.01f, "Specular:", directionLayout);
51+
ambient_ = addSlider(0, 100, ambient, 0.01f, "Ambient:", directionLayout);
5252

5353
projectionLayout = new QVBoxLayout(projectionGroup);
5454
hasProjection_ = addToggle("Has Projector", projectionLayout);
@@ -57,8 +57,9 @@ void SlidersGroup::createSliders()
5757
projCutOff_ = addSlider(0, 3600, projCutOff, 0.1f, "Cutoff:", projectionLayout);
5858
projOuterCutOff_ = addSlider(0, 3600, projOuterCutOff, 0.1f, "Outer Cutoff:", projectionLayout);
5959
projectionLightColor_ = addColorButton("", projectionLightColor, projectionLayout);
60-
61-
60+
diffuseP_ = addSlider(0, 100, diffuseP, 0.01f, "Diffuse:", projectionLayout);
61+
specularP_ = addSlider(0, 100, specularP, 0.01f, "Specular:", projectionLayout);
62+
ambientP_ = addSlider(0, 100, ambientP, 0.01f, "Ambient:", projectionLayout);
6263
setFixedWidth(300);
6364
}
6465

@@ -114,7 +115,6 @@ void SlidersGroup::setupLayout()
114115
this->setStyleSheet("background-color: lightblue;");
115116
mainLayout = new QVBoxLayout();
116117
mainLayout->addWidget(morphGroup);
117-
mainLayout->addWidget(lightGroup);
118118
mainLayout->addWidget(directionGroup);
119119
mainLayout->addWidget(projectionGroup);
120120
mainLayout->setContentsMargins(10, 10, 10, 10);
@@ -127,6 +127,11 @@ void SlidersGroup::connectSignals()
127127
connect(ambient_, &QSlider::valueChanged, this, &SlidersGroup::onAmbientChanged);
128128
connect(diffuse_, &QSlider::valueChanged, this, &SlidersGroup::onDiffuseChanged);
129129
connect(specular_, &QSlider::valueChanged, this, &SlidersGroup::onSpecularChanged);
130+
131+
connect(ambientP_, &QSlider::valueChanged, this, &SlidersGroup::onAmbientPChanged);
132+
connect(diffuseP_, &QSlider::valueChanged, this, &SlidersGroup::onDiffusePChanged);
133+
connect(specularP_, &QSlider::valueChanged, this, &SlidersGroup::onSpecularPChanged);
134+
130135
connect(directionalLightColor_, &QPushButton::clicked, this, &SlidersGroup::onColorDirButtonClicked);
131136
connect(projectionLightColor_, &QPushButton::clicked, this, &SlidersGroup::onColorProjButtonClicked);
132137

@@ -137,6 +142,13 @@ void SlidersGroup::connectSignals()
137142
connect(projOuterCutOff_, &QSlider::valueChanged, this, &SlidersGroup::onOuterCutOffClicked);
138143

139144
connect(morph_, &QSlider::valueChanged, this, &SlidersGroup::onMorphChanged);
145+
146+
connect(circleRadius_, &QSlider::valueChanged, this, &SlidersGroup::onRadiusChanged);
147+
}
148+
149+
void SlidersGroup::onRadiusChanged(int value) {
150+
circleRadius = value * 0.01f;
151+
emit morphChanged(value);
140152
}
141153

142154
void SlidersGroup::onMorphChanged(int value)
@@ -182,6 +194,24 @@ void SlidersGroup::onDiffuseChanged(int value)
182194
}
183195

184196
void SlidersGroup::onSpecularChanged(int value)
197+
{
198+
specularP = (float)value * 0.01f;
199+
emit specularPChanged(value);
200+
}
201+
202+
void SlidersGroup::onAmbientPChanged(int value)
203+
{
204+
ambientP = (float)value * 0.01f;
205+
emit ambientPChanged(value);
206+
}
207+
208+
void SlidersGroup::onDiffusePChanged(int value)
209+
{
210+
diffuseP = (float)value * 0.01f;
211+
emit diffusePChanged(value);
212+
}
213+
214+
void SlidersGroup::onSpecularPChanged(int value)
185215
{
186216
specular = (float)value * 0.01f;
187217
emit specularChanged(value);

src/App/SliderGroup.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ class SlidersGroup : public QGroupBox
2020
float ambient = 1.0f;
2121
float diffuse = 1.0f;
2222
float specular = 1.0f;
23+
24+
float ambientP = 1.0f;
25+
float diffuseP = 1.0f;
26+
float specularP = 1.0f;
27+
2328
float morph = 0.0f;
29+
float circleRadius = 1.0f;
2430
QVector3D directionalLightColor = QVector3D(0.5f, 0.5f, 0.5f);
2531
QVector3D projectionLightColor = QVector3D(0.5f, 0.5f, 0.5f);
2632

@@ -41,18 +47,25 @@ class SlidersGroup : public QGroupBox
4147
void ambientChanged(int value);
4248
void diffuseChanged(int value);
4349
void specularChanged(int value);
50+
void ambientPChanged(int value);
51+
void diffusePChanged(int value);
52+
void specularPChanged(int value);
4453
void colorDirButtonClicked(const QVector3D & value);
4554
void colorProjButtonClicked(const QVector3D & value);
4655
void hasDirectionalClicked(bool value);
4756
void hasProjectionClicked(bool value);
4857
void cutOffClicked(int value);
4958
void outerCutOffClicked(int value);
5059
void morphChanged(int value);
60+
void radiusChanged(int value);
5161

5262
private slots:
5363
void onAmbientChanged(int value);
5464
void onDiffuseChanged(int value);
5565
void onSpecularChanged(int value);
66+
void onAmbientPChanged(int value);
67+
void onDiffusePChanged(int value);
68+
void onSpecularPChanged(int value);
5669
void onColorDirButtonClicked();
5770
void onColorProjButtonClicked();
5871

@@ -64,6 +77,8 @@ private slots:
6477
void onCutOffClicked(int value);
6578
void onOuterCutOffClicked(int value);
6679

80+
void onRadiusChanged(int value);
81+
6782
private:
6883
void createSliders();
6984
void setupLayout();
@@ -84,6 +99,12 @@ private slots:
8499
QSlider * diffuse_;
85100
QSlider * specular_;
86101
QSlider * morph_;
102+
103+
QSlider * ambientP_;
104+
QSlider * diffuseP_;
105+
QSlider * specularP_;
106+
QSlider * circleRadius_;
107+
87108
QPushButton * directionalLightColor_;
88109
QPushButton * projectionLightColor_;
89110
Vector3DInputWidget * directionalLightPosition_;
@@ -97,7 +118,6 @@ private slots:
97118
QCheckBox * hasProjection_;
98119

99120
// layouts
100-
QGroupBox * lightGroup = new QGroupBox("Light Parameters");
101121
QGroupBox * directionGroup = new QGroupBox("Direction Light Parameters");
102122
QGroupBox * projectionGroup = new QGroupBox("Projection Light Parameters");
103123
QGroupBox * morphGroup = new QGroupBox("Morph Parameters");

src/App/Window.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <QOpenGLShaderProgram>
1111
#include <QScreen>
1212
#include <QVBoxLayout>
13-
13+
#include <iostream>
1414
#include <QMatrix4x4>
1515
#include <QOpenGLContext>
1616

@@ -88,9 +88,9 @@ void Window::onInit()
8888
sceneRenderer->onInit(this);
8989
// Camera
9090
sceneRenderer->camera = new Camera();
91-
sceneRenderer->camera->position().setX(0);
92-
sceneRenderer->camera->position().setY(0);
93-
sceneRenderer->camera->position().setZ(1);
91+
sceneRenderer->camera->position().setX(0.0415709);
92+
sceneRenderer->camera->position().setY(-0.0718041);
93+
sceneRenderer->camera->position().setZ(20);
9494
changeCameraPerspective((float)width(), (float)height());
9595
}
9696

0 commit comments

Comments
 (0)