void Object::UpdateObjectMatrix() { Matrix4f mTranslate(MATRIX_TRANSLATE, m_vWorldPos); Matrix4f mRotate(MATRIX_ROTATE, m_qRotation); Matrix4f mScale(MATRIX_SCALE, m_vScale); m_mModelMatrix = mTranslate * mRotate * mScale; //m_mModelMatrix.Print("Model"); } // end Object::UpdateObjectMatrix()
void SliceRenderer::calculateBoundingRect() { assert(_sliceFramePtr); _screenRectangle.left = 0; _screenRectangle.right = 0; _screenRectangle.top = 0; _screenRectangle.bottom = 0; Matrix4x3 viewMatrix = _view->_sliceViewMatrix; Vector3 frameBottom = Vector3(0.0f, 0.0f, _frameBottomZ); Vector3 frameTop = Vector3(0.0f, 0.0f, _frameBottomZ + _frameSliceCount * _frameSliceHeight); Vector3 bottom = viewMatrix * (_position + frameBottom); Vector3 top = viewMatrix * (_position + frameTop); top = bottom + _scale * (top - bottom); if (bottom.z <= 0.0f || top.z <= 0.0f) { return; } Matrix3x2 facingRotation = calculateFacingRotationMatrix(); Matrix3x2 mProjection(_view->_viewportPosition.z / bottom.z, 0.0f, 0.0f, 0.0f, 25.5f, 0.0f); Matrix3x2 mOffset(1.0f, 0.0f, _framePos.x, 0.0f, 1.0f, _framePos.y); Matrix3x2 mScale(_frameScale.x, 0.0f, 0.0f, 0.0f, _frameScale.y, 0.0f); _mvpMatrix = mProjection * (facingRotation * (mOffset * mScale)); Vector4 startScreenVector( _view->_viewportPosition.x + (top.x / top.z) * _view->_viewportPosition.z, _view->_viewportPosition.y + (top.y / top.z) * _view->_viewportPosition.z, 1.0f / top.z, _frameSliceCount * (1.0f / top.z)); Vector4 endScreenVector( _view->_viewportPosition.x + (bottom.x / bottom.z) * _view->_viewportPosition.z, _view->_viewportPosition.y + (bottom.y / bottom.z) * _view->_viewportPosition.z, 1.0f / bottom.z, 0.0f); Vector4 delta = endScreenVector - startScreenVector; if (delta.y == 0.0f) { return; } /* * Calculate min and max Y */ float screenTop = 0.0f; float screenBottom = 479.0f; if (startScreenVector.y < screenTop) { if (endScreenVector.y < screenTop) { return; } float f = (screenTop - startScreenVector.y) / delta.y; startScreenVector = startScreenVector + f * delta; } else if (startScreenVector.y > screenBottom) { if (endScreenVector.y >= screenBottom) { return; } float f = (screenBottom - startScreenVector.y) / delta.y; startScreenVector = startScreenVector + f * delta; } if (endScreenVector.y < screenTop) { float f = (screenTop - endScreenVector.y) / delta.y; endScreenVector = endScreenVector + f * delta; } else if (endScreenVector.y > screenBottom) { float f = (screenBottom - endScreenVector.y) / delta.y; endScreenVector = endScreenVector + f * delta; } _screenRectangle.top = (int)MIN(startScreenVector.y, endScreenVector.y); _screenRectangle.bottom = (int)MAX(startScreenVector.y, endScreenVector.y) + 1; /* * Calculate min and max X */ Matrix3x2 mStart( 1.0f, 0.0f, startScreenVector.x, 0.0f, 1.0f, 25.5f / startScreenVector.z ); Matrix3x2 mEnd( 1.0f, 0.0f, endScreenVector.x, 0.0f, 1.0f, 25.5f / endScreenVector.z ); Matrix3x2 mStartMVP = mStart * _mvpMatrix; Matrix3x2 mEndMVP = mEnd * _mvpMatrix; float minX = 640.0f; float maxX = 0.0f; for (float i = 0.0f; i <= 256.0f; i += 255.0f) { for (float j = 0.0f; j <= 256.0f; j += 255.0f) { Vector2 v1 = mStartMVP * Vector2(i, j); minX = MIN(minX, v1.x); maxX = MAX(maxX, v1.x); Vector2 v2 = mEndMVP * Vector2(i, j); minX = MIN(minX, v2.x); maxX = MAX(maxX, v2.x); } } _screenRectangle.left = CLIP((int)minX, 0, 640); _screenRectangle.right = CLIP((int)maxX + 1, 0, 640); _startScreenVector.x = startScreenVector.x; _startScreenVector.y = startScreenVector.y; _startScreenVector.z = startScreenVector.z; _endScreenVector.x = endScreenVector.x; _endScreenVector.y = endScreenVector.y; _endScreenVector.z = endScreenVector.z; _startSlice = startScreenVector.w; _endSlice = endScreenVector.w; }