/*---------------------------------------------------------------------------* Project: NintendoWare File: gfx_FragmentLight.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: 29199 $ *---------------------------------------------------------------------------*/ #include "precompiled.h" #include #include #include #include namespace nw { namespace gfx { NW_UT_RUNTIME_TYPEINFO_DEFINITION(FragmentLight, Light); //---------------------------------------- FragmentLight* FragmentLight::DynamicBuilder::Create( os::IAllocator* allocator ) { NW_NULL_ASSERT(allocator); ResPtr resource( CreateResFragmentLight(allocator), ResFragmentLightDataDestroyer(allocator)); void* memory = allocator->Alloc(sizeof(FragmentLight)); NW_NULL_ASSERT(memory); FragmentLight* light = new(memory) FragmentLight( allocator, resource, m_Description); Result result = light->Initialize(allocator); NW_ASSERT(result.IsSuccess()); return light; } //---------------------------------------- FragmentLight* FragmentLight::Create( SceneNode* parent, ResSceneObject resource, const FragmentLight::Description& description, os::IAllocator* allocator ) { NW_NULL_ASSERT(allocator); ResFragmentLight resNode = ResDynamicCast(resource); NW_ASSERT(resNode.IsValid()); NW_ASSERT( internal::ResCheckRevision( resNode ) ); void* memory = allocator->Alloc(sizeof(FragmentLight)); NW_NULL_ASSERT(memory); FragmentLight* light = new(memory) FragmentLight( allocator, resNode, description); Result result = light->Initialize(allocator); NW_ASSERT(result.IsSuccess()); if (parent) { bool isAttached = parent->AttachChild(light); NW_ASSERT(isAttached); } return light; } //---------------------------------------- void FragmentLight::UpdateDirection() { ResFragmentLight resLight = this->GetResFragmentLight(); if (ut::CheckFlag(resLight.GetFlags(), ResFragmentLightData::FLAG_IS_INHERITING_DIRECTION_ROTATE)) { this->CalcInheritingDiretion(this->Direction(), resLight.GetDirection()); } else { this->Direction() = resLight.GetDirection(); } } //---------------------------------------- void FragmentLight::Accept( ISceneVisitor* visitor ) { visitor->VisitFragmentLight(this); AcceptChildren(visitor); } //----------------------------------------- /* static*/ ResFragmentLightData* FragmentLight::CreateResFragmentLight(os::IAllocator* allocator, const char* name /* = NULL */) { // TODO: 細かくアロケートする実装になっているが、まとめて確保できる仕組みも追加予定。 ResFragmentLightData* resFragmentLight = AllocateAndFillN(allocator, sizeof(ResFragmentLightData), 0); //-------------------------------- // ResSceneObjectData のメンバ初期化 resFragmentLight->typeInfo = ResFragmentLight::TYPE_INFO; resFragmentLight->m_Header.revision = ResLight::BINARY_REVISION; resFragmentLight->m_Header.signature = ResLight::SIGNATURE; resFragmentLight->m_UserDataDicCount = 0; resFragmentLight->toUserDataDic.set_ptr( NULL ); resFragmentLight->toName.set_ptr(AllocateAndCopyString(name, allocator, MAX_NAME_LENGTH)); //-------------------------------- // ResSceneNodeData のメンバ初期化 resFragmentLight->m_ChildrenTableCount = 0; resFragmentLight->toChildrenTable.set_ptr( NULL ); resFragmentLight->m_AnimGroupsDicCount = 0; resFragmentLight->toAnimGroupsDic.set_ptr( NULL ); //-------------------------------- // ResTransformNode のメンバ初期化 const math::VEC3 scale(1.0f, 1.0f, 1.0f); const math::VEC3 rotate(0.0f, 0.0f, 0.0f); const math::VEC3 translate(0.0f, 0.0, 0.0f); resFragmentLight->m_Transform = math::Transform3(scale, rotate, translate); resFragmentLight->m_WorldMatrix = math::MTX34::Identity(); //-------------------------------- // ResFragmentLightData のメンバ初期化 ResReferenceLookupTableData* distanceSampler = AllocateAndFill(allocator, 0); distanceSampler->typeInfo = ResReferenceLookupTable_TYPE_INFO; distanceSampler->toTargetLut.set_ptr(NULL); distanceSampler->toPath.set_ptr(NULL); ResLightingLookupTableData* angleSampler = AllocateAndFill(allocator, 0); ResReferenceLookupTableData* referenceAngleSampler = AllocateAndFill(allocator, 0); referenceAngleSampler->typeInfo = ResReferenceLookupTable_TYPE_INFO; referenceAngleSampler->toPath.set_ptr(NULL); referenceAngleSampler->toTargetLut.set_ptr(NULL); angleSampler->toSampler.set_ptr(referenceAngleSampler); angleSampler->m_Input = ResLightingLookupTable::INPUT_NH; angleSampler->m_Scale = ResLightingLookupTable::SCALE_1; resFragmentLight->toDistanceSampler.set_ptr( distanceSampler ); resFragmentLight->toAngleSampler.set_ptr( angleSampler ); return resFragmentLight; } //----------------------------------------- /* static */ void FragmentLight::DestroyResFragmentLight(os::IAllocator* allocator, ResFragmentLightData* resFragmentLight) { NW_NULL_ASSERT( allocator ); NW_NULL_ASSERT( resFragmentLight ); allocator->Free( resFragmentLight->toDistanceSampler.to_ptr() ); ResLightingLookupTableData* angleSampler = reinterpret_cast(resFragmentLight->toAngleSampler.to_ptr()); allocator->Free( angleSampler->toSampler.to_ptr() ); allocator->Free( resFragmentLight->toAngleSampler.to_ptr() ); if ( resFragmentLight->toName.to_ptr() != NULL ) { allocator->Free( const_cast( resFragmentLight->toName.to_ptr() ) ); } allocator->Free( resFragmentLight ); } //----------------------------------------- Result FragmentLight::CreateOriginalValue(os::IAllocator* allocator) { Result result = INITIALIZE_RESULT_OK; void* buffer = allocator->Alloc(sizeof(ResFragmentLightData)); NW_NULL_ASSERT(buffer); // リソースをコピー ResFragmentLightData* originalValue = new(buffer) ResFragmentLightData(GetResFragmentLight().ref()); m_OriginalValue = ResFragmentLight(originalValue); m_OriginalTransform = this->GetResTransformNode().GetTransform(); return result; } //---------------------------------------- Result FragmentLight::Initialize(os::IAllocator* allocator) { Result result = INITIALIZE_RESULT_OK; result |= TransformNode::Initialize(allocator); NW_ENSURE_AND_RETURN(result); result |= CreateOriginalValue(allocator); NW_ENSURE_AND_RETURN(result); result |= CreateAnimGroup(allocator); NW_ENSURE_AND_RETURN(result); return result; } } // namespace gfx } // namespace nw