mirror of
https://github.com/lubosz/overte.git
synced 2025-04-27 16:35:28 +02:00
Stable version of the Transform and usage for Model rendering with soimilar performances and same accuracy level
This commit is contained in:
parent
7a9f45d34f
commit
b716a512c6
9 changed files with 37 additions and 19 deletions
interface/src
libraries/shared/src
|
@ -2805,6 +2805,8 @@ void Application::updateShadowMap() {
|
|||
|
||||
// store view matrix without translation, which we'll use for precision-sensitive objects
|
||||
updateUntranslatedViewMatrix();
|
||||
// TODO: assign an equivalent viewTransform object to the application to match the current path which uses glMatrixStack
|
||||
// setViewTransform(viewTransform);
|
||||
|
||||
glEnable(GL_POLYGON_OFFSET_FILL);
|
||||
glPolygonOffset(1.1f, 4.0f); // magic numbers courtesy http://www.eecs.berkeley.edu/~ravir/6160/papers/shadowmaps.ppt
|
||||
|
@ -2883,6 +2885,7 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) {
|
|||
PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "Application::displaySide()");
|
||||
// transform by eye offset
|
||||
|
||||
|
||||
gpu::Transform viewTransform;
|
||||
|
||||
// load the view frustum
|
||||
|
@ -2902,9 +2905,9 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) {
|
|||
glm::quat eyeOffsetOrient = whichCamera.getEyeOffsetOrientation();
|
||||
glm::vec3 eyeOffsetAxis = glm::axis(eyeOffsetOrient);
|
||||
glRotatef(-glm::degrees(glm::angle(eyeOffsetOrient)), eyeOffsetAxis.x, eyeOffsetAxis.y, eyeOffsetAxis.z);
|
||||
viewTransform.preRotate(glm::quat(-glm::angle(eyeOffsetOrient), glm::vec3(eyeOffsetAxis.x, eyeOffsetAxis.y, eyeOffsetAxis.z)));
|
||||
glTranslatef(-eyeOffsetPos.x, -eyeOffsetPos.y, -eyeOffsetPos.z);
|
||||
viewTransform.preTranslate(glm::vec3(-eyeOffsetPos.x, -eyeOffsetPos.y, -eyeOffsetPos.z));
|
||||
viewTransform.postRotate(glm::conjugate(eyeOffsetOrient));
|
||||
glTranslatef(-eyeOffsetPos.x, -eyeOffsetPos.y, -eyeOffsetPos.z);
|
||||
viewTransform.postTranslate(-eyeOffsetPos);
|
||||
|
||||
// transform view according to whichCamera
|
||||
// could be myCamera (if in normal mode)
|
||||
|
@ -2913,11 +2916,15 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) {
|
|||
glm::quat rotation = whichCamera.getRotation();
|
||||
glm::vec3 axis = glm::axis(rotation);
|
||||
glRotatef(-glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
||||
viewTransform.preRotate(glm::quat(-glm::angle(rotation), axis));
|
||||
viewTransform.postRotate(glm::conjugate(rotation));
|
||||
|
||||
// store view matrix without translation, which we'll use for precision-sensitive objects
|
||||
updateUntranslatedViewMatrix(-whichCamera.getPosition());
|
||||
viewTransform.preTranslate(-whichCamera.getPosition());
|
||||
|
||||
// Equivalent to what is happening with _untranslatedViewMatrix and the _viewMatrixTranslation
|
||||
// the viewTransofmr object is updated with the correct value and saved,
|
||||
// this is what is used for rendering the ENtities and avatars
|
||||
setViewTransform(viewTransform);
|
||||
|
||||
glTranslatef(_viewMatrixTranslation.x, _viewMatrixTranslation.y, _viewMatrixTranslation.z);
|
||||
|
||||
|
@ -3120,8 +3127,10 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) {
|
|||
void Application::updateUntranslatedViewMatrix(const glm::vec3& viewMatrixTranslation) {
|
||||
glGetFloatv(GL_MODELVIEW_MATRIX, (GLfloat*)&_untranslatedViewMatrix);
|
||||
_viewMatrixTranslation = viewMatrixTranslation;
|
||||
_viewTransform->evalFromRawMatrix(_untranslatedViewMatrix);
|
||||
_viewTransform->postTranslate(viewMatrixTranslation);
|
||||
}
|
||||
|
||||
void Application::setViewTransform(const gpu::Transform& view) {
|
||||
(*_viewTransform) = view;
|
||||
}
|
||||
|
||||
void Application::loadTranslatedViewMatrix(const glm::vec3& translation) {
|
||||
|
|
|
@ -234,6 +234,7 @@ public:
|
|||
void setViewMatrixTranslation(const glm::vec3& translation) { _viewMatrixTranslation = translation; }
|
||||
|
||||
const gpu::TransformPointer& getViewTransform() const { return _viewTransform; }
|
||||
void setViewTransform(const gpu::Transform& view);
|
||||
|
||||
/// if you need to access the application settings, use lockSettings()/unlockSettings()
|
||||
QSettings* lockSettings() { _settingsMutex.lock(); return _settings; }
|
||||
|
|
|
@ -21,7 +21,11 @@ Batch::Batch() :
|
|||
_commandOffsets(),
|
||||
_params(),
|
||||
_resources(),
|
||||
_data(){
|
||||
_data(),
|
||||
_buffers(),
|
||||
_streamFormats(),
|
||||
_transforms()
|
||||
{
|
||||
}
|
||||
|
||||
Batch::~Batch() {
|
||||
|
@ -32,8 +36,10 @@ void Batch::clear() {
|
|||
_commandOffsets.clear();
|
||||
_params.clear();
|
||||
_resources.clear();
|
||||
_buffers.clear();
|
||||
_data.clear();
|
||||
_buffers.clear();
|
||||
_streamFormats.clear();
|
||||
_transforms.clear();
|
||||
}
|
||||
|
||||
uint32 Batch::cacheResource(Resource* res) {
|
||||
|
|
|
@ -316,13 +316,12 @@ public:
|
|||
CommandOffsets _commandOffsets;
|
||||
Params _params;
|
||||
Resources _resources;
|
||||
Bytes _data;
|
||||
|
||||
BufferCaches _buffers;
|
||||
StreamFormatCaches _streamFormats;
|
||||
|
||||
TransformCaches _transforms;
|
||||
|
||||
Bytes _data;
|
||||
protected:
|
||||
};
|
||||
|
||||
|
|
|
@ -458,6 +458,7 @@ void GLBackend::do_setProjectionTransform(Batch& batch, uint32 paramOffset) {
|
|||
|
||||
void GLBackend::updateTransform() {
|
||||
if (_transform._invalidProj) {
|
||||
// TODO: implement the projection matrix assignment to gl state
|
||||
/* if (_transform._lastMode != GL_PROJECTION) {
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
_transform._lastMode = GL_PROJECTION;
|
||||
|
|
|
@ -560,7 +560,8 @@ bool Model::render(float alpha, RenderMode mode, RenderArgs* args) {
|
|||
_transforms.push_back(gpu::TransformPointer(new gpu::Transform()));
|
||||
}
|
||||
(*_transforms[0]) = gpu::Transform((*Application::getInstance()->getViewTransform()));
|
||||
_transforms[0]->postTranslate(_translation);
|
||||
// apply entity translation + camera position offset to the viewTransform in one go
|
||||
_transforms[0]->postTranslate(Application::getInstance()->getViewMatrixTranslation() + _translation);
|
||||
|
||||
batch.setViewTransform(_transforms[0]);
|
||||
|
||||
|
|
|
@ -919,7 +919,9 @@ void SetSpannerTool::applyEdit(const AttributePointer& attribute, const SharedOb
|
|||
Application::getInstance()->setupWorldLight();
|
||||
|
||||
Application::getInstance()->updateUntranslatedViewMatrix();
|
||||
|
||||
// TODO: assign an equivalent viewTransform object to the application to match the current path which uses glMatrixStack
|
||||
// setViewTransform(viewTransform);
|
||||
|
||||
const glm::vec4 OPAQUE_WHITE(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
spannerData->getRenderer()->render(OPAQUE_WHITE, SpannerRenderer::DIFFUSE_MODE, glm::vec3(), 0.0f);
|
||||
|
||||
|
|
|
@ -25,14 +25,12 @@ void Transform::evalRotationScale(Quat& rotation, Vec3& scale, const Mat3& rotat
|
|||
Mat3 rotationMat = rotationScaleMatrix;
|
||||
do {
|
||||
Mat3 nextRotation;
|
||||
Mat3 currInvTranspose =
|
||||
glm::inverse(glm::transpose(rotationMat));
|
||||
Mat3 currInvTranspose = glm::inverse(glm::transpose(rotationMat));
|
||||
|
||||
// Go through every component in the matrices and find the next matrix
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int j = 0; j <3; j++) {
|
||||
nextRotation[j][i] = 0.5f *
|
||||
(rotationMat[j][i] + currInvTranspose[j][i]);
|
||||
nextRotation[j][i] = 0.5f * (rotationMat[j][i] + currInvTranspose[j][i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,7 +71,8 @@ void Transform::evalRotationScale(Quat& rotation, Vec3& scale, const Mat3& rotat
|
|||
|
||||
// Beware: even though the matRot is supposed to be normalized at that point,
|
||||
// glm::quat_cast doesn't always return a normalized quaternion...
|
||||
rotation = glm::normalize(glm::quat_cast(matRot));
|
||||
// rotation = glm::normalize(glm::quat_cast(matRot));
|
||||
rotation = (glm::quat_cast(matRot));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -296,7 +296,7 @@ inline Transform& Transform::evalInverse(Transform& inverse) const {
|
|||
}
|
||||
}
|
||||
if (isRotating()) {
|
||||
inverse.postRotate(-_rotation);
|
||||
inverse.postRotate(glm::conjugate(_rotation));
|
||||
}
|
||||
if (isTranslating()) {
|
||||
inverse.postTranslate(-_translation);
|
||||
|
|
Loading…
Reference in a new issue