📄 spinningcloud.cpp
字号:
#include "gosFXHeaders.hpp"
//==========================================================================//
// File: gosFX_SpinningCloud.cpp //
// Contents: Base gosFX::SpinningCloud Component //
//---------------------------------------------------------------------------//
// Copyright (C) Microsoft Corporation. All rights reserved. //
//===========================================================================//
//
//############################################################################
//######################## gosFX::SpinningCloud__Specification #############################
//############################################################################
//------------------------------------------------------------------------------
//
gosFX::SpinningCloud__Specification::SpinningCloud__Specification(
Stuff::RegisteredClass::ClassID class_id,
Stuff::MemoryStream *stream,
int gfx_version
):
ParticleCloud__Specification(class_id, stream, gfx_version)
{
Check_Pointer(this);
Verify(gos_GetCurrentHeap() == Heap);
//
//-----------------
// Load the fcurves
//-----------------
//
m_pSpin.Load(stream, gfx_version);
m_pScale.Load(stream, gfx_version);
//
//-----------------------
// Load the rotation flag
//-----------------------
//
*stream >> m_randomStartingRotation;
*stream >> m_alignZUsingX >> m_alignZUsingY;
if (gfx_version >= 10)
*stream >> m_alignYUsingVelocity;
else
m_alignYUsingVelocity = false;
}
//------------------------------------------------------------------------------
//
gosFX::SpinningCloud__Specification::SpinningCloud__Specification(
Stuff::RegisteredClass::ClassID class_id
):
ParticleCloud__Specification(class_id)
{
Check_Pointer(this);
Verify(gos_GetCurrentHeap() == Heap);
m_randomStartingRotation = false;
m_alignZUsingX = false;
m_alignZUsingY = false;
m_alignYUsingVelocity = false;
}
//------------------------------------------------------------------------------
//
void
gosFX::SpinningCloud__Specification::Save(Stuff::MemoryStream *stream)
{
Check_Object(this);
Check_Object(stream);
ParticleCloud__Specification::Save(stream);
m_pSpin.Save(stream);
m_pScale.Save(stream);
*stream << m_randomStartingRotation << m_alignZUsingX << m_alignZUsingY;
*stream << m_alignYUsingVelocity;
}
//------------------------------------------------------------------------------
//
void
gosFX::SpinningCloud__Specification::BuildDefaults()
{
Check_Object(this);
ParticleCloud__Specification::BuildDefaults();
m_randomStartingRotation = false;
m_alignZUsingX = false;
m_alignZUsingY = false;
m_alignYUsingVelocity = false;
m_pSpin.m_ageCurve.SetCurve(0.0f);
m_pSpin.m_seeded = false;
m_pSpin.m_seedCurve.SetCurve(1.0f);
m_pScale.m_ageCurve.SetCurve(1.0f);
m_pScale.m_seeded = false;
m_pScale.m_seedCurve.SetCurve(1.0f);
}
//------------------------------------------------------------------------------
//
bool
gosFX::SpinningCloud__Specification::IsDataValid(bool fix_data)
{
Check_Object(this);
Stuff::Scalar min,max;
m_pScale.ExpensiveComputeRange(&min,&max);
if(min<0.0f)
if(fix_data)
{
m_pScale.m_ageCurve.SetCurve(1.0f);
m_pScale.m_seeded = false;
m_pScale.m_seedCurve.SetCurve(1.0f);
PAUSE(("Warning: Curve \"pScale\" in Effect \"%s\" Is Out of Range and has been Reset",(char *)m_name));
}
else
return false;
return ParticleCloud__Specification::IsDataValid(fix_data);
}
//------------------------------------------------------------------------------
//
void
gosFX::SpinningCloud__Specification::Copy(SpinningCloud__Specification *spec)
{
Check_Object(this);
Check_Object(spec);
ParticleCloud__Specification::Copy(spec);
gos_PushCurrentHeap(Heap);
m_pSpin = spec->m_pSpin;
m_pScale = spec->m_pScale;
m_randomStartingRotation = spec->m_randomStartingRotation;
m_alignZUsingX = spec->m_alignZUsingX;
m_alignZUsingY = spec->m_alignZUsingY;
m_alignYUsingVelocity = spec->m_alignYUsingVelocity;
gos_PopCurrentHeap();
}
//############################################################################
//############################## gosFX::SpinningCloud ################################
//############################################################################
gosFX::SpinningCloud::ClassData*
gosFX::SpinningCloud::DefaultData = NULL;
//------------------------------------------------------------------------------
//
void
gosFX::SpinningCloud::InitializeClass()
{
Verify(!DefaultData);
Verify(gos_GetCurrentHeap() == Heap);
DefaultData =
new ClassData(
SpinningCloudClassID,
"gosFX::SpinningCloud",
ParticleCloud::DefaultData,
NULL,
NULL
);
Register_Object(DefaultData);
}
//------------------------------------------------------------------------------
//
void
gosFX::SpinningCloud::TerminateClass()
{
Unregister_Object(DefaultData);
delete DefaultData;
DefaultData = NULL;
}
//------------------------------------------------------------------------------
//
gosFX::SpinningCloud::SpinningCloud(
ClassData *class_data,
Specification *spec,
unsigned flags
):
ParticleCloud(class_data, spec, flags)
{
Verify(gos_GetCurrentHeap() == Heap);
}
//------------------------------------------------------------------------------
//
bool
gosFX::SpinningCloud::Execute(ExecuteInfo *info)
{
Check_Object(this);
Check_Object(info);
//
//----------------------------------------
// If we aren't supposed to execute, don't
//----------------------------------------
//
if (!IsExecuted())
return false;
//
//------------------------------------------------------------------
// Animate the particles. If it is time for us to die, return false
//------------------------------------------------------------------
//
if (!ParticleCloud::Execute(info))
return false;
//
//-----------------------------------------------------------------------
// If there are active particles to animate, get the current center point
// of the bounds
//-----------------------------------------------------------------------
//
if (m_activeParticleCount > 0)
{
Stuff::ExtentBox box(Stuff::Point3D::Identity, Stuff::Point3D::Identity);
unsigned i=0;
//
//-------------------------------------------------------------------
// If there is no bounds yet, we need to create our extent box around
// the first legal point we find
//-------------------------------------------------------------------
//
while (i<m_activeParticleCount)
{
Particle *particle = GetParticle(i++);
Check_Object(particle);
//
//-----------------------------------------------------------
// We have found our first particle, so put the box around it
//-----------------------------------------------------------
//
if (particle->m_age < 1.0f)
{
box.maxX =
particle->m_localTranslation.x
+ particle->m_radius*particle->m_scale;
box.minX =
particle->m_localTranslation.x
- particle->m_radius*particle->m_scale;
box.maxY =
particle->m_localTranslation.y
+ particle->m_radius*particle->m_scale;
box.minY =
particle->m_localTranslation.y
- particle->m_radius*particle->m_scale;
box.maxZ =
particle->m_localTranslation.z
+ particle->m_radius*particle->m_scale;
box.minZ =
particle->m_localTranslation.z
- particle->m_radius*particle->m_scale;
break;
}
}
//
//-----------------------------
// Look for the other particles
//-----------------------------
//
while (i<m_activeParticleCount)
{
Particle *particle = GetParticle(i++);
Check_Object(particle);
if (particle->m_age < 1.0f)
{
Stuff::ExtentBox local_box;
local_box.minX =
particle->m_localTranslation.x
- particle->m_radius*particle->m_scale;
local_box.maxX =
particle->m_localTranslation.x
+ particle->m_radius*particle->m_scale;
local_box.minY =
particle->m_localTranslation.y
- particle->m_radius*particle->m_scale;
local_box.maxY =
particle->m_localTranslation.y
+ particle->m_radius*particle->m_scale;
local_box.minZ =
particle->m_localTranslation.z
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -