Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
GraPa
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kai Westerkamp
GraPa
Commits
10e12c16
Commit
10e12c16
authored
Jan 26, 2016
by
Kai Westerkamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
start of Animation/mainwidget.cpp
parent
bcc29328
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
85 additions
and
18 deletions
+85
-18
mainwidget.cpp
A5/Animation/mainwidget.cpp
+4
-2
mainwidget.h
A5/Animation/mainwidget.h
+1
-0
mesh.cpp
A5/Animation/mesh.cpp
+74
-15
mesh.h
A5/Animation/mesh.h
+6
-1
No files found.
A5/Animation/mainwidget.cpp
View file @
10e12c16
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
MainWidget
::
MainWidget
()
MainWidget
::
MainWidget
()
{
{
startTime
=
QTime
::
currentTime
();
}
}
QSize
MainWidget
::
minimumSizeHint
()
const
QSize
MainWidget
::
minimumSizeHint
()
const
...
@@ -104,7 +104,9 @@ void MainWidget::paintGL(){
...
@@ -104,7 +104,9 @@ void MainWidget::paintGL(){
animationShader
->
setUniformValue
(
"colorTexture"
,
0
);
animationShader
->
setUniformValue
(
"colorTexture"
,
0
);
animationShader
->
setUniformValue
(
"LightPos"
,
QVector3D
(
0
,
100
,
100
));
animationShader
->
setUniformValue
(
"LightPos"
,
QVector3D
(
0
,
100
,
100
));
mesh
->
render
(
animationShader
,
m_view
*
rot
,
m_projection
);
time
=
startTime
.
msecsTo
(
QTime
::
currentTime
())
/
1000.0
;
mesh
->
render
(
animationShader
,
m_view
*
rot
,
m_projection
,(
float
)
time
);
animationShader
->
release
();
animationShader
->
release
();
update
();
update
();
...
...
A5/Animation/mainwidget.h
View file @
10e12c16
...
@@ -35,6 +35,7 @@ private:
...
@@ -35,6 +35,7 @@ private:
QOpenGLShaderProgram
*
animationShader
;
QOpenGLShaderProgram
*
animationShader
;
QMatrix4x4
m_projection
;
QMatrix4x4
m_projection
;
QMatrix4x4
m_view
;
QMatrix4x4
m_view
;
QTime
startTime
;
float
camDistance
;
float
camDistance
;
...
...
A5/Animation/mesh.cpp
View file @
10e12c16
...
@@ -284,8 +284,14 @@ void Mesh::updateBoneTransform(float TimeInSeconds){
...
@@ -284,8 +284,14 @@ void Mesh::updateBoneTransform(float TimeInSeconds){
if
(
!
scene
)
if
(
!
scene
)
return
;
return
;
const
aiAnimation
*
animation
=
scene
->
mAnimations
[
0
];
const
aiAnimation
*
animation
=
scene
->
mAnimations
[
0
];
float
TicksPerSecond
=
(
float
)(
animation
->
mTicksPerSecond
!=
0
?
animation
->
mTicksPerSecond
:
25.0
f
);
float
TimeInTicks
=
TimeInSeconds
*
TicksPerSecond
;
float
AnimationTime
=
fmod
(
TimeInTicks
,
(
float
)
animation
->
mDuration
);
//TODO calc time and get Anaimation;
//TODO calc time and get Anaimation;
updateBoneHeirachy
(
0.0
,
animation
,
this
->
rootNode
,
QMatrix4x4
());
updateBoneHeirachy
(
AnimationTime
,
animation
,
this
->
rootNode
,
QMatrix4x4
());
...
@@ -345,28 +351,81 @@ const aiNodeAnim* Mesh::findAnimOfNode(const aiAnimation* animation, QString Nod
...
@@ -345,28 +351,81 @@ const aiNodeAnim* Mesh::findAnimOfNode(const aiAnimation* animation, QString Nod
QVector3D
Mesh
::
calcInterpolatedScaling
(
float
AnimTime
,
const
aiNodeAnim
*
nodeAnimation
){
QVector3D
Mesh
::
calcInterpolatedScaling
(
float
AnimTime
,
const
aiNodeAnim
*
nodeAnimation
){
int
index
=
nodeAnimation
->
mNumScalingKeys
/
2
;
if
(
nodeAnimation
->
mNumScalingKeys
==
1
){
//index = 0;
return
convert
(
nodeAnimation
->
mScalingKeys
[
0
].
mValue
);
aiVector3D
scale
=
nodeAnimation
->
mScalingKeys
[
index
].
mValue
;
}
return
QVector3D
(
scale
.
x
,
scale
.
y
,
scale
.
z
);
//Index find
int
index
=
0
;
for
(
uint
i
=
0
;
i
<
nodeAnimation
->
mNumScalingKeys
-
1
;
i
++
)
{
if
(
AnimTime
<
(
float
)
nodeAnimation
->
mScalingKeys
[
i
+
1
].
mTime
)
{
index
=
i
;
break
;
}
}
float
DeltaTime
=
(
float
)(
nodeAnimation
->
mScalingKeys
[
index
+
1
].
mTime
-
nodeAnimation
->
mScalingKeys
[
index
].
mTime
);
float
Factor
=
(
AnimTime
-
(
float
)
nodeAnimation
->
mScalingKeys
[
index
].
mTime
)
/
DeltaTime
;
QVector3D
start
=
convert
(
nodeAnimation
->
mScalingKeys
[
index
].
mValue
);
QVector3D
end
=
convert
(
nodeAnimation
->
mScalingKeys
[
index
+
1
].
mValue
);
return
linInterpolate
(
start
,
end
,
Factor
);
}
}
QQuaternion
Mesh
::
calcInterpolatedRotation
(
float
AnimTime
,
const
aiNodeAnim
*
nodeAnimation
){
QQuaternion
Mesh
::
calcInterpolatedRotation
(
float
AnimTime
,
const
aiNodeAnim
*
nodeAnimation
){
int
index
=
nodeAnimation
->
mNumRotationKeys
/
2
;
if
(
nodeAnimation
->
mNumRotationKeys
==
1
){
// index = 0;
return
convert
(
nodeAnimation
->
mRotationKeys
[
0
].
mValue
);
aiQuaternion
quat
=
nodeAnimation
->
mRotationKeys
[
index
].
mValue
;
}
return
QQuaternion
(
quat
.
w
,
quat
.
x
,
quat
.
y
,
quat
.
z
);
//Index find
int
index
=
0
;
for
(
uint
i
=
0
;
i
<
nodeAnimation
->
mNumRotationKeys
-
1
;
i
++
)
{
if
(
AnimTime
<
(
float
)
nodeAnimation
->
mRotationKeys
[
i
+
1
].
mTime
)
{
index
=
i
;
break
;
}
}
float
DeltaTime
=
(
float
)(
nodeAnimation
->
mRotationKeys
[
index
+
1
].
mTime
-
nodeAnimation
->
mRotationKeys
[
index
].
mTime
);
float
Factor
=
(
AnimTime
-
(
float
)
nodeAnimation
->
mRotationKeys
[
index
].
mTime
)
/
DeltaTime
;
// qDebug()<<AnimTime<<DeltaTime<<Factor;
const
aiQuaternion
start
=
nodeAnimation
->
mRotationKeys
[
index
].
mValue
;
const
aiQuaternion
end
=
nodeAnimation
->
mRotationKeys
[
index
+
1
].
mValue
;
aiQuaternion
RotationQ
;
aiQuaternion
::
Interpolate
(
RotationQ
,
start
,
end
,
Factor
);
return
convert
(
RotationQ
);
//return convert(start);
}
}
QVector3D
Mesh
::
calcInterpolatedTranslation
(
float
AnimTime
,
const
aiNodeAnim
*
nodeAnimation
){
QVector3D
Mesh
::
calcInterpolatedTranslation
(
float
AnimTime
,
const
aiNodeAnim
*
nodeAnimation
){
int
index
=
nodeAnimation
->
mNumScalingKeys
/
2
;
if
(
nodeAnimation
->
mNumPositionKeys
==
1
){
// index = 0;
convert
(
nodeAnimation
->
mPositionKeys
[
0
].
mValue
);
aiVector3D
pos
=
nodeAnimation
->
mPositionKeys
[
index
].
mValue
;
}
return
QVector3D
(
pos
.
x
,
pos
.
y
,
pos
.
z
);
//Index find
int
index
=
0
;
for
(
uint
i
=
0
;
i
<
nodeAnimation
->
mNumPositionKeys
-
1
;
i
++
)
{
if
(
AnimTime
<
(
float
)
nodeAnimation
->
mPositionKeys
[
i
+
1
].
mTime
)
{
index
=
i
;
break
;
}
}
float
DeltaTime
=
(
float
)(
nodeAnimation
->
mPositionKeys
[
index
+
1
].
mTime
-
nodeAnimation
->
mPositionKeys
[
index
].
mTime
);
float
Factor
=
(
AnimTime
-
(
float
)
nodeAnimation
->
mPositionKeys
[
index
].
mTime
)
/
DeltaTime
;
QVector3D
start
=
convert
(
nodeAnimation
->
mPositionKeys
[
index
].
mValue
);
QVector3D
end
=
convert
(
nodeAnimation
->
mPositionKeys
[
index
+
1
].
mValue
);
return
linInterpolate
(
start
,
end
,
Factor
);
}
}
void
Mesh
::
render
(
QOpenGLShaderProgram
*
shader
,
QMatrix4x4
V
,
QMatrix4x4
P
){
void
Mesh
::
render
(
QOpenGLShaderProgram
*
shader
,
QMatrix4x4
V
,
QMatrix4x4
P
,
float
TimeInSeconds
){
if
(
!
loaded
)
if
(
!
loaded
)
return
;
return
;
if
(
f
==
NULL
){
if
(
f
==
NULL
){
...
@@ -381,7 +440,7 @@ void Mesh::render(QOpenGLShaderProgram *shader, QMatrix4x4 V,QMatrix4x4 P){
...
@@ -381,7 +440,7 @@ void Mesh::render(QOpenGLShaderProgram *shader, QMatrix4x4 V,QMatrix4x4 P){
f
->
glEnableVertexAttribArray
(
boneweightIndex
);
f
->
glEnableVertexAttribArray
(
boneweightIndex
);
updateBoneTransform
(
0.0
);
updateBoneTransform
(
TimeInSeconds
);
QVector
<
QMatrix4x4
>
boneTransforms
=
QVector
<
QMatrix4x4
>
(
bones
.
size
());
QVector
<
QMatrix4x4
>
boneTransforms
=
QVector
<
QMatrix4x4
>
(
bones
.
size
());
for
(
int
i
=
0
;
i
<
bones
.
size
();
i
++
){
for
(
int
i
=
0
;
i
<
bones
.
size
();
i
++
){
boneTransforms
[
i
]
=
bones
[
i
].
FinalTransformation
;
boneTransforms
[
i
]
=
bones
[
i
].
FinalTransformation
;
...
...
A5/Animation/mesh.h
View file @
10e12c16
...
@@ -47,7 +47,7 @@ public:
...
@@ -47,7 +47,7 @@ public:
void
render
(
QOpenGLShaderProgram
*
shader
,
QMatrix4x4
V
,
QMatrix4x4
P
);
void
render
(
QOpenGLShaderProgram
*
shader
,
QMatrix4x4
V
,
QMatrix4x4
P
,
float
TimeInSeconds
);
private
:
private
:
...
@@ -138,6 +138,11 @@ private:
...
@@ -138,6 +138,11 @@ private:
void
renderNode
(
QOpenGLShaderProgram
*
shader
,
Node
&
node
,
QMatrix4x4
V
,
QMatrix4x4
P
,
QMatrix4x4
M
);
void
renderNode
(
QOpenGLShaderProgram
*
shader
,
Node
&
node
,
QMatrix4x4
V
,
QMatrix4x4
P
,
QMatrix4x4
M
);
void
renderMesh
(
QOpenGLShaderProgram
*
shader
,
int
index
);
void
renderMesh
(
QOpenGLShaderProgram
*
shader
,
int
index
);
QVector3D
convert
(
aiVector3D
in
){
return
QVector3D
(
in
.
x
,
in
.
y
,
in
.
z
);}
QQuaternion
convert
(
aiQuaternion
quat
){
return
QQuaternion
(
quat
.
w
,
quat
.
x
,
quat
.
y
,
quat
.
z
);}
QVector3D
linInterpolate
(
QVector3D
start
,
QVector3D
end
,
float
Factor
){
return
(
1
.
0
-
Factor
)
*
start
+
Factor
*
end
;}
};
};
#endif // MESH_H
#endif // MESH_H
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment