📄 shapecloud.cpp
字号:
particle->m_color.red = spec->m_pRed.ComputeValue(age, seed);
particle->m_color.green = spec->m_pGreen.ComputeValue(age, seed);
particle->m_color.blue = spec->m_pBlue.ComputeValue(age, seed);
particle->m_color.alpha = spec->m_pAlpha.ComputeValue(age, seed);
return true;
}
//------------------------------------------------------------------------------
//
void gosFX::ShapeCloud::Draw(DrawInfo *info)
{
Check_Object(this);
Check_Object(info);
Check_Object(info->m_parentToWorld);
//
//----------------------------
// Set up the common draw info
//----------------------------
//
if (m_activeParticleCount)
{
MidLevelRenderer::DrawScalableShapeInformation dinfo;
MidLevelRenderer::MLRShape *shape = GetSpecification()->m_shape;
dinfo.clippingFlags.SetClippingState(0x3f);
dinfo.worldToShape = NULL;
Specification *spec = GetSpecification();
Check_Object(spec);
dinfo.state.Combine(info->m_state, spec->m_state);
dinfo.activeLights = NULL;
dinfo.nrOfActiveLights = 0;
dinfo.shape = shape;
Stuff::LinearMatrix4D local_to_world;
local_to_world.Multiply(m_localToParent, *info->m_parentToWorld);
//
//--------------------------------------------------------------
// Check the orientation mode. The first case is XY orientation
//--------------------------------------------------------------
//
unsigned i;
if (spec->m_alignZUsingX)
{
if (spec->m_alignZUsingY)
{
//
//-----------------------------------------
// Get the camera location into local space
//-----------------------------------------
//
Stuff::Point3D
camera_in_world(info->m_clipper->GetCameraToWorldMatrix());
Stuff::Point3D camera_in_cloud;
camera_in_cloud.MultiplyByInverse(
camera_in_world,
local_to_world
);
for (unsigned i = 0; i < m_activeParticleCount; i++)
{
Particle *particle = GetParticle(i);
Check_Object(particle);
//
//-----------------------------------------------------------------
// If the particle is still alive, concatenate into world space and
// issue the draw command
//-----------------------------------------------------------------
//
if (particle->m_age < 1.0f)
{
Stuff::Vector3D direction_in_cloud;
direction_in_cloud.Subtract(
camera_in_cloud,
particle->m_localTranslation
);
Stuff::LinearMatrix4D shape_to_cloud;
shape_to_cloud.BuildRotation(particle->m_localRotation);
shape_to_cloud.AlignLocalAxisToWorldVector(
direction_in_cloud,
Stuff::Z_Axis,
Stuff::Y_Axis,
Stuff::X_Axis
);
shape_to_cloud.BuildTranslation(particle->m_localTranslation);
Stuff::LinearMatrix4D shape_to_world;
shape_to_world.Multiply(
shape_to_cloud,
local_to_world
);
dinfo.shapeToWorld = &shape_to_world;
Stuff::Vector3D
scale(
particle->m_scale,
particle->m_scale,
particle->m_scale
);
dinfo.scaling = &scale;
dinfo.paintMe = &particle->m_color;
info->m_clipper->DrawScalableShape(&dinfo);
}
}
}
//
//-----------------------
// Handle X-only rotation
//-----------------------
//
else
{
//
//-----------------------------------------
// Get the camera location into local space
//-----------------------------------------
//
Stuff::Point3D
camera_in_world(info->m_clipper->GetCameraToWorldMatrix());
Stuff::Point3D camera_in_cloud;
camera_in_cloud.MultiplyByInverse(
camera_in_world,
local_to_world
);
for (unsigned i = 0; i < m_activeParticleCount; i++)
{
Particle *particle = GetParticle(i);
Check_Object(particle);
//
//-----------------------------------------------------------------
// If the particle is still alive, concatenate into world space and
// issue the draw command
//-----------------------------------------------------------------
//
if (particle->m_age < 1.0f)
{
Stuff::Vector3D direction_in_cloud;
direction_in_cloud.Subtract(
camera_in_cloud,
particle->m_localTranslation
);
Stuff::LinearMatrix4D shape_to_cloud;
shape_to_cloud.BuildRotation(particle->m_localRotation);
shape_to_cloud.AlignLocalAxisToWorldVector(
direction_in_cloud,
Stuff::Z_Axis,
Stuff::X_Axis,
-1
);
shape_to_cloud.BuildTranslation(particle->m_localTranslation);
Stuff::LinearMatrix4D shape_to_world;
shape_to_world.Multiply(
shape_to_cloud,
local_to_world
);
dinfo.shapeToWorld = &shape_to_world;
Stuff::Vector3D
scale(
particle->m_scale,
particle->m_scale,
particle->m_scale
);
dinfo.scaling = &scale;
dinfo.paintMe = &particle->m_color;
info->m_clipper->DrawScalableShape(&dinfo);
}
}
}
}
//
//-------------------------------------------------------
// Each matrix needs to be aligned to the camera around Y
//-------------------------------------------------------
//
else if (spec->m_alignZUsingY)
{
//
//-----------------------------------------
// Get the camera location into local space
//-----------------------------------------
//
Stuff::Point3D
camera_in_world(info->m_clipper->GetCameraToWorldMatrix());
Stuff::Point3D camera_in_cloud;
camera_in_cloud.MultiplyByInverse(
camera_in_world,
local_to_world
);
for (unsigned i = 0; i < m_activeParticleCount; i++)
{
Particle *particle = GetParticle(i);
Check_Object(particle);
//
//-----------------------------------------------------------------
// If the particle is still alive, concatenate into world space and
// issue the draw command
//-----------------------------------------------------------------
//
if (particle->m_age < 1.0f)
{
Stuff::Vector3D direction_in_cloud;
direction_in_cloud.Subtract(
camera_in_cloud,
particle->m_localTranslation
);
Stuff::LinearMatrix4D shape_to_cloud;
shape_to_cloud.BuildRotation(particle->m_localRotation);
shape_to_cloud.AlignLocalAxisToWorldVector(
direction_in_cloud,
Stuff::Z_Axis,
Stuff::Y_Axis,
-1
);
shape_to_cloud.BuildTranslation(particle->m_localTranslation);
Stuff::LinearMatrix4D shape_to_world;
shape_to_world.Multiply(
shape_to_cloud,
local_to_world
);
dinfo.shapeToWorld = &shape_to_world;
Stuff::Vector3D
scale(
particle->m_scale,
particle->m_scale,
particle->m_scale
);
dinfo.scaling = &scale;
dinfo.paintMe = &particle->m_color;
info->m_clipper->DrawScalableShape(&dinfo);
}
}
}
//
//---------------------------------------------------------------
// No alignment is necessary, so just multiply out all the active
// particles
//---------------------------------------------------------------
//
else
{
for (i=0; i < m_activeParticleCount; i++)
{
Particle *particle = GetParticle(i);
Check_Object(particle);
//
//-----------------------------------------------------------------
// If the particle is still alive, concatenate into world space and
// issue the draw command
//-----------------------------------------------------------------
//
if (particle->m_age < 1.0f)
{
Stuff::LinearMatrix4D shape_to_cloud;
shape_to_cloud.BuildTranslation(particle->m_localTranslation);
shape_to_cloud.BuildRotation(particle->m_localRotation);
Stuff::LinearMatrix4D shape_to_world;
shape_to_world.Multiply(
shape_to_cloud,
local_to_world
);
dinfo.shapeToWorld = &shape_to_world;
Stuff::Vector3D
scale(
particle->m_scale,
particle->m_scale,
particle->m_scale
);
dinfo.scaling = &scale;
dinfo.paintMe = &particle->m_color;
info->m_clipper->DrawScalableShape(&dinfo);
}
}
}
}
//
//----------------------------
// Let our parent do its thing
//----------------------------
//
SpinningCloud::Draw(info);
}
//------------------------------------------------------------------------------
//
void
gosFX::ShapeCloud::TestInstance() const
{
Verify(IsDerivedFrom(DefaultData));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -