Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Bunin, Matvii
PGR_project
Commits
c1c62f6c
Commit
c1c62f6c
authored
May 18, 2021
by
Bunin, Matvii
Browse files
animator and skybox fixed. screenshots
parent
23ba4b67
Changes
30
Hide whitespace changes
Inline
Side-by-side
MyEngine/MyEngine.vcxproj
View file @
c1c62f6c
...
...
@@ -179,11 +179,9 @@
<ClInclude
Include=
"util.h"
/>
</ItemGroup>
<ItemGroup>
<None
Include=
"anim.vert"
/>
<None
Include=
"textured.frag"
/>
<None
Include=
"textured.vert"
/>
<None
Include=
"uniform.frag"
/>
<None
Include=
"uniform.vert"
/>
<None
Include=
"shaders\anim.vert"
/>
<None
Include=
"shaders\phong.frag"
/>
<None
Include=
"shaders\phong.vert"
/>
</ItemGroup>
<Import
Project=
"$(VCTargetsPath)\Microsoft.Cpp.targets"
/>
<ImportGroup
Label=
"ExtensionTargets"
>
...
...
MyEngine/MyEngine.vcxproj.filters
View file @
c1c62f6c
...
...
@@ -88,19 +88,13 @@
</ClInclude>
</ItemGroup>
<ItemGroup>
<None
Include=
"
uniform.vert
"
>
<None
Include=
"
shaders\phong.frag
"
>
<Filter>
Shaders
</Filter>
</None>
<None
Include=
"
uniform.frag
"
>
<None
Include=
"
shaders\phong.vert
"
>
<Filter>
Shaders
</Filter>
</None>
<None
Include=
"textured.frag"
>
<Filter>
Shaders
</Filter>
</None>
<None
Include=
"textured.vert"
>
<Filter>
Shaders
</Filter>
</None>
<None
Include=
"anim.vert"
>
<None
Include=
"shaders\anim.vert"
>
<Filter>
Shaders
</Filter>
</None>
</ItemGroup>
...
...
MyEngine/camera.cpp
View file @
c1c62f6c
...
...
@@ -21,7 +21,8 @@ glm::mat4 EulerCamera::getView() {
float
y
=
glm
::
radians
(
yaw
);
float
p
=
glm
::
radians
(
pitch
);
glm
::
vec3
translation
=
node
->
transform
*
glm
::
vec4
(
0.0
f
,
0.0
f
,
0.0
f
,
1.0
f
);
glm
::
vec3
center
=
translation
-
glm
::
vec3
(
glm
::
sin
(
y
)
*
glm
::
cos
(
p
),
-
glm
::
sin
(
p
),
glm
::
cos
(
p
)
*
glm
::
cos
(
y
));
glm
::
vec3
center
=
translation
+
glm
::
vec3
(
glm
::
rotate
(
glm
::
mat4
(
1.
f
),
3.5
f
*
glm
::
half_pi
<
float
>
(),
glm
::
vec3
(
0.
f
,
1.
f
,
0.
f
))
*
((
node
->
transform
[
0
])
+
(
node
->
transform
[
2
])));
//glm::vec3(glm::sin(y) * glm::cos(p), -glm::sin(p), glm::cos(p) * glm::cos(y));
glm
::
vec3
up
=
glm
::
vec3
(
glm
::
sin
(
y
)
*
glm
::
sin
(
p
),
glm
::
cos
(
p
),
glm
::
sin
(
p
)
*
glm
::
cos
(
y
));
return
glm
::
lookAt
(
translation
,
center
,
up
);
}
...
...
MyEngine/camera.h
View file @
c1c62f6c
...
...
@@ -42,6 +42,10 @@ struct EulerCamera : Camera {
glm
::
mat3
getLinBase
()
override
;
glm
::
mat4
getView
()
override
;
void
moveCamSpace
(
glm
::
vec3
delta
)
override
{}
void
updateTransform
()
override
{}
};
struct
OrbitCamera
:
EulerCamera
{
...
...
MyEngine/character_animator.h
View file @
c1c62f6c
...
...
@@ -31,11 +31,6 @@ public:
for
(
const
auto
&
obj
:
collisionObjects
)
{
collVec
+=
obj
.
getCollisionVec
(
characterObject
,
testedNode
);
}
float
len
=
glm
::
length
(
collVec
);
if
(
len
>
0
)
{
collVec
/=
len
;
}
glm
::
vec3
moveVec
=
(
dir
-
collVec
)
*
speed
;
if
(
endlessMode
)
{
...
...
@@ -72,6 +67,14 @@ public:
movedNode
->
setLocalPos
(
npos
);
}
void
startWalking
()
{
characterObject
.
animationPaused
=
false
;
}
void
stopWalking
()
{
characterObject
.
animationPaused
=
true
;
}
void
turnLeft
(
float
speed
)
{
glm
::
vec3
movedY
=
glm
::
normalize
(
glm
::
vec3
(
movedNode
->
transform
[
1
]));
movedNode
->
transformLocal
=
glm
::
rotate
(
movedNode
->
transformLocal
,
glm
::
half_pi
<
float
>
()
*
speed
,
movedY
);
...
...
MyEngine/flat_tex.vert
deleted
100644 → 0
View file @
23ba4b67
MyEngine/geometry.cpp
View file @
c1c62f6c
...
...
@@ -143,7 +143,7 @@ glm::vec2 cubeUV(glm::vec3 pos, glm::vec3& norm, const glm::vec2 uvs[3]){
}
GeometryObject
<
Vertex
>*
GeometryObject
<
Vertex
>::
makeCube
()
{
auto
cube
=
new
GeometryObject
<
Vertex
>
(
"cube"
);
auto
cube
=
new
GeometryObject
<
Vertex
>
();
struct
VertexData
{
glm
::
vec3
pos
;
glm
::
vec2
uvs
[
3
];
...
...
@@ -226,11 +226,10 @@ GeometryObject<Vertex>* GeometryObject<Vertex>::makeTorus(float radius, float ri
torus
->
indices
.
push_back
(
v3
);
}
}
torus
->
material
.
diffuseTexture
=
std
::
make_unique
<
Texture
>
(
"metal-texture.jpg"
);
return
torus
;
}
GeometryObject
<
Vertex
>*
GeometryObject
<
Vertex
>::
makePlane
(
int
xTiles
,
int
yTiles
,
float
tileSide
,
glm
::
vec2
uvScale
)
{
GeometryObject
<
Vertex
>*
GeometryObject
<
Vertex
>::
makePlane
(
int
xTiles
,
int
yTiles
,
float
tileSide
,
glm
::
vec2
uvScale
,
glm
::
vec2
uvOffset
)
{
auto
*
plane
=
new
GeometryObject
;
float
midX
=
xTiles
*
tileSide
*
0.5
;
float
midY
=
yTiles
*
tileSide
*
0.5
;
...
...
@@ -256,7 +255,7 @@ GeometryObject<Vertex>* GeometryObject<Vertex>::makePlane(int xTiles, int yTiles
{
pos
,
glm
::
vec3
(
0.0
f
,
1.0
f
,
0.0
f
),
glm
::
vec3
(
1.0
f
,
0.0
f
,
0.0
f
),
vert
.
uv
*
uvScale
});
uvOffset
+
vert
.
uv
*
uvScale
});
}
auto
indOffset
=
verts
.
size
()
*
(
i
*
yTiles
+
j
);
for
(
auto
ind
:
inds
)
{
...
...
@@ -269,13 +268,9 @@ GeometryObject<Vertex>* GeometryObject<Vertex>::makePlane(int xTiles, int yTiles
GeometryObject
<
PGRVertex
>*
GeometryObject
<
PGRVertex
>::
loadWizard
()
{
auto
*
geom
=
new
GeometryObject
<
PGRVertex
>
();
struct
frame
{
const
int
nvert
;
const
int
ntriag
;
const
unsigned
*
indices
;
};
std
::
vector
<
const
float
*>
frames
=
{
bodyVertices
,
body_001Vertices
,
body_002Vertices
,
body_003Vertices
,
body_004Vertices
,
body_005Vertices
,
bodyVertices
bodyVertices
,
body_001Vertices
,
body_002Vertices
,
body_003Vertices
,
body_004Vertices
,
body_005Vertices
,
bodyVertices
,
body_001Vertices
};
geom
->
vertices
.
resize
(
bodyNVertices
*
frames
.
size
());
for
(
size_t
i
=
0
;
i
<
frames
.
size
();
++
i
)
{
...
...
MyEngine/geometry.h
View file @
c1c62f6c
...
...
@@ -88,7 +88,8 @@ struct GeometryObject {
static
GeometryObject
*
makeTorus
(
float
radius
,
float
ringRadius
,
int
uSteps
,
int
vSteps
);
static
GeometryObject
*
makePlane
(
int
xTiles
,
int
yTiles
,
float
tileSide
,
glm
::
vec2
uvScale
=
glm
::
vec2
(
1.
f
,
1.
f
));
static
GeometryObject
*
makePlane
(
int
xTiles
,
int
yTiles
,
float
tileSide
,
glm
::
vec2
uvScale
=
glm
::
vec2
(
1.
f
,
1.
f
),
glm
::
vec2
uvOffset
=
glm
::
vec2
(
0.
f
,
0.
f
));
static
GeometryObject
<
PGRVertex
>*
loadWizard
();
...
...
MyEngine/main.cpp
View file @
c1c62f6c
...
...
@@ -93,26 +93,41 @@ class App {
auto
&
cam
=
instance
->
render
.
camera
;
bool
fast
=
glfwGetKey
(
window
,
GLFW_KEY_LEFT_CONTROL
)
==
GLFW_PRESS
;
float
speed
=
fast
?
0.5
f
:
0.05
f
;
bool
moving
=
true
;
if
(
glfwGetKey
(
window
,
GLFW_KEY_A
)
==
GLFW_PRESS
||
glfwGetKey
(
window
,
GLFW_KEY_LEFT
)
==
GLFW_PRESS
)
{
instance
->
render
.
characterAnimator
->
turnLeft
(
0.03
f
);
}
if
(
glfwGetKey
(
window
,
GLFW_KEY_D
)
==
GLFW_PRESS
else
if
(
glfwGetKey
(
window
,
GLFW_KEY_D
)
==
GLFW_PRESS
||
glfwGetKey
(
window
,
GLFW_KEY_RIGHT
)
==
GLFW_PRESS
)
{
instance
->
render
.
characterAnimator
->
turnRight
(
0.03
f
);
}
float
speed
=
fast
?
0.5
f
:
0.05
f
;
if
(
glfwGetKey
(
window
,
GLFW_KEY_W
)
==
GLFW_PRESS
else
if
(
glfwGetKey
(
window
,
GLFW_KEY_W
)
==
GLFW_PRESS
||
glfwGetKey
(
window
,
GLFW_KEY_UP
)
==
GLFW_PRESS
)
{
instance
->
render
.
characterAnimator
->
move
(
glm
::
vec3
(
0.
f
,
0.
f
,
1.
f
),
speed
);
}
if
(
glfwGetKey
(
window
,
GLFW_KEY_S
)
==
GLFW_PRESS
else
if
(
glfwGetKey
(
window
,
GLFW_KEY_S
)
==
GLFW_PRESS
||
glfwGetKey
(
window
,
GLFW_KEY_DOWN
)
==
GLFW_PRESS
)
{
instance
->
render
.
characterAnimator
->
move
(
glm
::
vec3
(
0.
f
,
0.
f
,
-
1.
f
),
speed
);
}
else
{
moving
=
false
;
instance
->
render
.
characterAnimator
->
stopWalking
();
}
if
(
moving
)
{
instance
->
render
.
characterAnimator
->
startWalking
();
}
if
(
glfwGetKey
(
window
,
GLFW_KEY_SPACE
)
==
GLFW_PRESS
)
{
instance
->
render
.
characterAnimator
->
move
(
glm
::
vec3
(
0.
f
,
1.
f
,
0.
f
),
0.5
f
);
if
(
moving
)
{
instance
->
render
.
characterAnimator
->
move
(
glm
::
vec3
(
0.
f
,
1.
f
,
0.
f
),
0.5
f
);
}
}
if
(
glfwGetKey
(
window
,
GLFW_KEY_F1
)
==
GLFW_PRESS
)
{
instance
->
render
.
useFPSCam
=
false
;
}
if
(
glfwGetKey
(
window
,
GLFW_KEY_F2
)
==
GLFW_PRESS
)
{
instance
->
render
.
useFPSCam
=
true
;
}
}
...
...
MyEngine/render.cpp
View file @
c1c62f6c
...
...
@@ -50,7 +50,7 @@ void Render::draw() {
bindLightsUBO
();
}
glm
::
vec3
camPos
=
-
camera
->
getView
()[
3
];
glm
::
vec3
camPos
=
glm
::
inverse
(
camera
->
getView
()
)
[
3
];
std
::
vector
<
RenderObject
*>
rosSorted
;
for
(
auto
&
obj
:
renderObjects
)
{
...
...
@@ -64,31 +64,27 @@ void Render::draw() {
if
(
!
a
->
transparent
)
{
return
true
;
}
if
(
camPos
.
y
>
0
)
{
if
(
a
->
id
==
plId
)
{
return
true
;
}
if
(
b
->
id
==
plId
)
{
return
false
;
}
}
else
{
if
(
a
->
id
==
plId
)
{
return
false
;
}
if
(
b
->
id
==
plId
)
{
return
true
;
}
}
glm
::
vec3
apos
=
a
->
nodes
[
0
]
->
getGlobalPos
();
glm
::
vec3
bpos
=
b
->
nodes
[
0
]
->
getGlobalPos
();
float
adist
=
glm
::
length
(
camPos
-
apos
);
float
bdist
=
glm
::
length
(
camPos
-
bpos
);
return
adist
>
bdist
;
return
adist
>
bdist
;
});
for
(
auto
*
obj
:
rosSorted
)
{
obj
->
render
(
*
camera
,
lightsUBO
,
fogTexture
,
windowExtent
,
frameInd
,
frameTime
/
animFramePeriodSec
);
obj
->
render
(
useFPSCam
?*
fpsCamera
:
*
camera
,
lightsUBO
,
fogTexture
,
windowExtent
,
frameInd
,
frameTime
/
animFramePeriodSec
);
}
if
(
frameTime
>
animFramePeriodSec
)
{
...
...
MyEngine/render.h
View file @
c1c62f6c
...
...
@@ -9,7 +9,7 @@
class
Render
{
ShaderProgram
tex
Shader
;
ShaderProgram
phong
Shader
;
ShaderProgram
colorShader
;
ShaderProgram
animShader
;
...
...
@@ -40,9 +40,13 @@ class Render
public:
bool
useFPSCam
=
false
;
glm
::
vec2
windowExtent
;
std
::
unique_ptr
<
Camera
>
camera
;
std
::
unique_ptr
<
Camera
>
fpsCamera
;
std
::
unique_ptr
<
CharacterAnimator
>
characterAnimator
;
...
...
@@ -124,9 +128,11 @@ public:
auto
&
camNode
=
movedNode
.
addChild
();
auto
&
fpsCamNode
=
movedNode
.
addChild
();
fpsCamNode
.
transformLocal
=
glm
::
translate
(
fpsCamNode
.
transformLocal
,
glm
::
vec3
(
0.
f
,
1.
f
,
0.
f
));
auto
&
skyboxNode
=
camNode
.
addChild
();
skyboxNode
.
transformLocal
=
glm
::
scale
(
glm
::
mat4
(
1.0
f
),
glm
::
vec3
(
200.
f
));
//skyboxNode.transformLocal = glm::rotate(skyboxNode.transformLocal, -glm::pi<float>(), glm::vec3(1.0f, 0.0f, 0.0f));
skyboxNode
.
cancelParentRotation
=
true
;
auto
&
sunNode
=
camNode
.
addChild
();
...
...
@@ -136,24 +142,44 @@ public:
sunNode
.
transformLocal
=
glm
::
scale
(
sunNode
.
transformLocal
,
glm
::
vec3
(
2.5
f
,
2.
f
,
2.
f
));
auto
&
buddhaNode
=
worldMovedNode
->
addChild
();
buddhaNode
.
transformLocal
=
glm
::
translate
(
buddhaNode
.
transformLocal
,
glm
::
vec3
(
0.
f
,
1.
f
,
5
.
f
));
buddhaNode
.
transformLocal
=
glm
::
translate
(
buddhaNode
.
transformLocal
,
glm
::
vec3
(
0.
f
,
1.
f
,
10
.
f
));
buddhaNode
.
transformLocal
=
glm
::
scale
(
buddhaNode
.
transformLocal
,
glm
::
vec3
(
2.
f
,
2.
f
,
2.
f
));
auto
&
textNode
=
buddhaNode
.
addChild
();
//ufoAnimNodes[0]->addChild();
auto
&
textNode
=
buddhaNode
.
addChild
();
textNode
.
transformLocal
=
glm
::
translate
(
textNode
.
transformLocal
,
glm
::
vec3
(
-
5.5
f
,
1.0
f
,
0.
f
));
textNode
.
transformLocal
=
glm
::
rotate
(
textNode
.
transformLocal
,
glm
::
half_pi
<
float
>
()
*
3
,
glm
::
vec3
(
1.
f
,
0.
f
,
0.
f
));
textNode
.
transformLocal
=
glm
::
rotate
(
textNode
.
transformLocal
,
glm
::
pi
<
float
>
(),
glm
::
vec3
(
0.
f
,
0.
f
,
1.
f
));
textNode
.
transformLocal
=
glm
::
scale
(
textNode
.
transformLocal
,
glm
::
vec3
(
3.
f
,
0.1
f
,
0.3
f
)
*
0.5
f
);
// skybox planes nodes
auto
&
nd_sx
=
skyboxNode
.
addChild
();
nd_sx
.
transformLocal
=
glm
::
rotate
(
nd_sx
.
transformLocal
,
-
glm
::
half_pi
<
float
>
(),
glm
::
vec3
(
1.
f
,
0.
f
,
0.
f
));
nd_sx
.
transformLocal
=
glm
::
translate
(
nd_sx
.
transformLocal
,
glm
::
vec3
(
0.
f
,
1.
f
,
0.
f
));
auto
&
nd_smz
=
nd_sx
.
addChild
();
nd_smz
.
transformLocal
=
glm
::
rotate
(
nd_smz
.
transformLocal
,
glm
::
half_pi
<
float
>
(),
glm
::
vec3
(
0.
f
,
0.
f
,
1.
f
));
nd_smz
.
transformLocal
=
glm
::
translate
(
nd_smz
.
transformLocal
,
glm
::
vec3
(
-
1.
f
,
1.
f
,
0.
f
));
auto
&
nd_sz
=
nd_sx
.
addChild
();
nd_sz
.
transformLocal
=
glm
::
rotate
(
nd_sz
.
transformLocal
,
-
glm
::
half_pi
<
float
>
(),
glm
::
vec3
(
0.
f
,
0.
f
,
1.
f
));
nd_sz
.
transformLocal
=
glm
::
translate
(
nd_sz
.
transformLocal
,
glm
::
vec3
(
1.
f
,
1.
f
,
0.
f
));
auto
&
nd_sy
=
nd_sx
.
addChild
();
nd_sy
.
transformLocal
=
glm
::
rotate
(
nd_sy
.
transformLocal
,
glm
::
half_pi
<
float
>
(),
glm
::
vec3
(
1.
f
,
0.
f
,
0.
f
));
nd_sy
.
transformLocal
=
glm
::
translate
(
nd_sy
.
transformLocal
,
glm
::
vec3
(
0.
f
,
1.
f
,
1.
f
));
auto
&
nd_smx
=
nd_sz
.
addChild
();
nd_smx
.
transformLocal
=
glm
::
rotate
(
nd_smx
.
transformLocal
,
-
glm
::
half_pi
<
float
>
(),
glm
::
vec3
(
0.
f
,
0.
f
,
1.
f
));
nd_smx
.
transformLocal
=
glm
::
translate
(
nd_smx
.
transformLocal
,
glm
::
vec3
(
1.
f
,
1.
f
,
0.
f
));
auto
&
nd_smy
=
nd_sx
.
addChild
();
nd_smy
.
transformLocal
=
glm
::
rotate
(
nd_smy
.
transformLocal
,
-
glm
::
half_pi
<
float
>
(),
glm
::
vec3
(
1.
f
,
0.
f
,
0.
f
));
nd_smy
.
transformLocal
=
glm
::
translate
(
nd_smy
.
transformLocal
,
glm
::
vec3
(
0.
f
,
1.
f
,
-
1.
f
));
// GEOMETRIES ----------------------------------
GeometryObject
<
Vertex
>
geometryBuddha
(
"buddha"
,
true
);
GeometryObject
<
Vertex
>
geomTrashCan
(
"trash_can"
);
GeometryObject
<
Vertex
>
geometrySphere
(
"
spher
e"
);
geometrySphere
.
material
.
diffuseTexture
=
std
::
make_unique
<
Texture
>
(
"textures/
sky
map.p
n
g"
);
GeometryObject
<
Vertex
>
geometrySphere
(
"
cub
e"
);
geometrySphere
.
material
.
diffuseTexture
=
std
::
make_unique
<
Texture
>
(
"textures/
cube
map.
j
pg"
);
auto
&
geometryTorus
=
*
GeometryObject
<
Vertex
>::
makeTorus
(
0.4
f
,
0.2
f
,
40
,
30
);
geometryTorus
.
material
.
diffuseTexture
=
std
::
make_unique
<
Texture
>
(
"textures/metal-texture.jpg"
);
//auto& geometryPlane = *GeometryObject<Vertex>::makePlane(150, 150, 2.f);
auto
&
geometryPlane
=
*
GeometryObject
<
Vertex
>::
makePlane
(
1
,
1
,
300.
f
,
glm
::
vec2
(
100.
f
,
100.0
f
));
geometryPlane
.
material
.
params
.
emissive
=
glm
::
vec4
(
0.1
,
0.1
,
0.0
,
1.0
f
);
...
...
@@ -169,24 +195,70 @@ public:
text
<<
"PLEASE DON`T PANIC"
<<
std
::
endl
;
geomText
.
material
.
diffuseTexture
=
std
::
unique_ptr
<
Texture
>
(
Texture
::
makeText
(
text
,
500
,
50
));
//skybox planes
/*Texture skyboxTex("textures/cubemap.jpg");
auto& sy = *GeometryObject<Vertex>::makePlane(1, 1, 2, { 1.f, 1.f }, {0.25f, 0.f}); //{ 0.33f, 0.25f }, { 0.25f, 0.f }
sy.material.diffuseTexture = std::make_unique<Texture>("textures/cubemap.jpg");
auto& smz = *GeometryObject<Vertex>::makePlane(1, 1, 2, { 0.25f, 0.33f }, { 0.f, 0.33f });
smz.material.diffuseTexture = std::make_unique<Texture>(skyboxTex);
auto& sx = *GeometryObject<Vertex>::makePlane(1, 1, 2, { 0.25f, 0.33f }, { 0.25f, 0.33f });
sx.material.diffuseTexture = std::make_unique<Texture>(skyboxTex);
auto& sz = *GeometryObject<Vertex>::makePlane(1, 1, 2, { 0.25f, 0.33f }, { 0.5f, 0.33f });
sz.material.diffuseTexture = std::make_unique<Texture>(skyboxTex);
auto& smx = *GeometryObject<Vertex>::makePlane(1, 1, 2, { 0.25f, 0.33f }, { 0.75f, 0.33f });
smx.material.diffuseTexture = std::make_unique<Texture>(skyboxTex);
auto& smy = *GeometryObject<Vertex>::makePlane(1, 1, 2, { 0.25f, 0.33f }, { 0.25f, 0.66f });
smy.material.diffuseTexture = std::make_unique<Texture>(skyboxTex);*/
auto
&
sy
=
*
GeometryObject
<
Vertex
>::
makePlane
(
1
,
1
,
2
);
sy
.
material
.
diffuseTexture
=
std
::
make_unique
<
Texture
>
(
"textures/cubemap_y.jpg"
);
auto
&
smz
=
*
GeometryObject
<
Vertex
>::
makePlane
(
1
,
1
,
2
);
smz
.
material
.
diffuseTexture
=
std
::
make_unique
<
Texture
>
(
"textures/cubemap_-z.jpg"
);
auto
&
sx
=
*
GeometryObject
<
Vertex
>::
makePlane
(
1
,
1
,
2
);
sx
.
material
.
diffuseTexture
=
std
::
make_unique
<
Texture
>
(
"textures/cubemap_x.jpg"
);
auto
&
sz
=
*
GeometryObject
<
Vertex
>::
makePlane
(
1
,
1
,
2
);
sz
.
material
.
diffuseTexture
=
std
::
make_unique
<
Texture
>
(
"textures/cubemap_z.jpg"
);
auto
&
smx
=
*
GeometryObject
<
Vertex
>::
makePlane
(
1
,
1
,
2
);
smx
.
material
.
diffuseTexture
=
std
::
make_unique
<
Texture
>
(
"textures/cubemap_-x.jpg"
);
auto
&
smy
=
*
GeometryObject
<
Vertex
>::
makePlane
(
1
,
1
,
2
);
smy
.
material
.
diffuseTexture
=
std
::
make_unique
<
Texture
>
(
"textures/cubemap_-y.jpg"
);
// SHADERS -------------------------------------
tex
Shader
=
ShaderProgram
(
"
textured.vert"
,
"textured
.frag"
);
tex
Shader
.
setBinding
(
tex
Shader
.
uniformBlock
(
"LightSourcesData"
),
0
);
animShader
=
ShaderProgram
(
"anim.vert"
,
"
textured
.frag"
);
phong
Shader
=
ShaderProgram
(
"
shaders/phong.vert"
,
"shaders/phong
.frag"
);
phong
Shader
.
setBinding
(
phong
Shader
.
uniformBlock
(
"LightSourcesData"
),
0
);
animShader
=
ShaderProgram
(
"
shaders/
anim.vert"
,
"
shaders/phong
.frag"
);
animShader
.
setBinding
(
animShader
.
uniformBlock
(
"LightSourcesData"
),
0
);
glGenBuffers
(
1
,
&
lightsUBO
);
// RENDER OBJECTS ----------------------------
auto
&
roBuddha
=
renderObjects
.
emplace_back
(
geometryBuddha
,
texShader
);
auto
&
ro_sy
=
renderObjects
.
emplace_back
(
sy
,
phongShader
);
ro_sy
.
lighted
=
false
;
ro_sy
.
nodes
.
push_back
(
&
nd_sy
);
auto
&
ro_smz
=
renderObjects
.
emplace_back
(
smz
,
phongShader
);
ro_smz
.
lighted
=
false
;
ro_smz
.
nodes
.
push_back
(
&
nd_smz
);
auto
&
ro_sx
=
renderObjects
.
emplace_back
(
sx
,
phongShader
);
ro_sx
.
lighted
=
false
;
ro_sx
.
nodes
.
push_back
(
&
nd_sx
);
auto
&
ro_sz
=
renderObjects
.
emplace_back
(
sz
,
phongShader
);
ro_sz
.
lighted
=
false
;
ro_sz
.
nodes
.
push_back
(
&
nd_sz
);
auto
&
ro_smx
=
renderObjects
.
emplace_back
(
smx
,
phongShader
);
ro_smx
.
lighted
=
false
;
ro_smx
.
nodes
.
push_back
(
&
nd_smx
);
auto
&
ro_smy
=
renderObjects
.
emplace_back
(
smy
,
phongShader
);
ro_smy
.
lighted
=
false
;
ro_smy
.
nodes
.
push_back
(
&
nd_smy
);
auto
&
roBuddha
=
renderObjects
.
emplace_back
(
geometryBuddha
,
phongShader
);
roBuddha
.
nodes
.
push_back
(
&
buddhaNode
);
auto
&
trashCan
=
renderObjects
.
emplace_back
(
geomTrashCan
,
texShader
);
auto
&
roSphere
=
renderObjects
.
emplace_back
(
geometrySphere
,
texShader
);
auto
&
roTorus
=
renderObjects
.
emplace_back
(
geometryTorus
,
texShader
);
auto
&
trashCan
=
renderObjects
.
emplace_back
(
geomTrashCan
,
phongShader
);
auto
&
roTorus
=
renderObjects
.
emplace_back
(
geometryTorus
,
phongShader
);
auto
&
roPlane
=
renderObjects
.
emplace_back
(
geometryPlane
,
tex
Shader
);
auto
&
roPlane
=
renderObjects
.
emplace_back
(
geometryPlane
,
phong
Shader
);
roPlane
.
boundSphereRadius
=
0.
f
;
roPlane
.
transparent
=
true
;
roPlane
.
nodes
.
push_back
(
sceneRoot
.
get
());
...
...
@@ -194,16 +266,15 @@ public:
auto
&
roWizard
=
renderObjects
.
emplace_back
(
wizard
,
animShader
);
auto
&
roSun
=
renderObjects
.
emplace_back
(
geomSun
,
tex
Shader
);
auto
&
roSun
=
renderObjects
.
emplace_back
(
geomSun
,
phong
Shader
);
roSun
.
lighted
=
false
;
roSun
.
uvOffset
=
glm
::
vec2
(
0.2
f
,
0.
f
);
roSun
.
numTexFrames
=
5
;
roSun
.
transparent
=
true
;
roSun
.
nodes
.
push_back
(
&
sunNode
);
auto
&
roText
=
renderObjects
.
emplace_back
(
geomText
,
tex
Shader
);
auto
&
roText
=
renderObjects
.
emplace_back
(
geomText
,
phong
Shader
);
roText
.
lighted
=
false
;
//roText.texCoordStep = glm::vec2(0.01f, 0.f);
roText
.
transparent
=
true
;
roText
.
nodes
.
push_back
(
&
textNode
);
...
...
@@ -214,10 +285,6 @@ public:
trashCan
.
nodes
.
insert
(
trashCan
.
nodes
.
end
(),
trashCanNodes
.
begin
(),
trashCanNodes
.
end
());
roSphere
.
nodes
.
push_back
(
&
skyboxNode
);
roSphere
.
lighted
=
false
;
roSphere
.
collisionDisabled
=
true
;
roWizard
.
nodes
.
push_back
(
&
wizardNode
);
//---------------------------------------------
...
...
@@ -230,6 +297,12 @@ public:
orbitCam
.
pitch
=
-
30
;
camera
=
std
::
make_unique
<
OrbitCamera
>
(
orbitCam
);
EulerCamera
eulerCam
;
eulerCam
.
node
=
&
fpsCamNode
;
eulerCam
.
far
=
1000.
f
;
eulerCam
.
yaw
=
180
;
fpsCamera
=
std
::
make_unique
<
EulerCamera
>
(
eulerCam
);
auto
&
wizardLightNode
=
movedNode
.
addChild
();
wizardLightNode
.
transformLocal
=
glm
::
translate
(
glm
::
mat4
(
1.0
f
),
glm
::
vec3
(
0.
f
,
3.
f
,
0.
f
));
auto
&
wizardLightNode1
=
movedNode
.
addChild
();
...
...
@@ -243,7 +316,7 @@ public:
col1
.
specular
=
glm
::
vec4
(
.1
f
);
col1
.
ambient
=
glm
::
vec4
(
.01
f
);
LightColor
col2
;
col2
.
diffuse
=
glm
::
vec4
(
.2
f
,
.9
f
,
.0
f
,
1.
f
);
//
col2.diffuse = glm::vec4(.2f, .9f, .0f, 1.f);
LightColor
col3
;
col3
.
diffuse
=
glm
::
vec4
(
.0
f
,
.0
f
,
1.
f
,
1.
f
);
auto
&
dirLight
=
lightSources
.
emplace_back
(
new
DirectionalLight
(
col1
));
...
...
MyEngine/render_object.cpp
View file @
c1c62f6c
...
...
@@ -76,15 +76,25 @@ void RenderObject::fillElementArrays(const GeometryObject<VertexT>& geom) {
if
(
numFrames
>
1
)
{
frameOffset
=
(
geom
.
vertices
.
size
()
/
numFrames
);
GLint
next
_pos_l
oc
=
3
;
glEnableVertexAttribArray
(
next
_pos_l
oc
);
glVertexAttribPointer
(
next
_pos_l
oc
,
3
,
GL_FLOAT
,
GL_FALSE
,
sizeof
(
VertexT
),
GLint
next
PosL
oc
=
3
;
glEnableVertexAttribArray
(
next
PosL
oc
);
glVertexAttribPointer
(
next
PosL
oc
,
3
,
GL_FLOAT
,
GL_FALSE
,
sizeof
(
VertexT
),
(
void
*
)(
frameOffset
*
sizeof
(
VertexT
)
+
offsetof
(
VertexT
,
pos
)));
GLint
next
_n
orm
_l
oc
=
4
;
glEnableVertexAttribArray
(
next
_n
orm
_l
oc
);
glVertexAttribPointer
(
next
_n
orm
_l
oc
,
3
,
GL_FLOAT
,
GL_FALSE
,
sizeof
(
VertexT
),
GLint
next
N
orm
L
oc
=
4
;
glEnableVertexAttribArray
(
next
N
orm
L
oc
);
glVertexAttribPointer
(
next
N
orm
L
oc
,
3
,
GL_FLOAT
,
GL_FALSE
,
sizeof
(
VertexT
),
(
void
*
)(
frameOffset
*
sizeof
(
VertexT
)
+
offsetof
(
VertexT
,
normal
)));
GLint
nextNextPosLoc
=
5
;
glEnableVertexAttribArray
(
nextNextPosLoc
);
glVertexAttribPointer
(
nextNextPosLoc
,
3
,
GL_FLOAT
,
GL_FALSE
,
sizeof
(
VertexT
),
(
void
*
)(
2
*
frameOffset
*
sizeof
(
VertexT
)
+
offsetof
(
VertexT
,
pos
)));
GLint
nextNextNormLoc
=
6
;
glEnableVertexAttribArray
(
nextNextNormLoc
);
glVertexAttribPointer
(
nextNextNormLoc
,
3
,
GL_FLOAT
,
GL_FALSE
,
sizeof
(
VertexT
),
(
void
*
)(
2
*
frameOffset
*
sizeof
(
VertexT
)
+
offsetof
(
VertexT
,
normal
)));
}
glBindVertexArray
(
0
);
...
...
@@ -111,7 +121,7 @@ void RenderObject::render(Camera& camera, GLuint lightsUBO, GLuint fogTexture, g
auto
view
=
camera
.
getView
();
glUniformMatrix4fv
(
shader
.
uniform
(
"transform.view"
),
1
,
GL_FALSE
,
glm
::
value_ptr
(
view
));
glUniformMatrix4fv
(
shader
.
uniform
(
"transform.projection"
),
1
,
GL_FALSE
,
glm
::
value_ptr
(
camera
.
getProj
()));
auto
viewer
=
-
glm
::
vec3
(
view
[
3
]);
auto
viewer
=
glm
::
vec3
(
glm
::
inverse
(
view
)
[
3
]);
glUniform3fv
(
shader
.
uniform
(
"viewer"
),
1
,
glm
::
value_ptr
(
viewer
));
glm
::
vec2
texOffset
=
glm
::
vec2
(
0.
f
);
...
...
@@ -146,8 +156,39 @@ void RenderObject::render(Camera& camera, GLuint lightsUBO, GLuint fogTexture, g
glUniform1i
(
shader
.
uniform
(
"fogTexture"
),
2
);
glBindVertexArray
(
vertexArray
);
static
int
offset
=
0
;
static
bool
first
=
true
;
if
(
animated
)
{
glDrawElementsBaseVertex
(
GL_TRIANGLES
,
numIndices
,
GL_UNSIGNED_INT
,
0
,
frameOffset
*
(
frameInd
%
(
numFrames
-
1
)));
// finish the animation before stopping it
uint32_t
animFrameId
=
std
::
max
(
frameInd
-
animStartFrameInd
+
offset
,
0
)
%
(
numFrames
-
2
);
bool
stopped
=
false
;
if
(
animationPaused
&&
animFrameId
==
0
)
{
animStartFrameInd
=
frameInd
+
1
;
stopped
=
true
;
offset
=
0
;
first
=
true
;
}
bool
useNextNext
=
false
;
if
(
!
animationPaused
)
{
if
(
animFrameId
==
numFrames
-
3
)
{
useNextNext
=
true
;
}
else
{
if
(
animFrameId
==
0
)
{
if
(
!
first
)
{
animFrameId
=
1
;
offset
+=
1
;
}
}
else
{
first
=
false
;
}
}
std
::
cout
<<
animFrameId
<<
std
::
endl
;
}
glUniform1i
(
shader
.
uniform
(
"stopped"
),
stopped
);
glUniform1i
(
shader
.
uniform
(
"useNextNext"
),
useNextNext
);
glDrawElementsBaseVertex
(
GL_TRIANGLES
,
numIndices
,
GL_UNSIGNED_INT
,
0
,
frameOffset
*
animFrameId
);
}
else
{
glDrawElements
(
GL_TRIANGLES
,
numIndices
,
GL_UNSIGNED_INT
,
0
);
...
...
@@ -165,7 +206,7 @@ glm::vec4 RenderObject::globalAmbient = glm::vec4(0.0);
glm
::
vec3
RenderObject
::
getCollisionVec
(
RenderObject
&
tested
,
SceneNode
*
testedNode
)
const
{
glm
::
vec3
colSum
=
glm
::
vec3
(
0.
f
);
if
(
id
==
tested
.
id
||
tested
.
collisionDisabled
||
collisionDisabled
)
{
if
(
id
==
tested
.
id
||
tested
.
collisionDisabled
||
collisionDisabled
||
testedNode
->
disabled
)
{
return
colSum
;
}
for
(
const
auto
&
node
:
nodes
)
{
...
...
MyEngine/render_object.h
View file @
c1c62f6c
...
...
@@ -19,6 +19,7 @@ class RenderObject {
ShaderProgram
shader
;
size_t
frameOffset
;
int
animStartFrameInd
=
0
;
public:
...
...
@@ -46,6 +47,8 @@ public:
int
numTexFrames
=
0
;
bool
animationPaused
=
true
;
static
glm
::
vec4
globalAmbient
;
RenderObject
(
const
GeometryObject
<
Vertex
>&
geom
,
const
ShaderProgram
&
shader
);
...
...
MyEngine/screenshots/screenshot1.png
0 → 100644
View file @
c1c62f6c
451 KB
MyEngine/screenshots/screenshot2.png
0 → 100644
View file @
c1c62f6c
435 KB
MyEngine/screenshots/screenshot3.png
0 → 100644
View file @
c1c62f6c
352 KB
MyEngine/anim.vert
→
MyEngine/
shaders/
anim.vert
View file @
c1c62f6c
...
...
@@ -7,6 +7,9 @@ layout(location = 2) in vec2 inTexCoord;
layout
(
location
=
3
)
in
vec3
posNext
;
layout
(
location
=
4
)
in
vec3
normalNext
;
layout
(
location
=
5
)
in
vec3
posNextNext
;
layout
(
location
=
6
)
in
vec3
normalNextNext
;
layout
(
location
=
0
)
out
vec2
texCoord
;
layout
(
location
=
1
)
out
vec3
fragNormal
;
layout
(
location
=
2
)
out
vec3
fragPos
;
...
...
@@ -21,12 +24,26 @@ uniform Transform transform;
uniform
float
mixT
;
uniform
bool
stopped
;
uniform
bool
useNextNext
;
void
main
(){
vec4
posInterp
=
vec4
(
mix
(
pos
,
posNext
,
mixT
),
1
.
0
f
);