Hi Folks,
I am trying to extend the daeviewer example with support for animation and have some questions. I would really appreciate any help or tips from other pycollada users and developers.
What is typically necessary for animation is to change some transformation (for example, rotation) for certain primitive and redraw it. So my first question is where can I find a list of transformations defined for the primitive? I realized, that there is a "matrix" member variable used to create bounded primitives, but it seams like it represents combined transformation. However, what I think is necessary is the list of named transformations to make it easier to find target transformation based on the parameters defined in the animation. Is something like this already exists in pycollada?
Since pycollada reader already applies defined transformations to create bounded primitives, I thought that, as a first experiment I can access original primitive and apply transformation matrix myself. I've assumed, that I can treat this matrix as ModelView matrix (using OpenGL terminology) and can pass it to the shader as a parameter. For these purposes, I flatten the original matrix as following:
transform_matrix = []
for row in geom.matrix:
transform_matrix.extend(row.tolist())
Then I modify the simplePhong vertex shader from daeview visualization example:
varying vec3 normal, lightDir0, eyeVec;
uniform mat4 mvMatrix;
uniform mat4 pMatrix;
void main()
{
normal = gl_NormalMatrix * gl_Normal;
vec4 vVertex = mvMatrix * gl_Vertex;
lightDir0 = vec3(gl_LightSource[0].
position.xyz - vVertex.xyz);
eyeVec = -vVertex.xyz;
gl_Position = pMatrix * vVertex;
}
where pMatrix is an OpenGL projection matrix and calculated as described
here:
def createProjectionMatrix(fovY, aspect, zNear, zFar):
"""Creates perspective projection matrix. fovY should be in radians"""
f = 1.0 / math.tan(fovY/2.0) #cotangent(fovY/2)
dz = zNear - zFar
m = []
m.extend([f/aspect, 0.0, 0.0, 0.0])
m.extend([0.0, f, 0.0, 0.0])
m.extend([0.0, 0.0, (zFar + zNear) / dz, (2.0 * zFar * zNear) / dz])
m.extend([0.0, 0.0, -1.0, 0.0])
return m
Despite all my attempts, with this approach I was unable to visualize the model as it should be. My best results were all primitives drawn at origin, which corresponds to the original primitive with all transformations ignored. So maybe there is some conceptual mistake in my approach and I would highly appreciate if someone experienced with pycollada can provide some comments on it.
Thank you,
Andrey.