Set each Left/Right/Top/Bottom plane distance setter is deprecated.
Instead of that API, we make to use OrthographicSize.
Change-Id: I7da73713b112502f08820b78bfdf58cf999462e6
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 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.
// Enable debug log for test coverage
#define DEBUG_ENABLED 1
-#include "dali-scene3d/public-api/loader/camera-parameters.h"
#include <dali-test-suite-utils.h>
+#include <dali/devel-api/actors/camera-actor-devel.h>
#include <string_view>
+#include "dali-scene3d/public-api/loader/camera-parameters.h"
using namespace Dali;
using namespace Dali::Scene3D::Loader;
int UtcDaliCameraParameters(void)
{
- Quaternion qView = Quaternion(Radian(Degree(180.f)), Vector3::YAXIS);
+ Quaternion qView = Quaternion(Radian(Degree(180.f)), Vector3::YAXIS);
CameraParameters camParams;
camParams.matrix.SetTransformComponents(Vector3::ONE * 2.f,
- qView,
- Vector3::ZAXIS * -100.f);
- camParams.orthographicSize = Vector4{ -1.f, 1.f, -1.f, 1.f };
- camParams.yFov = Radian(M_PI * .5).radian;
- camParams.zNear = 1.f;
- camParams.zFar = 1000.f;
+ qView,
+ Vector3::ZAXIS * -100.f);
+ camParams.orthographicSize = 3.0f;
+ camParams.aspectRatio = 1.0f;
+ camParams.yFov = Degree(Radian(M_PI * .5)).degree;
+ camParams.zNear = 1.f;
+ camParams.zFar = 1000.f;
- Vector3 scale;
+ Vector3 scale;
Quaternion orientation;
- Vector3 position;
+ Vector3 position;
camParams.CalculateTransformComponents(position, orientation, scale);
DALI_TEST_EQUAL(scale, Vector3::ONE * 2.f);
DALI_TEST_EQUAL(orientation, Quaternion::IDENTITY); // 2 180 degrees rotations along y
DALI_TEST_EQUAL(position, Vector3::ZAXIS * -100.f);
TestApplication app;
- CameraActor camera = CameraActor::New();
- for (auto i : { false, true })
+ CameraActor camera = CameraActor::New();
+ for(auto i : {false, true})
{
camParams.isPerspective = i;
- auto viewProjection = camParams.GetViewProjection();
- Matrix view{ false };
+ auto viewProjection = camParams.GetViewProjection();
+ Matrix view{false};
Matrix::Multiply(view, Matrix(qView), camParams.matrix);
view.Invert();
DALI_TEST_EQUAL(viewProjection.GetView(), view);
DALI_TEST_EQUAL(camera.GetProperty(Actor::Property::POSITION).Get<Vector3>(), position);
DALI_TEST_EQUAL(camera.GetProperty(Actor::Property::ORIENTATION).Get<Quaternion>(), orientation);
DALI_TEST_EQUAL(camera.GetProperty(Actor::Property::SCALE).Get<Vector3>(), scale);
+
+ if(camParams.isPerspective)
+ {
+ DALI_TEST_EQUAL(camera.GetProperty(Dali::CameraActor::Property::FIELD_OF_VIEW).Get<float>(), Radian(Degree(camParams.yFov)).radian);
+ }
+ else
+ {
+ DALI_TEST_EQUAL(camera.GetProperty(Dali::DevelCameraActor::Property::ORTHOGRAPHIC_SIZE).Get<float>(), camParams.orthographicSize);
+ }
}
END_TEST;
{Vector3(-1.0f, -1.0f, 1.0f)},
{Vector3(1.0f, -1.0f, 1.0f)}};
- Dali::Shader shaderSkybox = Shader::New(SHADER_SKYBOX_SHADER_VERT.data(), SHADER_SKYBOX_SHADER_FRAG.data());
- Dali::VertexBuffer vertexBuffer = Dali::VertexBuffer::New(Property::Map().Add("aPosition", Property::VECTOR3));
+ Dali::Shader shaderSkybox = Shader::New(SHADER_SKYBOX_SHADER_VERT.data(), SHADER_SKYBOX_SHADER_FRAG.data());
+ Dali::VertexBuffer vertexBuffer = Dali::VertexBuffer::New(Property::Map().Add("aPosition", Property::VECTOR3));
vertexBuffer.SetData(skyboxVertices, sizeof(skyboxVertices) / sizeof(Vertex));
Dali::Geometry skyboxGeometry = Geometry::New();
skyboxGeometry.AddVertexBuffer(vertexBuffer);
skyboxGeometry.SetType(Geometry::TRIANGLES);
- Dali::Texture skyboxTexture = Dali::Scene3D::Loader::LoadCubeMap(skyboxUrl);
+ Dali::Texture skyboxTexture = Dali::Scene3D::Loader::LoadCubeMap(skyboxUrl);
Dali::TextureSet skyboxTextures = TextureSet::New();
skyboxTextures.SetTexture(0, skyboxTexture);
Vector3 size = Self().GetProperty<Vector3>(Dali::Actor::Property::SIZE);
const float aspectRatio = size.width / size.height;
mSelectedCamera.SetAspectRatio(aspectRatio);
- const bool projectionVertical = mSelectedCamera.GetProperty<int>(Dali::DevelCameraActor::Property::PROJECTION_DIRECTION) == Dali::DevelCameraActor::VERTICAL;
-
- // if projectionVertical, Top / Bottom is +-ve to keep consistency with orthographic values
- // else, Left / Right is +-ve to keep consistency with orthographic values
- const float orthographicSize = DALI_LIKELY(projectionVertical) ? mSelectedCamera[Dali::CameraActor::Property::TOP_PLANE_DISTANCE] : mSelectedCamera[Dali::CameraActor::Property::RIGHT_PLANE_DISTANCE];
- const float halfHeight = DALI_LIKELY(projectionVertical) ? orthographicSize : orthographicSize / aspectRatio;
- const float halfWidth = DALI_LIKELY(projectionVertical) ? orthographicSize * aspectRatio : orthographicSize;
-
- mSelectedCamera[Dali::CameraActor::Property::LEFT_PLANE_DISTANCE] = -halfWidth;
- mSelectedCamera[Dali::CameraActor::Property::RIGHT_PLANE_DISTANCE] = halfWidth;
- mSelectedCamera[Dali::CameraActor::Property::TOP_PLANE_DISTANCE] = halfHeight;
- mSelectedCamera[Dali::CameraActor::Property::BOTTOM_PLANE_DISTANCE] = -halfHeight;
if(mUseFrameBuffer)
{
*/
#include "dali-scene3d/public-api/loader/camera-parameters.h"
#include "dali-scene3d/public-api/loader/utils.h"
+#include "dali/devel-api/actors/camera-actor-devel.h"
#include "dali/integration-api/debug.h"
#include "dali/public-api/actors/camera-actor.h"
#include "dali/public-api/math/quaternion.h"
else
{
Orthographic(viewProjection.GetProjection(),
- orthographicSize.x,
- orthographicSize.y,
- orthographicSize.z,
- orthographicSize.w,
+ -orthographicSize * aspectRatio,
+ orthographicSize * aspectRatio,
+ orthographicSize,
+ -orthographicSize,
zNear,
zFar,
true);
else
{
camera.SetProjectionMode(Camera::ORTHOGRAPHIC_PROJECTION);
- camera.SetOrthographicProjection(orthographicSize.x,
- orthographicSize.y,
- orthographicSize.z,
- orthographicSize.w,
- zNear,
- zFar);
+ camera.SetNearClippingPlane(zNear);
+ camera.SetFarClippingPlane(zFar);
+ camera.SetAspectRatio(aspectRatio);
+ camera.SetProperty(Dali::DevelCameraActor::Property::ORTHOGRAPHIC_SIZE, orthographicSize);
}
// model
{
struct DALI_SCENE3D_API CameraParameters
{
- Matrix matrix = Matrix::IDENTITY;
- Vector4 orthographicSize = Vector4{-1.f, 1.f, 1.f, -1.f};
- float yFov = 60.f;
- float zNear = 0.1f;
- float zFar = 1000.f;
- bool isPerspective = true;
+ Matrix matrix = Matrix::IDENTITY;
+ float orthographicSize = 1.f;
+ float aspectRatio = 1.f;
+ float yFov = 60.f;
+ float zNear = 0.1f;
+ float zFar = 1000.f;
+ bool isPerspective = true;
/**
* @return The view-projection matrix of the camera.
void DliLoader::Impl::ParseSceneInternal(Index iScene, const Toolkit::TreeNode* tnScenes, const Toolkit::TreeNode* tnNodes, LoadParams& params)
{
- auto getSceneRootIdx = [tnScenes, tnNodes](Index iScene)
- {
+ auto getSceneRootIdx = [tnScenes, tnNodes](Index iScene) {
auto tn = GetNthChild(tnScenes, iScene); // now a "scene" object
if(!tn)
{
{
if(const TreeNode* jsonCameras = mParser.GetRoot()->GetChild("cameras"))
{
+ float dummyFloatArray[4];
+
cameras.resize(jsonCameras->Size());
auto iCamera = cameras.begin();
for(auto i0 = jsonCameras->CBegin(), i1 = jsonCameras->CEnd(); i0 != i1; ++i0)
ReadFloat(jsonCamera.GetChild("fov"), iCamera->yFov);
ReadFloat(jsonCamera.GetChild("near"), iCamera->zNear);
ReadFloat(jsonCamera.GetChild("far"), iCamera->zFar);
- if(ReadVector(jsonCamera.GetChild("orthographic"), iCamera->orthographicSize.AsFloat(), 4u))
+ if(ReadVector(jsonCamera.GetChild("orthographic"), dummyFloatArray, 4u))
{
iCamera->isPerspective = false;
+
+ iCamera->orthographicSize = dummyFloatArray[2] * 0.5f;
+ iCamera->aspectRatio = dummyFloatArray[1] / dummyFloatArray[2];
}
if(auto jsonMatrix = jsonCamera.GetChild("matrix"))
else
{
auto& ortho = camera.mOrthographic;
- camParams.orthographicSize = Vector4(-ortho.mXMag, ortho.mXMag, ortho.mYMag, -ortho.mYMag) * .5f;
+ camParams.orthographicSize = ortho.mYMag * .5f;
+ camParams.aspectRatio = ortho.mXMag / ortho.mYMag;
camParams.zNear = ortho.mZNear;
camParams.zFar = ortho.mZFar;
}
/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 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.
// EXTERNAL INCLUDES
#include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
+#include <dali/devel-api/actors/camera-actor-devel.h>
#include <dali/devel-api/adaptor-framework/file-stream.h>
#include <dali/devel-api/adaptor-framework/image-loading.h>
#include <dali/integration-api/debug.h>
template<typename T>
bool ReadBinFile(Vector<T>& dataBuffer, std::string url, int32_t offset, int32_t count)
{
- size_t readCount = 0;
+ size_t readCount = 0;
Dali::FileStream fileStream(url, FileStream::READ | FileStream::BINARY);
FILE* fp = fileStream.GetFile();
if(fp)
if(cameraInfo.type == "orthographic")
{
LoadOrthoGraphic((*cameraIter).second, cameraInfo);
- float xMag_2 = cameraInfo.orthographic.xmag / 2.0;
- float yMag_2 = cameraInfo.orthographic.ymag / 2.0;
- cameraActor.SetOrthographicProjection(-xMag_2, xMag_2, yMag_2, -yMag_2, cameraInfo.orthographic.znear, cameraInfo.orthographic.zfar);
+ float xMag_2 = cameraInfo.orthographic.xmag / 2.0;
+ float yMag_2 = cameraInfo.orthographic.ymag / 2.0;
+ const float aspect = xMag_2 / yMag_2;
+
+ cameraActor.SetProjectionMode(Dali::Camera::ORTHOGRAPHIC_PROJECTION);
+ cameraActor.SetProperty(Dali::DevelCameraActor::Property::ORTHOGRAPHIC_SIZE, yMag_2);
+
+ cameraActor.SetNearClippingPlane(cameraInfo.orthographic.znear);
+ if(cameraInfo.orthographic.zfar > 0.0)
+ {
+ cameraActor.SetFarClippingPlane(cameraInfo.orthographic.zfar);
+ }
+ if(aspect > 0.0f) // Avoid divide-by-zero logic
+ {
+ cameraActor.SetAspectRatio(aspect);
+ }
}
else if(cameraInfo.type == "perspective")
{
actor.SetProperty(Actor::Property::POSITION, translation);
float hasLightSource = static_cast<float>(!!(scene3dView.GetLightType() & (Toolkit::Scene3dView::LightType::POINT_LIGHT | Toolkit::Scene3dView::LightType::DIRECTIONAL_LIGHT)));
- float isPointLight = static_cast<float>(!!(scene3dView.GetLightType() & Toolkit::Scene3dView::LightType::POINT_LIGHT));
+ float isPointLight = static_cast<float>(!!(scene3dView.GetLightType() & Toolkit::Scene3dView::LightType::POINT_LIGHT));
shader.RegisterProperty("uHasLightSource", hasLightSource);
shader.RegisterProperty("uIsPointLight", isPointLight);
shader.RegisterProperty("uLightVector", scene3dView.GetLightVector());