/*---------------------------------------------------------------------------* Project: NintendoWare File: gfx_OrthoProjectionUpdater.cpp Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo and/or its licensed developers and are protected by national and international copyright laws. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. The content herein is highly confidential and should be handled accordingly. $Revision: 31311 $ *---------------------------------------------------------------------------*/ #include "precompiled.h" #include #include #include namespace nw { namespace gfx { NW_UT_RUNTIME_TYPEINFO_DEFINITION(OrthoProjectionUpdater,CameraProjectionUpdater); //---------------------------------------- OrthoProjectionUpdater* OrthoProjectionUpdater::Create(os::IAllocator* allocator) { NW_NULL_ASSERT(allocator); void* updaterMemory = allocator->Alloc(sizeof(OrthoProjectionUpdater)); NW_NULL_ASSERT(updaterMemory); void* dataMemory = AllocateAndFill(allocator, 0); ResOrthoProjectionUpdaterData* buffer = new(dataMemory) ResOrthoProjectionUpdaterData(); buffer->typeInfo = ResOrthoProjectionUpdater::TYPE_INFO; buffer->m_Near = PROJECTION_NEAR_CLIP; buffer->m_Far = PROJECTION_FAR_CLIP; buffer->m_Rect.m_AspectRatio = PROJECTION_ASPECT_RATIO; buffer->m_Rect.m_Center = PROJECTION_CENTER; buffer->m_Rect.m_Height = PROJECTION_HEIGHT; ResOrthoProjectionUpdater resUpdater = ResOrthoProjectionUpdater(buffer); return new(updaterMemory) OrthoProjectionUpdater(allocator, true, resUpdater); } //---------------------------------------- OrthoProjectionUpdater* OrthoProjectionUpdater::Create( os::IAllocator* allocator, ResOrthoProjectionUpdater resUpdater) { NW_NULL_ASSERT(allocator); void* updaterMemory = allocator->Alloc(sizeof(OrthoProjectionUpdater)); NW_NULL_ASSERT(updaterMemory); return new(updaterMemory) OrthoProjectionUpdater(allocator, false, resUpdater); } //---------------------------------------- OrthoProjectionUpdater::OrthoProjectionUpdater( os::IAllocator* allocator, bool isDynamic, ResOrthoProjectionUpdater resUpdater ) : CameraProjectionUpdater(allocator, isDynamic), m_Resource(resUpdater) { } //---------------------------------------- OrthoProjectionUpdater::~OrthoProjectionUpdater() { if (this->IsDynamic() && this->m_Resource.IsValid()) { this->GetAllocator().Free(m_Resource.ptr()); } } //---------------------------------------- void OrthoProjectionUpdater::Update(math::MTX44* projectionMatrix, math::MTX34* textureProjectionMatrix) { NW_ASSERT(m_Resource.IsValid()); NW_ASSERT(m_Resource.GetRect().GetAspectRatio() != 0); NW_ASSERT(m_Resource.GetRect().GetHeight() != 0); float halfWidth = m_Resource.GetRect().GetWidth() / 2.0f; float halfHeight = m_Resource.GetRect().GetHeight() / 2.0f; float left = m_Resource.GetRect().GetCenter().x - halfWidth; float right = m_Resource.GetRect().GetCenter().x + halfWidth; float bottom = m_Resource.GetRect().GetCenter().y - halfHeight; float top = m_Resource.GetRect().GetCenter().y + halfHeight; float near = m_Resource.GetNear(); float far = m_Resource.GetFar(); NW_ASSERT(near != far); math::MTX44OrthoPivot( projectionMatrix, left, right, bottom, top, near, far, this->GetPivotDirection()); math::MTX34TextureProjectionOrtho( textureProjectionMatrix, left, right, bottom, top, this->TextureScale().x, this->TextureScale().y, this->TextureTranslate().x, this->TextureTranslate().y); } } // namespace gfx } // namespace nw