//---------------------------------------------------------------------------- Scene::Scene() : mIsShowHelpNode(true), mIsOverrideWireFrame(false), mIsUseBloom(false), mIsBloomRenderTargetSizeSameWithScreen(false), mBloomRenderTargetSize(Float2(512.0f, 512.0f)), mBloomBrightWeight(0.3f), mBloomBlurDeviation(1.0f), mBloomBlurWeight(1.0f), mBloomWeight(1.0f), mBloomBrightParam(Float4::ZERO), mBloomParam(Float4::UNIT), mIsUseShadowMap(false), mIsShadowRenderTargetSizeSameWithScreen(false), mShadowRenderTargetSize(Float2(512.0f, 512.0f)) { SetName("Scene"); mEnvirParam = new0 EnvirParam(); CameraActor *camActor = new0 CameraActor(); AttachChild(camActor); camActor->SetName("DefaultCameraActor"); camActor->LocalTransform.SetTranslate(APoint(0.0f, -5.0f, 1.0f)); SetUseCameraActor(camActor); mDefaultAmbientRegionActor = new0 AmbientRegionActor(); AttachChild(mDefaultAmbientRegionActor); mDefaultAmbientRegionActor->SetName("DefaultAmbientRegionActor"); SetColor(Float3::WHITE); mIsShowHelpNode = true; }
//---------------------------------------------------------------------------- void EditRenderView_Scene::_RolateCamera(float horz, float vert) { Scene *scene = PX2_PROJ.GetScene(); CameraActor *camActor = scene->GetUseCameraActor(); if (VT_PERSPECTIVE == mViewType) { AVector rVector; AVector dVector; AVector uVector; camActor->GetRDUVector(rVector, dVector, uVector); // horz HMatrix incrH(AVector::UNIT_Z, -horz*0.5f); dVector = incrH * dVector; uVector = incrH * uVector; rVector = incrH * rVector; // vert Matrix3f kIncrV(rVector, -vert*0.5f); dVector = kIncrV * dVector; uVector = kIncrV * uVector; dVector.Normalize(); float dVectorAdj = dVector.Dot(AVector::UNIT_Z); float dVectorAdj1 = dVector.Dot(-AVector::UNIT_Z); if (dVectorAdj > 0.9f || dVectorAdj1 > 0.9f) return; AVector::Orthonormalize(dVector, uVector, rVector); camActor->LocalTransform.SetRotate(HMatrix(rVector, dVector, uVector, AVector::ZERO, true)); } }
int UtcDaliObjectRegistrySignalCameraCreated(void) { TestApplication application; ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry(); bool verified = false; TestCameraActorCallback test(verified); Dali::RefObject* objectPointer = NULL; TestObjectDestroyedCallback test2(verified, objectPointer); registry.ObjectCreatedSignal().Connect(&application, test); registry.ObjectDestroyedSignal().Connect(&application, test2); { CameraActor actor = CameraActor::New(); DALI_TEST_CHECK( test.mSignalVerified ); verified = false; objectPointer = actor.GetObjectPtr(); } DALI_TEST_CHECK( test.mSignalVerified ); END_TEST; }
//---------------------------------------------------------------------------- void EditRenderView_Scene::_RoundCamera(float horz, float vert) { Scene *scene = PX2_PROJ.GetScene(); CameraActor *camActor = scene->GetUseCameraActor(); if (mViewType == VT_PERSPECTIVE) { PX2::Object *obj = PX2_SELECTION.GetFirstObject(); bool hasTarget = false; APoint pos; Movable *mov = DynamicCast<Movable>(obj); if (mov) { pos = mov->WorldTransform.GetTranslate(); hasTarget = true; } if (hasTarget) { const APoint &camPos = camActor->LocalTransform.GetTranslate(); AVector rVector; AVector dVector; AVector uVector; camActor->GetRDUVector(rVector, dVector, uVector); AVector targetDir = pos - camPos; float targetLength = targetDir.Normalize(); // horz HMatrix incrH(AVector::UNIT_Z, -horz*0.1f); targetDir = incrH * targetDir; dVector = incrH * dVector; uVector = incrH * uVector; rVector = incrH * rVector; HMatrix incrV(rVector, -vert*0.1f); targetDir = incrV * targetDir; dVector = incrV * dVector; uVector = incrV * uVector; APoint newPos = pos - targetDir*targetLength; camActor->LocalTransform.SetTranslate(newPos); AVector::Orthonormalize(dVector, uVector, rVector); camActor->LocalTransform.SetRotate( HMatrix(rVector, dVector, uVector, AVector::ZERO, true)); } } }
//---------------------------------------------------------------------------- void EditRenderView_Scene::_MoveCamera(float horz, float vert) { Scene *scene = PX2_PROJ.GetScene(); if (!scene) return; CameraActor *camActor = scene->GetUseCameraActor(); if (camActor) { APoint position = camActor->LocalTransform.GetTranslate(); AVector rVector; AVector dVector; AVector uVector; camActor->GetRDUVector(rVector, dVector, uVector); if (mViewType == VT_PERSPECTIVE) { dVector.Z() = 0.0f; dVector.Normalize(); rVector.Z() = 0.0f; rVector.Normalize(); position += dVector * vert; position -= rVector * horz; } else if (mViewType == VT_TOP) { position.Y() += vert * 1.0f; position.X() -= horz * 1.0f; } else if (mViewType == VT_LEFT) { position.Z() += vert * 1.0f; position.Y() += horz * 1.0f; } else if (mViewType == VT_FRONT) { position.Z() += vert * 1.0f; position.X() -= horz * 1.0f; } camActor->LocalTransform.SetTranslate(position); } }
//---------------------------------------------------------------------------- void Project::SetScene(Scene *scene) { if (mScene) { mScene->GoOutEventWorld(); mScene = 0; mSceneRenderStep->SetCamera(0); PX2_GR.SetCurEnvirParam(0); } mScene = scene; mSceneRenderStep->SetNode(mScene); if (mScene) { mScene->ComeInEventWorld(); PX2_GR.SetCurEnvirParam(mScene->GetEnvirParam()); CameraActor *camActor = mScene->GetUseCameraActor(); if (camActor) { Camera *camera = camActor->GetCamera(); Renderer::GetDefaultRenderer()->SetCamera(camera); mSceneRenderStep->SetCamera(camera); } else { mSceneRenderStep->SetCamera(0); } } else { mSceneRenderStep->SetCamera(0); } //mSceneRenderStep->SetSize(mSize); }
//---------------------------------------------------------------------------- void EditRenderView_Scene::_ZoomCamera(float zoom) { RenderStep *renderStep = PX2_PROJ.GetSceneRenderStep(); const Sizef &size = renderStep->GetSize(); Scene *scene = PX2_PROJ.GetScene(); if (!scene) return; CameraActor *camActor = scene->GetUseCameraActor(); if (camActor) { APoint position = camActor->LocalTransform.GetTranslate(); AVector dir = camActor->GetCamera()->GetDVector(); dir.Normalize(); if (VT_PERSPECTIVE == mViewType) { position += dir*zoom; camActor->LocalTransform.SetTranslate(position); } else if (VT_TOP == mViewType) { float rMin = 0.0f; float rMax = 0.0f; float uMin = 0.0f; float uMax = 0.0f; float dMin = 0.0f; float dMax = 0.0f; float orthoFrustumMin = 1.0f; camActor->GetCamera()->GetFrustum(dMin, dMax, uMin, uMax, rMin, rMax); uMin += (zoom * 1.0f); if (uMin > -orthoFrustumMin) uMin = -orthoFrustumMin; uMax = -uMin; rMin = uMin * size.Width / size.Height; rMax = -rMin; camActor->GetCamera()->SetFrustum(dMin, dMax, uMin, uMax, rMin, rMax); } else if (VT_FRONT == mViewType) { float rMin = 0.0f; float rMax = 0.0f; float uMin = 0.0f; float uMax = 0.0f; float dMin = 0.0f; float dMax = 0.0f; float orthoFrustumMin = 1.0f; camActor->GetCamera()->GetFrustum(dMin, dMax, uMin, uMax, rMin, rMax); uMin += (zoom * 1.0f); if (uMin > -orthoFrustumMin) uMin = -orthoFrustumMin; uMax = -uMin; rMin = uMin * size.Width / size.Height; rMax = -rMin; camActor->GetCamera()->SetFrustum(dMin, dMax, uMin, uMax, rMin, rMax); } } }
int UtcDaliHoverOutsideCameraNearFarPlanes(void) { TestApplication application; Stage stage = Stage::GetCurrent(); Vector2 stageSize = stage.GetSize(); Actor actor = Actor::New(); actor.SetSize(100.0f, 100.0f); actor.SetAnchorPoint(AnchorPoint::CENTER); actor.SetParentOrigin(ParentOrigin::CENTER); stage.Add(actor); // Render and notify application.SendNotification(); application.Render(); // Get the camera's near and far planes RenderTaskList taskList = stage.GetRenderTaskList(); Dali::RenderTask task = taskList.GetTask(0); CameraActor camera = task.GetCameraActor(); float nearPlane = camera.GetNearClippingPlane(); float farPlane = camera.GetFarClippingPlane(); // Calculate the current distance of the actor from the camera float tanHalfFov = tanf(camera.GetFieldOfView() * 0.5f); float distance = (stageSize.y * 0.5f) / tanHalfFov; // Connect to actor's hovered signal SignalData data; HoverEventFunctor functor( data ); actor.HoveredSignal().Connect( &application, functor ); Vector2 screenCoordinates( stageSize.x * 0.5f, stageSize.y * 0.5f ); // Emit a started signal application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) ); DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION ); data.Reset(); // Emit a started signal where actor is just at the camera's near plane actor.SetZ(distance - nearPlane); // Render and notify application.SendNotification(); application.Render(); application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) ); DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION ); data.Reset(); // Emit a started signal where actor is closer than the camera's near plane actor.SetZ((distance - nearPlane) + 1.0f); // Render and notify application.SendNotification(); application.Render(); application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) ); DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION ); data.Reset(); // Emit a started signal where actor is just at the camera's far plane actor.SetZ(distance - farPlane); // Render and notify application.SendNotification(); application.Render(); application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) ); DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION ); data.Reset(); // Emit a started signal where actor is further than the camera's far plane actor.SetZ((distance - farPlane) - 1.0f); // Render and notify application.SendNotification(); application.Render(); application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) ); DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION ); data.Reset(); END_TEST; }