⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sceneobject.cpp

📁 3D赛车游戏源代码-用Visual Studio 2005
💻 CPP
字号:
#include "StdAfx.h"
#include "SceneObject.h"
#include "SceneManager.h"

//-------------------------------------------------------------------------------
// 构造函数
//-------------------------------------------------------------------------------
CSceneObject::CSceneObject()
{
	m_nTypeMask = OBJECTTYPE_DEFAULT_OBJECT;
	m_mxTransformObjToWorld.Identity();
	m_mxTransformWorldToObj.Identity();
	m_boxObjectBox.Empty();
	m_boxWorldBox.Empty();
	m_sphWorldSphere.Empty();
	m_pSceneManager = NULL;
}

//-------------------------------------------------------------------------------
// 析构函数
//-------------------------------------------------------------------------------
CSceneObject::~CSceneObject()
{
	if (m_pSceneManager != NULL)
	{
		RemoveFromScene();
	}
}

//-------------------------------------------------------------------------------
// 将该对象添加到场景中
//-------------------------------------------------------------------------------
void CSceneObject::AddToScene()
{
	g_SceneManager.AddObjectToScene(this);
	m_pSceneManager = &g_SceneManager;
}

//-------------------------------------------------------------------------------
// 把该对象从场景中删除
//-------------------------------------------------------------------------------
void CSceneObject::RemoveFromScene()
{
	g_SceneManager.RemoveObjectFromScene(this);
	m_pSceneManager = NULL;
}

//-------------------------------------------------------------------------------
// 渲染这个对象
//-------------------------------------------------------------------------------
void CSceneObject::RenderObject()
{
}

//-------------------------------------------------------------------------------
// 设置转换矩阵,将导致世界坐标包围盒子、球、还有场景位置等一系列变换
//-------------------------------------------------------------------------------
void CSceneObject::SetTransform(const CMatrix44F &mat)
{
	m_mxTransformObjToWorld = mat;
	m_mxTransformWorldToObj = mat;
	m_mxTransformWorldToObj.AffineInverse();
	ResetWorldBox();
}

//-------------------------------------------------------------------------------
// 重置世界坐标的边界框
//-------------------------------------------------------------------------------
void CSceneObject::ResetWorldBox()
{
	m_boxWorldBox.SetToTransformedBox(m_boxObjectBox, m_mxTransformObjToWorld);
	m_sphWorldSphere.center = m_boxWorldBox.Center();
	m_sphWorldSphere.radius = Distance(m_boxWorldBox.max, m_sphWorldSphere.center);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -