PDA

View Full Version : Move horizontal or vertical according to modelView



daniel2k
04-28-2015, 04:26 AM
I have a multi view application with 4 viewports (top, front, left, perspective) and trying to map unprojected mouse coordinates according to viewport's modelView i.e. from top view, mouse x,y map to x and z of the viewport. From left mouse x,y map to z and y and in perspective it depends on the current rotation.

Currently I'm extracting the direction vector from modelView and find which component is larger and I exclude it from my computations like this:

var MV = getModelView()

if (abs(MV.m02) > abs(MV.m12) && abs(MV.m02) > abs(MV.m22)) {
ignoreAxis = 'x' //looking through the x axis so z and y are my active ones
} else if (abs(MV.m12) > abs(MV.m02) && abs(MV.m12) > abs(MV.m22)) {
ignoreAxis = 'y' //looking through the y axis (top) so x and z are my active ones
} else {
ignoreAxis = 'z' //looking through the z axis
}

This looks a little messy and a bit of a hack
I think I'm missing something. Any suggestions for a better way?