Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matrix multiplication (+ small Camera problem) #21

Open
Lemage74 opened this issue Mar 27, 2013 · 0 comments
Open

Matrix multiplication (+ small Camera problem) #21

Lemage74 opened this issue Mar 27, 2013 · 0 comments

Comments

@Lemage74
Copy link

Hi,
Here a big and a small problem.
The big one is about matrix multiplication.
To make an application targeting AS3, I took the example 2_texture as a base. As I wanted the projection matrix to affect the direction of the light (It was a mistake, but it doesn't matter here), so I replaced:
function vertex( mpos : M44, mproj : M44, light : Float3 ) {
out = input.pos.xyzw * mpos * mproj;
var tnorm = (input.norm * mpos).normalize();
lpow = light.dot(tnorm).max(0);
tuv = input.uv;
}
by
function vertex( mpos : M44, mproj : M44, light : Float3 ) {
out = input.pos.xyzw * mpos * mproj;
var tnorm = (input.norm * mpos * mproj).normalize();
lpow = light.dot(tnorm).max(0);
tuv = input.uv;
}
then I wanted to optimize by putting mpos_mproj in an variable, so I changed it for:
function vertex( mpos : M44, mproj : M44, light : Float3 ) {
var mposproj:M44 = mpos_mproj;
out = input.pos.xyzw * mposproj;
var tnorm = (input.norm * mposproj).normalize();
lpow = light.dot(tnorm).max(0);
tuv = input.uv;
}
and got an error on mpos_mproj:
M44 should be M44
I changed mposproj declaration for:
var mposproj = mpos_mproj;
and then got an error on input.pos.xyzw * mposproj:
M44 should be Float4

The small problem come with the Camera class that is given with the examples.
As the X,Y,Z vectors in Stage3D form a left-hand frame (see http://www.adobe.com/devnet/flashplayer/articles/3d-cameras.html) with X axis to right, Y to up and Z to front, the resulting projection matrix of Camera class comes reversing bottom and up.
In my case, I solved the problem replacing line 44:
var ay = az.cross(ax);
by
var ay = ax.cross(az);
It solved the problem with AS3 but it could cause it for other platforms. Maybe a better solution could be fine using precompilation instructions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant