📄 pertcloud.cpp
字号:
Specification *spec = GetSpecification();
Check_Object(spec);
Particle *particle = GetParticle(index);
Check_Object(particle);
//
//----------------------------------------
// Now we compute the geometry of the pert
//----------------------------------------
//
Verify(spec->m_vertices > 4);
Stuff::Scalar angle_between = Stuff::Two_Pi/(spec->m_vertices-2);
Stuff::Scalar radius = spec->m_size.ComputeValue(m_age, particle->m_seed);
int even = 1;
particle->m_vertices[0] = Stuff::Point3D::Identity;
Stuff::Scalar bound = 0.0f;
for (int j=1; j<spec->m_vertices-1; j++)
{
Stuff::Scalar perturbance =
even * spec->m_perturbation.ComputeValue(m_age, particle->m_seed);
Stuff::Scalar temp = perturbance + radius;
particle->m_vertices[j] =
Stuff::Point3D(
Stuff::Sin(j*angle_between)*temp,
Stuff::Cos(j*angle_between)*temp,
perturbance
);
perturbance = temp*temp + perturbance*perturbance;
if (perturbance > bound)
bound = perturbance;
even = -even;
}
particle->m_radius = Stuff::Sqrt(bound);
particle->m_vertices[j] = particle->m_vertices[1];
}
//------------------------------------------------------------------------------
//
void gosFX::PertCloud::DestroyParticle(unsigned index)
{
SpinningCloud::DestroyParticle(index);
m_cloudImplementation->TurnOff(index);
Verify(!m_cloudImplementation->IsOn(index));
}
//------------------------------------------------------------------------------
//
void gosFX::PertCloud::Draw(DrawInfo *info)
{
Check_Object(this);
Check_Object(info);
//
//---------------------------------------------------------
// If we have active particles, set up the draw information
//---------------------------------------------------------
//
if (m_activeParticleCount)
{
MidLevelRenderer::DrawEffectInformation dInfo;
dInfo.effect = m_cloudImplementation;
Specification *spec = GetSpecification();
Check_Object(spec);
dInfo.state.Combine(info->m_state, spec->m_state);
dInfo.clippingFlags = info->m_clippingFlags;
Stuff::LinearMatrix4D local_to_world;
local_to_world.Multiply(m_localToParent, *info->m_parentToWorld);
dInfo.effectToWorld = &local_to_world;
//
//--------------------------------------------------------------
// Check the orientation mode. The first case is XY orientation
//--------------------------------------------------------------
//
unsigned i;
unsigned vert=0;
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
);
//
//--------------------------------------
// Spin through all the active particles
//--------------------------------------
//
for (i = 0; i < m_activeParticleCount; i++)
{
Particle *particle = GetParticle(i);
Check_Object(particle);
if (particle->m_age < 1.0f)
{
//
//--------------------------------
// Build the local to cloud matrix
//--------------------------------
//
Stuff::Vector3D direction_in_cloud;
direction_in_cloud.Subtract(
camera_in_cloud,
particle->m_localTranslation
);
Stuff::LinearMatrix4D pert_to_cloud;
pert_to_cloud.BuildRotation(particle->m_localRotation);
pert_to_cloud.AlignLocalAxisToWorldVector(
direction_in_cloud,
Stuff::Z_Axis,
Stuff::Y_Axis,
Stuff::X_Axis
);
pert_to_cloud.BuildTranslation(particle->m_localTranslation);
//
//----------------------------------------------------
// Figure out the scale, then transform all the points
//----------------------------------------------------
//
Stuff::Scalar scale = particle->m_scale;
for (unsigned v=0; v<spec->m_vertices; ++v)
{
Stuff::Point3D scaled;
scaled.Multiply(particle->m_vertices[v], scale);
m_P_vertices[vert++].Multiply(scaled, pert_to_cloud);
}
}
else
vert += spec->m_vertices;
}
}
//
//-----------------------
// 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
);
//
//--------------------------------------
// Spin through all the active particles
//--------------------------------------
//
for (i = 0; i < m_activeParticleCount; i++)
{
Particle *particle = GetParticle(i);
Check_Object(particle);
if (particle->m_age < 1.0f)
{
//
//--------------------------------
// Build the local to cloud matrix
//--------------------------------
//
Stuff::Vector3D direction_in_cloud;
direction_in_cloud.Subtract(
camera_in_cloud,
particle->m_localTranslation
);
Stuff::LinearMatrix4D pert_to_cloud;
pert_to_cloud.BuildRotation(particle->m_localRotation);
pert_to_cloud.AlignLocalAxisToWorldVector(
direction_in_cloud,
Stuff::Z_Axis,
Stuff::X_Axis,
-1
);
pert_to_cloud.BuildTranslation(particle->m_localTranslation);
//
//----------------------------------------------------
// Figure out the scale, then transform all the points
//----------------------------------------------------
//
Stuff::Scalar scale = particle->m_scale;
for (unsigned v=0; v<spec->m_vertices; ++v)
{
Stuff::Point3D scaled;
scaled.Multiply(particle->m_vertices[v], scale);
m_P_vertices[vert++].Multiply(scaled, pert_to_cloud);
}
}
else
vert += spec->m_vertices;
}
}
}
//
//-------------------------------------------------------
// 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
);
//
//--------------------------------------
// Spin through all the active particles
//--------------------------------------
//
for (i = 0; i < m_activeParticleCount; i++)
{
Particle *particle = GetParticle(i);
Check_Object(particle);
if (particle->m_age < 1.0f)
{
//
//--------------------------------
// Build the local to cloud matrix
//--------------------------------
//
Stuff::Vector3D direction_in_cloud;
direction_in_cloud.Subtract(
camera_in_cloud,
particle->m_localTranslation
);
Stuff::LinearMatrix4D pert_to_cloud;
pert_to_cloud.BuildRotation(particle->m_localRotation);
pert_to_cloud.AlignLocalAxisToWorldVector(
direction_in_cloud,
Stuff::Z_Axis,
Stuff::Y_Axis,
-1
);
pert_to_cloud.BuildTranslation(particle->m_localTranslation);
//
//----------------------------------------------------
// Figure out the scale, then transform all the points
//----------------------------------------------------
//
Stuff::Scalar scale = particle->m_scale;
for (unsigned v=0; v<spec->m_vertices; ++v)
{
Stuff::Point3D scaled;
scaled.Multiply(particle->m_vertices[v], scale);
m_P_vertices[vert++].Multiply(scaled, pert_to_cloud);
}
}
else
vert += spec->m_vertices;
}
}
//
//---------------------------------------------------------------
// 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 (particle->m_age < 1.0f)
{
//
//--------------------------------
// Build the local to cloud matrix
//--------------------------------
//
Stuff::LinearMatrix4D pert_to_cloud;
pert_to_cloud.BuildRotation(particle->m_localRotation);
pert_to_cloud.BuildTranslation(particle->m_localTranslation);
//
//----------------------------------------------------
// Figure out the scale, then transform all the points
//----------------------------------------------------
//
Stuff::Scalar scale = particle->m_scale;
for (unsigned v=0; v<spec->m_vertices; ++v)
{
Stuff::Point3D scaled;
scaled.Multiply(particle->m_vertices[v], scale);
m_P_vertices[vert++].Multiply(scaled, pert_to_cloud);
}
}
else
vert += spec->m_vertices;
}
}
//
//---------------------
// Now just do the draw
//---------------------
//
info->m_clipper->DrawEffect(&dInfo);
}
SpinningCloud::Draw(info);
}
//------------------------------------------------------------------------------
//
void
gosFX::PertCloud::TestInstance() const
{
Verify(IsDerivedFrom(DefaultData));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -