/*---------------------------------------------------------------------------* Project: NintendoWare File: gfx_FrustumProjectionUpdater.cpp Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. 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. $Revision: 28760 $ *---------------------------------------------------------------------------*/ #include "precompiled.h" #include #include #include namespace nw { namespace gfx { NW_UT_RUNTIME_TYPEINFO_DEFINITION(FrustumProjectionUpdater,CameraProjectionUpdater); //---------------------------------------- FrustumProjectionUpdater* FrustumProjectionUpdater::Create(os::IAllocator* allocator) { NW_NULL_ASSERT(allocator); void* updaterMemory = allocator->Alloc(sizeof(FrustumProjectionUpdater)); NW_NULL_ASSERT(updaterMemory); void* dataMemory = AllocateAndFill(allocator, 0); ResFrustumProjectionUpdaterData* buffer = new(dataMemory) ResFrustumProjectionUpdaterData(); buffer->typeInfo = ResFrustumProjectionUpdater::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; ResFrustumProjectionUpdater resUpdater = ResFrustumProjectionUpdater(buffer); return new(updaterMemory) FrustumProjectionUpdater(allocator, true, resUpdater); } //---------------------------------------- FrustumProjectionUpdater* FrustumProjectionUpdater::Create(os::IAllocator* allocator, ResFrustumProjectionUpdater resUpdater) { NW_NULL_ASSERT(allocator); void* updaterMemory = allocator->Alloc(sizeof(FrustumProjectionUpdater)); NW_NULL_ASSERT(updaterMemory); return new(updaterMemory) FrustumProjectionUpdater(allocator, false, resUpdater); } //---------------------------------------- FrustumProjectionUpdater::FrustumProjectionUpdater( os::IAllocator* allocator, bool isDynamic, ResFrustumProjectionUpdater resUpdater ) : CameraProjectionUpdater(allocator, isDynamic), m_Resource(resUpdater) { } //---------------------------------------- FrustumProjectionUpdater::~FrustumProjectionUpdater() { if (this->IsDynamic() && this->m_Resource.IsValid()) { this->GetAllocator().Free(m_Resource.ptr()); } } //---------------------------------------- void FrustumProjectionUpdater::Update(math::MTX44* projectionMatrix, math::MTX34* textureProjectionMatrix) { NW_ASSERT(m_Resource.IsValid()); 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(); math::MTX44FrustumPivot( projectionMatrix, left, right, bottom, top, near, far, this->GetPivotDirection()); math::MTX34TextureProjectionFrustum( textureProjectionMatrix, left, right, bottom, top, near, this->TextureScale().x, this->TextureScale().y, this->TextureTranslate().x, this->TextureTranslate().y); } } // namespace gfx } // namespace nw