--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include <dali/internal/common/math.h>
+
+//EXTERNAL INCLUDES
+#include <cmath>
+
+void Dali::Internal::TransformVector3( Vec3 result, const Mat4 m, const Vec3 v )
+{
+#ifndef __ARM_NEON__
+
+ result[0] = v[0] * m[0] + v[1] * m[4] + v[2] * m[8];
+ result[1] = v[0] * m[1] + v[1] * m[5] + v[2] * m[9];
+ result[2] = v[0] * m[2] + v[1] * m[6] + v[2] * m[10];
+
+#else
+
+ Vec4 temp = { v[0], v[1], v[2], 0.0f };
+ Vec4 tempResult;
+
+ asm volatile ( "VLD1.F32 {q0}, [%1] \n\t" //Load "temp" from memory to register q0
+ "VLD1.F32 {q1}, [%0]! \n\t" //Load first row of the matrix from memory to register q1
+ "VMUL.F32 q2, q1, d0[0] \n\t" //q2 = (m[0..3] * v.x)
+ "VLD1.F32 {q1}, [%0]! \n\t" //Load second row of the matrix from memory
+ "VMLA.F32 q2, q1, d0[1] \n\t" //q2 = (m[0..3] * v.x) + (m[4..7] * v.y)
+ "VLD1.F32 {q1}, [%0]! \n\t" //Load third row of the matrix from memory
+ "VMLA.F32 q2, q1, d1[0] \n\t" //q2 = (m[0..3] * v.x) + (m[4..7] * v.y) + (m[8...11] * v.z)
+ "VST1.F32 {q2}, [%2] \n\t" //Write the result back to memory
+ :
+ : "r"(m), "r"(temp), "r"(tempResult)
+ : "q0", "q1", "q2", "memory" );
+
+ result[0] = tempResult[0];
+ result[1] = tempResult[1];
+ result[2] = tempResult[2];
+
+#endif
+}
+
+float Dali::Internal::Length( const Vec3 v )
+{
+ return sqrtf(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
+}
--- /dev/null
+#ifndef __DALI_INTERNAL_MATH_H__
+#define __DALI_INTERNAL_MATH_H__
+
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+namespace Dali
+{
+
+namespace Internal
+{
+
+typedef float Vec3[3];
+typedef float Vec4[4];
+typedef float Mat4[16];
+
+/**
+ * @brief Applies a transformation matrix to a vector
+ *
+ * @param[out] result The transformed vector
+ * @param[in] m The transformation matrix
+ * @param[in] v The vector to transform
+ */
+void TransformVector3( Vec3 result, const Mat4 m, const Vec3 v );
+
+/**
+ * @brief Computes the length of a vector3
+ *
+ * @param[in] v The vector
+ * @return The lenght of the vector
+ */
+float Length( const Vec3 v );
+
+} // namespace Internal
+
+} // namespace Dali
+
+#endif //__DALI_INTERNAL_MATH_H__
$(internal_src_dir)/common/blending-options.cpp \
$(internal_src_dir)/common/core-impl.cpp \
$(internal_src_dir)/common/internal-constants.cpp \
+ $(internal_src_dir)/common/math.cpp \
$(internal_src_dir)/common/message-buffer.cpp \
$(internal_src_dir)/common/mutex-impl.cpp \
$(internal_src_dir)/common/image-sampler.cpp \
}
/**
- * Sets the size of the render item
- * @param[in] size The size of the render item
+ * Retrives the size of the render item
+ * @return The size of the render item
*/
- void SetSize( const Vector3& size)
+ const Vector3& GetSize() const
{
- mSize = size;
+ return mSize;
}
/**
* Retrives the size of the render item
* @return The size of the render item
*/
- const Vector3& GetSize() const
+ Vector3& GetSize()
{
return mSize;
}
bool cull )
{
bool inside( true );
-
- const Matrix& worldMatrix = renderable.mNode->GetWorldMatrix( updateBufferIndex );
- const Vector3& size = renderable.mNode->GetSize( updateBufferIndex );
if ( cull && !renderable.mRenderer->GetShader().HintEnabled( Dali::Shader::HINT_MODIFIES_GEOMETRY ) )
{
- const Vector3& position = worldMatrix.GetTranslation3();
- float radius( size.Length() * 0.5f );
-
- inside = (radius > Math::MACHINE_EPSILON_1000) &&
- (cameraAttachment.CheckSphereInFrustum( updateBufferIndex, position, radius ) );
+ const Vector4& boundingSphere = renderable.mNode->GetBoundingSphere();
+ inside = (boundingSphere.w > Math::MACHINE_EPSILON_1000) &&
+ (cameraAttachment.CheckSphereInFrustum( updateBufferIndex, Vector3(boundingSphere), boundingSphere.w ) );
}
if ( inside )
item.SetDepthIndex( renderable.mRenderer->GetDepthIndex() + static_cast<int>( renderable.mNode->GetDepth() ) * Dali::Layer::TREE_DEPTH_MULTIPLIER );
}
// save MV matrix onto the item
+ const Matrix& worldMatrix = renderable.mNode->GetWorldMatrixAndSize( item.GetSize() );
Matrix::Multiply( item.GetModelViewMatrix(), worldMatrix, viewMatrix );
- item.SetSize( size );
}
}
}
//INTERNAL INCLUDES
#include <dali/public-api/common/constants.h>
#include <dali/public-api/common/compile-time-assert.h>
+#include <dali/internal/common/math.h>
namespace Dali
{
mParent.PushBack(INVALID_TRANSFORM_ID);
mWorld.PushBack(Matrix::IDENTITY);
mLocal.PushBack(Matrix::IDENTITY);
+ mBoundingSpheres.PushBack( Vector4(0.0f,0.0f,0.0f,0.0f) );
mTxComponentAnimatableBaseValue.PushBack(TransformComponentAnimatable());
mSizeBase.PushBack(Vector3(0.0f,0.0f,0.0f));
mComponentDirty.PushBack(false);
mParent[mComponentCount] = INVALID_TRANSFORM_ID;
mLocal[mComponentCount].SetIdentity();
mWorld[mComponentCount].SetIdentity();
+ mBoundingSpheres[mComponentCount] = Vector4(0.0f,0.0f,0.0f,0.0f);
mSizeBase[mComponentCount] = Vector3(0.0f,0.0f,0.0f);
mComponentDirty[mComponentCount] = false;
mLocalMatrixDirty[mComponentCount] = false;
mSizeBase[index] = mSizeBase[mComponentCount];
mComponentDirty[index] = mComponentDirty[mComponentCount];
mLocalMatrixDirty[index] = mLocalMatrixDirty[mComponentCount];
+ mBoundingSpheres[index] = mBoundingSpheres[mComponentCount];
TransformId lastItemId = mComponentId[mComponentCount];
mIds[ lastItemId ] = index;
mLocal[i].SetTransformComponents( mTxComponentAnimatable[i].mScale,mTxComponentAnimatable[i].mOrientation, localPosition );
}
+ //Update the world matrix
Matrix::Multiply( mWorld[i], mLocal[i], mWorld[parentIndex]);
}
else
localPosition = mTxComponentAnimatable[i].mPosition + anchorPosition;
mWorld[i].SetTransformComponents( mTxComponentAnimatable[i].mScale, mTxComponentAnimatable[i].mOrientation, localPosition );
}
+
+ //Update the bounding sphere
+ Vec3 centerToEdge = { mSize[i].Length() * 0.5f, 0.0f, 0.0f };
+ Vec3 centerToEdgeWorldSpace;
+ TransformVector3( centerToEdgeWorldSpace, mWorld[i].AsFloat(), centerToEdge );
+
+ mBoundingSpheres[i] = mWorld[i].GetTranslation();
+ mBoundingSpheres[i].w = Length( centerToEdgeWorldSpace );
}
}
std::swap( mSizeBase[i], mSizeBase[j] );
std::swap( mLocal[i], mLocal[j] );
std::swap( mComponentDirty[i], mComponentDirty[j] );
+ std::swap( mBoundingSpheres[i], mBoundingSpheres[j] );
mIds[ mComponentId[i] ] = i;
mIds[ mComponentId[j] ] = j;
mComponentDirty[ index ] = true;
}
+const Vector4& TransformManager::GetBoundingSphere( TransformId id ) const
+{
+ return mBoundingSpheres[ mIds[id] ];
+}
+
+const Matrix& TransformManager::GetWorldMatrixAndSize( TransformId id, Vector3& size ) const
+{
+ unsigned int index = mIds[id];
+ size = mSize[index];
+ return mWorld[index];
+}
+
} //namespace SceneGraph
} //namespace Internal
} //namespace Dali
*/
void BakeRelativeQuaternionPropertyValue( TransformId id, const Quaternion& q );
+ /**
+ * Get the bounding sphere, in world coordinates, of a given component
+ * @param[in] id Id of the transform component
+ * @return The world space bounding sphere of the component
+ */
+ const Vector4& GetBoundingSphere( TransformId id ) const;
+
+ /**
+ * Get the world matrix and size of a given component
+ * @param[in] id Id of the transform component
+ * @param[out] size size of the component
+ * @return The world matrix of the component
+ */
+ const Matrix& GetWorldMatrixAndSize( TransformId id, Vector3& size ) const;
+
private:
//Helper struct to order components
Vector<TransformId> mParent; ///< Parent of the components
Vector<Matrix> mWorld; ///< Local to world transform of the components
Vector<Matrix> mLocal; ///< Local to parent space transform of the components
+ Vector<Vector4> mBoundingSpheres; ///< Bounding spheres. xyz is the center and w is the radius
Vector<TransformComponentAnimatable> mTxComponentAnimatableBaseValue; ///< Base values for the animatable part of the components
Vector<Vector3> mSizeBase; ///< Base value for the size of the components
Vector<bool> mComponentDirty; ///< 1u if some of the parts of the component has changed in this frame, 0 otherwise
Vector<bool> mLocalMatrixDirty; ///< 1u if the local matrix has been updated in this frame, 0 otherwise
Vector<SOrderItem> mOrderedComponents; ///< Used to reorder components when hierarchy changes
bool mReorder; ///< Flag to determine if the components have to reordered in the next Update
-
};
} //namespace SceneGraph
}
/**
+ * Retrieve the bounding sphere of the node
+ * @return A vector4 describing the bounding sphere. XYZ is the center and W is the radius
+ */
+ const Vector4& GetBoundingSphere() const
+ {
+ if( mTransformId != INVALID_TRANSFORM_ID )
+ {
+ return mTransformManager->GetBoundingSphere( mTransformId );
+ }
+
+ return Vector4::ZERO;
+ }
+
+ /**
+ * Retrieve world matrix and size of the node
+ *
+ * @param[out] size The current size of the node
+ * @return The local to world matrix of the node
+ */
+ const Matrix& GetWorldMatrixAndSize( Vector3& size ) const
+ {
+ if( mTransformId != INVALID_TRANSFORM_ID )
+ {
+ return mTransformManager->GetWorldMatrixAndSize( mTransformId, size );
+ }
+ return Matrix::IDENTITY;
+ }
+
+ /**
* Checks if local matrix has changed since last update
* @return true if local matrix has changed, false otherwise
*/