Graphic3d_CStructure::Transformation - use Graphic3d_Mat4 instead of plain arrays.
Drop duplicating field OpenGl_Structure::myTransformation (copy of Graphic3d_CStructure::Transformation).
Drop unused property Graphic3d_CStructure::Composition and Graphic3d_Structure::Composition().
myZLayer (Graphic3d_ZLayerId_Default),
Priority (Structure_MAX_PRIORITY / 2),
PreviousPriority (Structure_MAX_PRIORITY / 2),
- Composition (Graphic3d_TOC_REPLACE),
ContainsFacet (0),
IsInfinite (0),
stick (0),
Is2dText (Standard_False),
myGraphicDriver (theManager->GraphicDriver())
{
- for (Standard_Integer i = 0; i <= 3; ++i)
- {
- for (Standard_Integer j = 0; j <= 3; ++j)
- {
- Transformation[i][j] = (i == j) ? 1.0f : 0.0f;
- }
- }
-
ContextLine.IsDef = 1,
ContextFillArea.IsDef = 1,
ContextMarker.IsDef = 1,
CALL_DEF_COLOR HighlightColor;
- float Transformation[4][4];
- Graphic3d_TypeOfComposition Composition;
+ Graphic3d_Mat4 Transformation;
int ContainsFacet;
return myCStructure->visible ? Standard_True : Standard_False;
}
-//=============================================================================
-//function : IsRotated
-//purpose :
-//=============================================================================
-Standard_Boolean Graphic3d_Structure::IsRotated() const
-{
- // A somewhat light test !
- return myCStructure->Transformation[0][1] != 0.0
- || myCStructure->Transformation[0][2] != 0.0
- || myCStructure->Transformation[1][0] != 0.0
- || myCStructure->Transformation[1][2] != 0.0
- || myCStructure->Transformation[2][0] != 0.0
- || myCStructure->Transformation[2][1] != 0.0;
-}
-
//=============================================================================
//function : IsTransformed
//purpose :
//=============================================================================
Standard_Boolean Graphic3d_Structure::IsTransformed() const
{
- Standard_Boolean aResult = Standard_False;
- for (Standard_Integer i = 0; i <= 3 && !aResult; ++i)
- {
- for (Standard_Integer j = 0; j <= 3 && !aResult; ++j)
- {
- if (i == j)
- aResult = myCStructure->Transformation[i][j] != 1.0;
- else
- aResult = myCStructure->Transformation[i][j] != 0.0;
- }
- }
- return aResult;
+ return !myCStructure->Transformation.IsIdentity();
}
//=============================================================================
}
}
-//=============================================================================
-//function : Composition
-//purpose :
-//=============================================================================
-Graphic3d_TypeOfComposition Graphic3d_Structure::Composition() const
-{
- return myCStructure->Composition;
-}
-
//=============================================================================
//function : SetTransform
//purpose :
Graphic3d_TransformError::Raise ("Transform : not a 4x4 matrix");
}
+ const Standard_Boolean wasTransformed = IsTransformed();
switch (theType)
{
case Graphic3d_TOC_REPLACE:
{
- myCStructure->Composition = Graphic3d_TOC_REPLACE;
// Update of CStructure
for (Standard_Integer i = 0; i <= 3; ++i)
{
for (Standard_Integer j = 0; j <= 3; ++j)
{
- myCStructure->Transformation[i][j] = float (theMatrix (lr + i, lc + j));
+ myCStructure->Transformation.ChangeValue (i, j) = float (theMatrix (lr + i, lc + j));
aNewTrsf (i, j) = theMatrix (lr + i, lc + j);
}
}
}
case Graphic3d_TOC_POSTCONCATENATE:
{
- myCStructure->Composition = Graphic3d_TOC_POSTCONCATENATE;
// To simplify management of indices
for (Standard_Integer i = 0; i <= 3; ++i)
{
aNewTrsf (i, j) = 0.0;
for (Standard_Integer k = 0; k <= 3; ++k)
{
- valueoldtrsf = myCStructure->Transformation[i][k];
+ valueoldtrsf = myCStructure->Transformation.GetValue (i, k);
valuetrsf = aMatrix44 (k, j);
valuenewtrsf = aNewTrsf (i, j) + valueoldtrsf * valuetrsf;
aNewTrsf (i, j) = valuenewtrsf;
{
for (Standard_Integer j = 0; j <= 3; ++j)
{
- myCStructure->Transformation[i][j] = float (aNewTrsf (i, j));
+ myCStructure->Transformation.ChangeValue (i, j) = float (aNewTrsf (i, j));
}
}
break;
}
// If transformation, no validation of hidden already calculated parts
- if (IsRotated())
+ if (IsTransformed() || (!IsTransformed() && wasTransformed))
{
ReCompute();
}
{
for (Standard_Integer j = 0; j <= 3; ++j)
{
- theMatrix (lr + i, lc + j) = myCStructure->Transformation[i][j];
+ theMatrix (lr + i, lc + j) = myCStructure->Transformation.GetValue (i, j);
}
}
}
{
for (Standard_Integer j = 0; j <= 3; ++j)
{
- myCStructure->Transformation[i][j] = float (theMatrix (i, j));
+ myCStructure->Transformation.ChangeValue (i, j) = float (theMatrix (i, j));
}
}
myCStructure->UpdateTransformation();
//! Returns the highlight indicator for the structure <me>.
Standard_EXPORT virtual Standard_Boolean IsHighlighted() const;
- //! Returns Standard_True if the structure <me> is rotated.
- //! <=> The transformation != Identity, != Scale, != Translation.
- Standard_EXPORT Standard_Boolean IsRotated() const;
-
//! Returns Standard_True if the structure <me> is transformed.
//! <=> The transformation != Identity.
Standard_EXPORT Standard_Boolean IsTransformed() const;
Standard_EXPORT void SetHLRValidation (const Standard_Boolean AFlag);
Standard_EXPORT Standard_Boolean HLRValidation() const;
-
- //! Returns the type of composition applied to matrices
- //! of transformation of <me>.
- Standard_EXPORT Graphic3d_TypeOfComposition Composition() const;
-
+
//! Modifies the current local modelling transformation
//! in the structure <me>.
//!
OpenGl_GraduatedTrihedron.cxx
OpenGl_MapOfZLayerSettings.hxx
OpenGl_Matrix.hxx
-OpenGl_Matrix.cxx
OpenGl_MatrixState.hxx
OpenGl_NamedStatus.hxx
OpenGl_TextParam.hxx
+++ /dev/null
-// Created on: 2011-07-13
-// Created by: Sergey ZERCHANINOV
-// Copyright (c) 2011-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#include <OpenGl_Matrix.hxx>
-
-/*----------------------------------------------------------------------*/
-
-void OpenGl_Transposemat3 (OpenGl_Matrix *c, const OpenGl_Matrix *a)
-{
- Tint row, col;
- for (row = 0; row < 4; row++)
- for (col = 0; col < 4; col++)
- c->mat[row][col] = a->mat[col][row];
-}
DEFINE_STANDARD_ALLOC
};
-Standard_EXPORT void OpenGl_Transposemat3 (OpenGl_Matrix *c, const OpenGl_Matrix *a);
-
#endif //OpenGl_Matrix_Header
// =======================================================================
OpenGl_Structure::OpenGl_Structure (const Handle(Graphic3d_StructureManager)& theManager)
: Graphic3d_CStructure (theManager),
- myTransformation (NULL),
myAspectLine (NULL),
myAspectFace (NULL),
myAspectMarker (NULL),
OpenGl_Structure::~OpenGl_Structure()
{
Release (Handle(OpenGl_Context)());
- delete myTransformation; myTransformation = NULL;
}
// =======================================================================
// =======================================================================
void OpenGl_Structure::UpdateTransformation()
{
- if (myTransformation == NULL)
- {
- myTransformation = new OpenGl_Matrix();
- }
-
- Standard_ShortReal (*aMat)[4] = Graphic3d_CStructure::Transformation;
-
+ const OpenGl_Mat4& aMat = Graphic3d_CStructure::Transformation;
Standard_ShortReal aDet =
- aMat[0][0] * (aMat[1][1] * aMat[2][2] - aMat[2][1] * aMat[1][2]) -
- aMat[0][1] * (aMat[1][0] * aMat[2][2] - aMat[2][0] * aMat[1][2]) +
- aMat[0][2] * (aMat[1][0] * aMat[2][1] - aMat[2][0] * aMat[1][1]);
+ aMat.GetValue(0, 0) * (aMat.GetValue(1, 1) * aMat.GetValue(2, 2) - aMat.GetValue(2, 1) * aMat.GetValue(1, 2)) -
+ aMat.GetValue(0, 1) * (aMat.GetValue(1, 0) * aMat.GetValue(2, 2) - aMat.GetValue(2, 0) * aMat.GetValue(1, 2)) +
+ aMat.GetValue(0, 2) * (aMat.GetValue(1, 0) * aMat.GetValue(2, 1) - aMat.GetValue(2, 0) * aMat.GetValue(1, 1));
// Determinant of transform matrix less then 0 means that mirror transform applied.
myIsMirrored = aDet < 0.0f;
- matcpy (myTransformation->mat, &Graphic3d_CStructure::Transformation[0][0]);
-
if (IsRaytracable())
{
++myModificationState;
theWorkspace->NamedStatus |= OPENGL_NS_HIGHLIGHT;
}
- // Do we need to restore GL_NORMALIZE?
- const Standard_Boolean anOldGlNormalize = aCtx->IsGlNormalizeEnabled();
-
// Apply local transformation
- if (myTransformation)
- {
- OpenGl_Matrix aModelWorld;
- OpenGl_Transposemat3 (&aModelWorld, myTransformation);
- aCtx->ModelWorldState.Push();
- aCtx->ModelWorldState.SetCurrent (OpenGl_Mat4::Map ((Standard_ShortReal* )aModelWorld.mat));
-
- Standard_ShortReal aScaleX = OpenGl_Vec3 (myTransformation->mat[0][0],
- myTransformation->mat[0][1],
- myTransformation->mat[0][2]).SquareModulus();
- // Scale transform detected.
- if (Abs (aScaleX - 1.f) > Precision::Confusion())
- {
- aCtx->SetGlNormalizeEnabled (Standard_True);
- }
+ aCtx->ModelWorldState.Push();
+ aCtx->ModelWorldState.SetCurrent (Transformation);
+
+ // detect scale transform
+ const Standard_Boolean anOldGlNormalize = aCtx->IsGlNormalizeEnabled();
+ const Standard_ShortReal aScaleX = Transformation.GetRow (0).xyz().SquareModulus();
+ if (Abs (aScaleX - 1.f) > Precision::Confusion())
+ {
+ aCtx->SetGlNormalizeEnabled (Standard_True);
}
+
if (TransformPersistence.Flags)
{
OpenGl_Mat4 aProjection = aCtx->ProjectionState.Current();
}
// Restore local transformation
- if (myTransformation)
- {
- aCtx->ModelWorldState.Pop();
- aCtx->SetGlNormalizeEnabled (anOldGlNormalize);
- }
+ aCtx->ModelWorldState.Pop();
+ aCtx->SetGlNormalizeEnabled (anOldGlNormalize);
if (TransformPersistence.Flags)
{
aCtx->ProjectionState.Pop();
//! Returns OpenGL face aspect.
const OpenGl_AspectFace* AspectFace() const { return myAspectFace; }
- //! Returns OpenGL transformation matrix.
- const OpenGl_Matrix* Transformation() const { return myTransformation; }
-
//! Returns structure modification state (for ray-tracing).
Standard_Size ModificationState() const { return myModificationState; }
protected:
- OpenGl_Matrix* myTransformation;
OpenGl_AspectLine* myAspectLine;
OpenGl_AspectFace* myAspectFace;
OpenGl_AspectMarker* myAspectMarker;
Handle(OpenGl_StructureShadow) aShadow = Handle(OpenGl_StructureShadow)::DownCast (theStructure);
myParent = aShadow.IsNull() ? theStructure : aShadow->myParent;
-
- Composition = myParent->Composition;
ContainsFacet = myParent->ContainsFacet;
IsInfinite = myParent->IsInfinite;
- for (Standard_Integer i = 0; i <= 3; ++i)
- {
- for (Standard_Integer j = 0; j <= 3; ++j)
- {
- Graphic3d_CStructure::Transformation[i][j] = myParent->Graphic3d_CStructure::Transformation[i][j];
- }
- }
+ Transformation = myParent->Transformation;
UpdateTransformation();
myInstancedStructure = const_cast<OpenGl_Structure*> (myParent->InstancedStructure());
//! Adds OpenGL groups to ray-traced scene geometry.
Standard_Boolean addRaytraceGroups (const OpenGl_Structure* theStructure,
const OpenGl_RaytraceMaterial& theStructMat,
- const Standard_ShortReal* theTransform,
+ const Graphic3d_Mat4* theTransform,
const Handle(OpenGl_Context)& theGlContext);
//! Creates ray-tracing material properties.
aStructMaterial = convertMaterial (theStructure->AspectFace(), theGlContext);
}
- Standard_ShortReal aStructTransform[16];
-
- if (theStructure->Transformation()->mat != NULL)
- {
- for (Standard_Integer i = 0; i < 4; ++i)
- {
- for (Standard_Integer j = 0; j < 4; ++j)
- {
- aStructTransform[j * 4 + i] = theStructure->Transformation()->mat[i][j];
- }
- }
- }
-
- Standard_Boolean aResult = addRaytraceGroups (theStructure, aStructMaterial,
- theStructure->Transformation()->mat ? aStructTransform : NULL, theGlContext);
+ Standard_Boolean aResult = addRaytraceGroups (theStructure, aStructMaterial, &theStructure->Transformation, theGlContext);
// Process all connected OpenGL structures
const OpenGl_Structure* anInstanced = theStructure->InstancedStructure();
if (anInstanced != NULL && anInstanced->IsRaytracable())
{
- aResult &= addRaytraceGroups (anInstanced, aStructMaterial,
- theStructure->Transformation()->mat ? aStructTransform : NULL, theGlContext);
+ aResult &= addRaytraceGroups (anInstanced, aStructMaterial, &theStructure->Transformation, theGlContext);
}
myStructureStates[theStructure] = StructState (theStructure);
// =======================================================================
Standard_Boolean OpenGl_View::addRaytraceGroups (const OpenGl_Structure* theStructure,
const OpenGl_RaytraceMaterial& theStructMat,
- const Standard_ShortReal* theTransform,
+ const Graphic3d_Mat4* theTransform,
const Handle(OpenGl_Context)& theGlContext)
{
for (OpenGl_Structure::GroupIterator aGroupIter (theStructure->DrawGroups()); aGroupIter.More(); aGroupIter.Next())
if (theTransform != NULL)
{
- aTransform->SetTransform (*(reinterpret_cast<const BVH_Mat4f*> (theTransform)));
+ aTransform->SetTransform (*theTransform);
}
aSet->SetProperties (aTransform);
if (theTransform != NULL)
{
- aTransform->SetTransform (*(reinterpret_cast<const BVH_Mat4f*> (theTransform)));
+ aTransform->SetTransform (*theTransform);
}
aSet->SetProperties (aTransform);