/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
#include <dali/public-api/math/rect.h>
#include <dali/public-api/math/matrix.h>
#include <dali/public-api/math/vector4.h>
+#include <dali/public-api/math/vector2.h>
+#include <dali/public-api/math/viewport.h>
#include <dali/integration-api/debug.h>
+#include <dali/public-api/math/math-utils.h>
namespace Dali
{
bool XyPlaneIntersect( const Vector4& pointA, const Vector4& pointB, Vector4& intersect )
{
- const Vector4* near = NULL;
- const Vector4* far = NULL;
+ const Vector4* near = nullptr;
+ const Vector4* far = nullptr;
if ( pointA.z > 0.0f && pointB.z < 0.0f )
{
return true;
}
+bool ProjectFull( const Vector4& position,
+ const Matrix& modelView,
+ const Matrix& projection,
+ float viewportX,
+ float viewportY,
+ float viewportWidth,
+ float viewportHeight,
+ Vector4& windowPos )
+{
+ bool ok = false;
+
+ Matrix Mvp( false ); // Don't initialize.
+ Matrix::Multiply( Mvp, modelView, projection );
+
+ Vector4 p = Mvp * position;
+
+ Vector2 depthRange(0,1);
+
+ if( !EqualsZero( p.w ) )
+ {
+ float div = 1.0f / p.w;
+
+ windowPos = Vector4( (1 + p.x * div) * viewportWidth / 2 + viewportX,
+ (1 - p.y * div) * viewportHeight / 2 + viewportY,
+ (p.z * div) * (depthRange.y - depthRange.x) + depthRange.x,
+ div);
+ ok = true;
+ }
+
+ return ok;
+}
+
+
} // namespace Internal
} // namespace Dali