const Matrix4 Matrix4::operator*(const Matrix4& rhs) const { Matrix4 t; for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) { vec3_t col = rhs.getCol(j); t.m[i][j] = (float) (getRow(i).dot(col) + m[3][i] * rhs.m[j][3]); } return t; }
static void OnMouseTracking(int x, int y, bool button_pressed){ static int mousex = x, mousey = y; static int bmx = x, bmy = y; float dx = x-mousex, dy = y-mousey; float sx = x-bmx, sy = y-bmy; if(button_pressed){ switch(g_CurrentMode){ case MENUID_FREE_OBJECT_ROT: g_WorldMatrix = Matrix4::rotate(dx*0.001f, Vector4(0.0f, 1.0f, 0.0f)) * Matrix4::rotate(dy*0.001f, Vector4(1.0f, 0.0f, 0.0f)) * g_WorldMatrix; break; case MENUID_FREE_CAMERA_WALK: g_ViewMatrix = Matrix4::rotate(dx*0.001f, Vector4(0.0f, 1.0f, 0.0f)) * Matrix4::rotate(dy*0.001f, Vector4(1.0f, 0.0f, 0.0f)) * g_ViewMatrix; break; case MENUID_OBJECT_AXISALIGNED: switch(g_CurrentAxisMode){ case HK_ROTATION_X_AXIS: g_TempMatrix = Matrix4::rotate(sx*0.001f, Vector4(1.0f, 0.0f, 0.0f)); break; case HK_ROTATION_Y_AXIS: g_TempMatrix = Matrix4::rotate(sx*0.001f, Vector4(0.0f, 1.0f, 0.0f)); break; case HK_ROTATION_Z_AXIS: g_TempMatrix = Matrix4::rotate(sx*0.001f, Vector4(0.0f, 0.0f, 1.0f)); break; case HK_TRANSLATION_X_AXIS: g_TempMatrix = Matrix4::translate(Vector4(sx, 0.0f, 0.0f)); break; case HK_TRANSLATION_Y_AXIS: g_TempMatrix = Matrix4::translate(Vector4(0.0f, sx, 0.0f)); break; case HK_TRANSLATION_Z_AXIS: g_TempMatrix = Matrix4::translate(Vector4(0.0f, 0.0f, sx)); break; case HK_SCALE_X_AXIS: g_TempMatrix = Matrix4::scale(Vector4(1.0f+sx * 0.01f, 1.0f, 1.0f)); break; case HK_SCALE_Y_AXIS: g_TempMatrix = Matrix4::scale(Vector4(1.0f, 1.0f+sx * 0.01f, 1.0f)); break; case HK_SCALE_Z_AXIS: g_TempMatrix = Matrix4::scale(Vector4(1.0f, 1.0f, 1.0f+sx * 0.01f)); break; case HK_SHEAR_X_AXIS: g_TempMatrix = Matrix4(Vector4(1.0f, sx * 0.01f, -sy * 0.01f, 0.0f), Vector4(0.0f, 1.0f, 0.0f, 0.0f), Vector4(0.0f, 0.0f, 1.0f, 0.0f), Vector4(0.0f, 0.0f, 0.0f, 1.0f)); break; case HK_SHEAR_Y_AXIS: g_TempMatrix = Matrix4(Vector4(1.0f, 0.0f, 0.0f, 0.0f), Vector4(sx * 0.01f, 1.0f, -sy * 0.01f, 0.0f), Vector4(0.0f, 0.0f, 1.0f, 0.0f), Vector4(0.0f, 0.0f, 0.0f, 1.0f)); break; case HK_SHEAR_Z_AXIS: g_TempMatrix = Matrix4(Vector4(1.0f, 0.0f, 0.0f, 0.0f), Vector4(0.0f, 1.0f, 0.0f, 0.0f), Vector4(sx * 0.01f, -sy * 0.01f, 1.0f, 0.0f), Vector4(0.0f, 0.0f, 0.0f, 1.0f)); break; } break; case MENUID_CAMERA_ROT_ARDOBJ_ALIGNED: { Matrix4 world; if(g_AxisAlignedTransform_InvMatrixMultOrder) world = g_WorldMatrix * g_TempMatrix; else world = g_TempMatrix * g_WorldMatrix; Vector4 object_center = world.getCol(3); Matrix4 transform = Matrix4::identity(); switch(g_CurrentAxisMode){ case HK_ROTATION_X_AXIS: transform = Matrix4::rotate(dx*0.001f, Vector4(1.0f, 0.0f, 0.0f)); break; case HK_ROTATION_Y_AXIS: transform = Matrix4::rotate(dx*0.001f, Vector4(0.0f, 1.0f, 0.0f)); break; case HK_ROTATION_Z_AXIS: transform = Matrix4::rotate(dx*0.001f, Vector4(0.0f, 0.0f, 1.0f)); break; case HK_TRANSLATION_X_AXIS: g_ViewMatrix = g_ViewMatrix * Matrix4::translate(Vector4(dx, 0.0f, 0.0f)); break; case HK_TRANSLATION_Y_AXIS: g_ViewMatrix = g_ViewMatrix * Matrix4::translate(Vector4(0.0f, dx, 0.0f)); break; case HK_TRANSLATION_Z_AXIS: g_ViewMatrix = g_ViewMatrix * Matrix4::translate(Vector4(0.0f, 0.0f, dx)); break; } transform = Matrix4::translate(object_center) * transform * Matrix4::translate(Vector4::negate(object_center)); g_ViewMatrix = g_ViewMatrix * transform; } break; } }else{ if(g_AxisAlignedTransform_InvMatrixMultOrder) g_WorldMatrix = g_WorldMatrix * g_TempMatrix; else g_WorldMatrix = g_TempMatrix * g_WorldMatrix; g_TempMatrix = Matrix4::identity(); bmx = x, bmy = y; } mousex = x, mousey = y; }