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
9703db3f
Commit
9703db3f
authored
Feb 07, 2016
by
Kai Westerkamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
AABB
parent
42afb638
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
53 deletions
+71
-53
camera.cpp
A5/Animation/camera.cpp
+1
-1
mesh.cpp
A5/Animation/mesh.cpp
+62
-52
mesh.h
A5/Animation/mesh.h
+8
-0
No files found.
A5/Animation/camera.cpp
View file @
9703db3f
...
...
@@ -3,7 +3,7 @@
Camera
::
Camera
()
{
//setHome(new QQuaternion(45,0,1,0), new QVector3D(-100,0,0));
setHome
(
new
QQuaternion
(
QQuaternion
::
fromAxisAndAngle
(
1
,
0
,
0
,
20
)),
new
QVector3D
(
0
,
-
25
,
-
150
));
setHome
(
new
QQuaternion
(
QQuaternion
::
fromAxisAndAngle
(
1
,
0
,
0
,
20
)),
new
QVector3D
(
0
,
0
,
-
150
));
}
void
Camera
::
home
()
...
...
A5/Animation/mesh.cpp
View file @
9703db3f
...
...
@@ -21,8 +21,9 @@ Mesh::MeshEntry::MeshEntry()
numIndex
=
0
;
VB
=
0xFFFFFFFF
;
IB
=
0xFFFFFFFF
;
};
min
=
QVector3D
();
max
=
QVector3D
();
}
void
Mesh
::
MeshEntry
::
init
(
QOpenGLFunctions_4_3_Core
*
f
,
QVector
<
Vertex
>&
Vertices
,
QVector
<
unsigned
int
>&
Indices
){
...
...
@@ -36,6 +37,22 @@ void Mesh::MeshEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertice
f
->
glGenBuffers
(
1
,
&
IB
);
f
->
glBindBuffer
(
GL_ELEMENT_ARRAY_BUFFER
,
IB
);
f
->
glBufferData
(
GL_ELEMENT_ARRAY_BUFFER
,
sizeof
(
unsigned
int
)
*
numIndex
,
&
Indices
[
0
],
GL_STATIC_DRAW
);
double
amax
=
std
::
numeric_limits
<
float
>::
max
();
min
=
QVector3D
(
amax
,
amax
,
amax
);
max
=
QVector3D
(
-
amax
,
-
amax
,
-
amax
);
//calc AABB
for
(
int
i
=
0
;
i
<
Vertices
.
size
();
++
i
)
{
Vertex
v
=
Vertices
[
i
];
min
.
setX
(
qMin
(
min
.
x
(),
v
.
pos
.
x
()));
min
.
setY
(
qMin
(
min
.
y
(),
v
.
pos
.
y
()));
min
.
setZ
(
qMin
(
min
.
z
(),
v
.
pos
.
z
()));
max
.
setX
(
qMax
(
max
.
x
(),
v
.
pos
.
x
()));
max
.
setY
(
qMax
(
max
.
y
(),
v
.
pos
.
y
()));
max
.
setZ
(
qMax
(
max
.
z
(),
v
.
pos
.
z
()));
}
}
Mesh
::
MeshEntry
::~
MeshEntry
()
...
...
@@ -64,6 +81,7 @@ Mesh::Node::Node()
Mesh
::
Mesh
(
QOpenGLFunctions_4_3_Core
*
f
,
QString
fileName
)
{
screenTransform
=
QMatrix4x4
();
loaded
=
false
;
linear
=
false
;
this
->
f
=
f
;
...
...
@@ -138,56 +156,22 @@ Mesh::Mesh(QOpenGLFunctions_4_3_Core *f,QString fileName)
globalInverseTransform
=
rootNode
.
transformation
.
inverted
();
double
amax
=
std
::
numeric_limits
<
float
>::
max
();
QVector3D
min
=
QVector3D
(
amax
,
amax
,
amax
);
QVector3D
max
=
QVector3D
(
-
amax
,
-
amax
,
-
amax
);
// findObjectDimension(rootNode,QMatrix4x4(),min,max);
qDebug
()
<<
"AABB"
<<
min
<<
max
;
float
dist
=
qMax
(
max
.
x
()
-
min
.
x
(),
qMax
(
max
.
y
()
-
min
.
y
(),
max
.
z
()
-
min
.
z
()));
float
sc
=
75.0
/
dist
;
QVector3D
center
=
(
max
-
min
)
/
2
;
QVector3D
trans
=
-
(
max
-
center
);
// //Test Interpolation:
// if(false){
// const aiAnimation* animation = scene->mAnimations[0];
// const aiNodeAnim *nodeAnimation = findAnimOfNode(animation,"upperarm.R");
// qDebug()<<"KeyFrames";
// for(uint i = 0; i < nodeAnimation->mNumPositionKeys; i++){
// qDebug()<<nodeAnimation->mPositionKeys[i].mTime<<convert(nodeAnimation->mPositionKeys[i].mValue);
// }
// qDebug()<<"Interpolated";
// for(float f = 0.0; f < (float)animation->mDuration; f += 0.5f){
// qDebug()<<f<<calcInterpolatedTranslation(f,nodeAnimation);
// }
// }
// for (int i = 0; i < scene->mNumAnimations; ++i) {
// const aiAnimation* animation = scene->mAnimations[i];
// qDebug()<<"Animation"<<animation->mName.C_Str();
// switch (animation->mChannels[0]->mPreState) {
// case aiAnimBehaviour_CONSTANT:
// qDebug()<<"Pre"<<"aiAnimBehaviour_CONSTANT";
// break;
// case aiAnimBehaviour_REPEAT: // use start or end
// qDebug()<<"Pre"<<"aiAnimBehaviour_REPEAT";
// break;
// case aiAnimBehaviour_LINEAR: // linear interpolate
// qDebug()<<"Pre"<<"aiAnimBehaviour_LINEAR";
// break;
// case aiAnimBehaviour_DEFAULT: // take default node transformation
// qDebug()<<"Pre"<<"aiAnimBehaviour_DEFAULT";
// break;
// default:
// qDebug()<<"Pre"<<"not";
// }
// switch (animation->mChannels[0]->mPostState) {
// case aiAnimBehaviour_CONSTANT:
// qDebug()<<"Post"<<"aiAnimBehaviour_CONSTANT";
// break;
// case aiAnimBehaviour_REPEAT: // use start or end
// qDebug()<<"Post"<<"aiAnimBehaviour_REPEAT";
// break;
// case aiAnimBehaviour_LINEAR: // linear interpolate
// qDebug()<<"Post"<<"aiAnimBehaviour_LINEAR";
// break;
// case aiAnimBehaviour_DEFAULT: // take default node transformation
// qDebug()<<"Post"<<"aiAnimBehaviour_DEFAULT";
// break;
// default:
// qDebug()<<"Post"<<"not";
// }
// }
// Apply the scale and translation to a matrix
screenTransform
.
setToIdentity
();
// screenTransform.scale(sc);
// screenTransform.translate(trans);
loaded
=
true
;
}
...
...
@@ -365,7 +349,7 @@ void Mesh::render(QOpenGLShaderProgram *shader, QMatrix4x4 V,QMatrix4x4 P, float
shader
->
setUniformValueArray
(
"Bones"
,
boneTransforms
.
constData
(),
boneTransforms
.
size
());
renderNode
(
shader
,
rootNode
,
V
,
P
,
QMatrix4x4
());
renderNode
(
shader
,
rootNode
,
V
*
screenTransform
,
P
,
QMatrix4x4
());
f
->
glDisableVertexAttribArray
(
positionIndex
);
...
...
@@ -653,6 +637,32 @@ double Mesh::timeCatmul(QVector3D p1, QVector3D p2, double t_1){
return
t
;
}
void
Mesh
::
findObjectDimension
(
Node
node
,
QMatrix4x4
transform
,
QVector3D
&
min
,
QVector3D
&
max
){
transform
*=
node
.
transformation
;
for
(
int
i
=
0
;
i
<
node
.
meshes
.
size
();
i
++
)
{
QVector4D
temp
=
transform
*
QVector4D
(
entries
[
node
.
meshes
[
i
]].
min
,
1.0
);
min
.
setX
(
qMin
(
min
.
x
(),
temp
.
x
()));
min
.
setY
(
qMin
(
min
.
y
(),
temp
.
y
()));
min
.
setZ
(
qMin
(
min
.
z
(),
temp
.
z
()));
max
.
setX
(
qMax
(
max
.
x
(),
temp
.
x
()));
max
.
setY
(
qMax
(
max
.
y
(),
temp
.
y
()));
max
.
setZ
(
qMax
(
max
.
z
(),
temp
.
z
()));
temp
=
transform
*
QVector4D
(
entries
[
node
.
meshes
[
i
]].
max
,
1.0
);
min
.
setX
(
qMin
(
min
.
x
(),
temp
.
x
()));
min
.
setY
(
qMin
(
min
.
y
(),
temp
.
y
()));
min
.
setZ
(
qMin
(
min
.
z
(),
temp
.
z
()));
max
.
setX
(
qMax
(
max
.
x
(),
temp
.
x
()));
max
.
setY
(
qMax
(
max
.
y
(),
temp
.
y
()));
max
.
setZ
(
qMax
(
max
.
z
(),
temp
.
z
()));
}
for
(
int
i
=
0
;
i
<
node
.
children
.
size
();
i
++
)
{
findObjectDimension
(
node
.
children
[
i
],
transform
,
min
,
max
);
}
}
A5/Animation/mesh.h
View file @
9703db3f
...
...
@@ -69,6 +69,9 @@ private:
int
numIndex
;
int
materialIndex
;
QOpenGLFunctions_4_3_Core
*
f
;
QVector3D
min
;
QVector3D
max
;
};
struct
MaterialInfo
...
...
@@ -112,6 +115,8 @@ private:
Assimp
::
Importer
importer
;
QMatrix4x4
globalInverseTransform
;
QMatrix4x4
screenTransform
;
QVector
<
MeshEntry
>
entries
;
...
...
@@ -152,6 +157,9 @@ private:
QVector3D
Catmul
(
QVector3D
before
,
QVector3D
start
,
QVector3D
end
,
QVector3D
after
,
float
Factor
);
double
timeCatmul
(
QVector3D
p1
,
QVector3D
p2
,
double
t_1
);
void
findObjectDimension
(
Node
node
,
QMatrix4x4
transform
,
QVector3D
&
min
,
QVector3D
&
max
);
};
#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