図0111a
class Tree : public GameObject {
Vec3 m_Pos;
shared_ptr<MultiMeshResource> m_MultiMeshResource;
public:
//構築と破棄
//--------------------------------------------------------------------------------------
/*!
@brief コンストラクタ
@param[in] StagePtr ステージ
*/
//--------------------------------------------------------------------------------------
Tree(const shared_ptr<Stage>& StagePtr, const Vec3& Pos);
//--------------------------------------------------------------------------------------
/*!
@brief デストラクタ
*/
//--------------------------------------------------------------------------------------
virtual ~Tree() {}
//--------------------------------------------------------------------------------------
/*!
@brief 初期化
*/
//--------------------------------------------------------------------------------------
virtual void OnCreate() override;
//--------------------------------------------------------------------------------------
/*!
@brief 更新
*/
//--------------------------------------------------------------------------------------
virtual void OnUpdate() override {}
};
void Tree::OnCreate() { auto PtrTransform = GetComponent<Transform>(); PtrTransform->SetPosition(m_Pos); PtrTransform->SetScale(0.5f, 1.0f, 0.5f); PtrTransform->SetRotation(0.0f, 0.0f, 0.0f); //capsuleの衝突判定をつける auto PtrColl = AddComponent<CollisionCapsule>(); PtrColl->SetFixed(true); // PtrColl->SetDrawActive(true); shared_ptr<MeshResource> TreeMesh, LeafMesh1, LeafMesh2; if (!App::GetApp()->CheckResource<MeshResource>(L"TREE_MESH")) { TreeMesh =MeshResource::CreateCylinder(1.0f, 1.0f, 18, false); Mat4x4 TransToMat; TransToMat.affineTransformation( Vec3(1.0f,1.0f,1.0f), Vec3(0.0f, 0.0f, 0.0f), Vec3(0.0f, 0.0f, 0.0f), Vec3(0.0f, 0.0f, 0.0f) ); TreeMesh->SetMeshToTransformMatrix(TransToMat); TreeMesh->SetUseMeshToTransformMatrix(true); App::GetApp()->RegisterResource(L"TREE_MESH", TreeMesh); } else { TreeMesh = App::GetApp()->GetResource<MeshResource>(L"TREE_MESH"); } //このメッシュ特有のテクスチャとして登録 TreeMesh->SetTextureResource(L"BROWN_TX"); if (!App::GetApp()->CheckResource<MeshResource>(L"LEAF_MESH_1")) { LeafMesh1 = MeshResource::CreateCone(1.0f, 1.0f,18,false); Mat4x4 TransToMat; TransToMat.affineTransformation( Vec3(3.0f, 0.5f, 3.0f), Vec3(0.0f, 0.0f, 0.0f), Vec3(0.0f, 0.0f, 0.0f), Vec3(0.0f, 0.4f, 0.0f) ); LeafMesh1->SetMeshToTransformMatrix(TransToMat); LeafMesh1->SetUseMeshToTransformMatrix(true); App::GetApp()->RegisterResource(L"LEAF_MESH_1", LeafMesh1); } else { LeafMesh1 = App::GetApp()->GetResource<MeshResource>(L"LEAF_MESH_1"); } //このメッシュ特有のテクスチャとして登録 LeafMesh1->SetTextureResource(L"GREEN_TX"); if (!App::GetApp()->CheckResource<MeshResource>(L"LEAF_MESH_2")) { LeafMesh2 = MeshResource::CreateCone(1.0f, 1.0f, 18, false); Mat4x4 TransToMat; TransToMat.affineTransformation( Vec3(2.0f, 0.5f, 2.0f), Vec3(0.0f, 0.0f, 0.0f), Vec3(0.0f, 0.0f, 0.0f), Vec3(0.0f, 0.7f, 0.0f) ); LeafMesh2->SetMeshToTransformMatrix(TransToMat); LeafMesh2->SetUseMeshToTransformMatrix(true); App::GetApp()->RegisterResource(L"LEAF_MESH_2", LeafMesh2); } else { LeafMesh2 = App::GetApp()->GetResource<MeshResource>(L"LEAF_MESH_2"); } //このメッシュ特有のテクスチャとして登録 LeafMesh2->SetTextureResource(L"GREEN_TX"); //このオブジェクトはマルチメッシュを使う m_MultiMeshResource = ObjectFactory::Create<MultiMeshResource>(); m_MultiMeshResource->AddMesh(TreeMesh); m_MultiMeshResource->AddMesh(LeafMesh1); m_MultiMeshResource->AddMesh(LeafMesh2); //影をつける auto ShadowPtr = AddComponent<Shadowmap>(); ShadowPtr->SetMultiMeshResource(m_MultiMeshResource); //描画コンポーネントの設定 auto PtrDraw = AddComponent<BcPNTStaticDraw>(); //描画するマルチメッシュを設定 PtrDraw->SetMultiMeshResource(m_MultiMeshResource); }
if (!App::GetApp()->CheckResource<MeshResource>(L"LEAF_MESH_2")) { LeafMesh2 = MeshResource::CreateCone(1.0f, 1.0f, 18, false); Mat4x4 TransToMat; TransToMat.affineTransformation( Vec3(2.0f, 0.5f, 2.0f), Vec3(0.0f, 0.0f, 0.0f), Vec3(0.0f, 0.0f, 0.0f), Vec3(0.0f, 0.7f, 0.0f) ); LeafMesh2->SetMeshToTransformMatrix(TransToMat); LeafMesh2->SetUseMeshToTransformMatrix(true); App::GetApp()->RegisterResource(L"LEAF_MESH_2", LeafMesh2); } else { LeafMesh2 = App::GetApp()->GetResource<MeshResource>(L"LEAF_MESH_2"); } //このメッシュ特有のテクスチャとして登録 LeafMesh2->SetTextureResource(L"GREEN_TX");
LeafMesh2->SetMeshToTransformMatrix(TransToMat); LeafMesh2->SetUseMeshToTransformMatrix(true);
//このメッシュ特有のテクスチャとして登録 LeafMesh2->SetTextureResource(L"GREEN_TX");
//このオブジェクトはマルチメッシュを使う m_MultiMeshResource = ObjectFactory::Create<MultiMeshResource>(); m_MultiMeshResource->AddMesh(TreeMesh); m_MultiMeshResource->AddMesh(LeafMesh1); m_MultiMeshResource->AddMesh(LeafMesh2);
//影をつける auto ShadowPtr = AddComponent<Shadowmap>(); ShadowPtr->SetMultiMeshResource(m_MultiMeshResource); //描画コンポーネントの設定 auto PtrDraw = AddComponent<BcPNTStaticDraw>(); //描画するマルチメッシュを設定 PtrDraw->SetMultiMeshResource(m_MultiMeshResource);
//木の作成 void GameStage::CreateTrees() { for (float x = -22.0f; x < 22.0f; x += 4.0f) { for (float z = -22.0f; z < 22.0f; z += 4.0f) { AddGameObject<Tree>(Vec3(x, 0.5f, z)); } } }