Files
RP412/MUNGA/SEGMENT.cpp
T
CydandClaude Opus 4.8 4abbf8879f Initial import of Red Planet v4.10 Win32 source
Imports the current Win32 source for the pod-racing game 'Red Planet',
built on the MUNGA engine and its L4 (Win32/DirectX) platform layer:

- MUNGA / MUNGA_L4: cross-platform engine core and Win32 backend
- RP / RP_L4: Red Planet game logic and Win32 application
- DivLoader, Setup1: asset loader and installer project
- lib, MUNGA_L4/openal, MUNGA_L4/sos: third-party audio dependencies

Removed stale Subversion metadata and added .gitignore/.gitattributes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-30 07:59:51 -05:00

274 lines
6.6 KiB
C++

#include "munga.h"
#pragma hdrstop
#include "segment.h"
#include "joint.h"
//#############################################################################
// Segment::VideoObjectNames Support
//
CString*
EntitySegment::VideoObjectNames::GetVideoObjectName(
Enumeration damage_graphic_state
)
{
Check(this);
CStringPlug *my_plug = videoObjectNames.Find(damage_graphic_state);
if (my_plug)
{
Check(my_plug);
return my_plug->GetPointer();
}
return NULL;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
EntitySegment__VideoObjectNames::EntitySegment__VideoObjectNames() : videoObjectNames(NULL, false)
{
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
EntitySegment::VideoObjectNames::~VideoObjectNames()
{
VChainIteratorOf<CStringPlug*, Enumeration> iterator(videoObjectNames);
iterator.DeletePlugs();
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
EntitySegment::VideoObjectNames::AddVideoObjectName(
const CString &new_name,
Enumeration damage_graphic_state
)
{
Check(this);
CStringPlug *new_string = new CStringPlug(new_name);
Register_Object(new_string);
videoObjectNames.AddValue(new_string, damage_graphic_state);
}
//#############################################################################
// Segment Support
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
EntitySegment::EntitySegment(
CString segment_name,
int this_index,
int parent_index,
int joint_index,
Joint *joint_ptr,
LinearMatrix &lin_matrix,
EntitySegment *parent_segment,
Logical is_site,
int primary_damage_zone
) :
baseOffset(LinearMatrix::Identity),
childIndexTable(NULL, True),
damageZoneTable(NULL,True),
videoObjectTable(NULL,True),
childPointerTable(NULL,True)
{
segmentModified = True;
thisIndex = this_index;
parentIndex = parent_index;
jointIndex = joint_index;
jointPointer = joint_ptr;
baseOffset = lin_matrix;
parentSegment =parent_segment;
segmentName = segment_name;
siteSegment = is_site;
primaryDamageZone = primary_damage_zone; // Add To constructor Call
segmentToParent = baseOffset;
segmentToEntity = baseOffset;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
CString*
EntitySegment::GetVideoObjectName(
SkeletonType skl_type,
Enumeration damage_graphic_state
)
{
Check(this);
VideoObjectNames *video_names = videoObjectTable.Find(skl_type);
if(video_names)
{
return video_names->GetVideoObjectName(damage_graphic_state);
}
else
{
return NULL;
}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
EntitySegment::~EntitySegment()
{
IntegerTableIterator iterator_child( childIndexTable);
iterator_child.DeletePlugs();
IntegerTableIterator iterator_damage(damageZoneTable);
iterator_damage.DeletePlugs();
VideoTableIterator iterator_video(videoObjectTable);
iterator_video.DeletePlugs();
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
EntitySegment::AddChildIndex(int child_index, int index)
{
Check(this);
IntegerPlug *child_plug = new IntegerPlug(child_index);
Register_Object(child_plug);
childIndexTable.AddValue(child_plug, index);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
EntitySegment::AddChildPointer(EntitySegment* child_ptr, int index)
{
Check(this);
childPointerTable.AddValue(child_ptr, index);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
EntitySegment::AddDamageZone(int damage_index, int index)
{
Check(this);
Check_Pointer(&damageZoneTable);
IntegerPlug *damage_plug = new IntegerPlug(damage_index);
Register_Object(damage_plug);
damageZoneTable.AddValue(damage_plug, index);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
EntitySegment::AddVideoObjectName(
CString video_object_name,
Enumeration skl_type,
Enumeration damage_graphic_state
)
{
Check(this);
Check_Pointer(&videoObjectTable);
VideoTableIterator iterator(videoObjectTable);
VideoObjectNames *names_plug = iterator.Find(skl_type);
if(!names_plug)
{
names_plug = new VideoObjectNames();
Register_Object(names_plug);
videoObjectTable.AddValue(names_plug, skl_type);
}
names_plug->AddVideoObjectName(video_object_name, damage_graphic_state);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
const LinearMatrix&
EntitySegment::GetSegmentToParent()
{
Check(this);
//
//-----------------------------------------------------------------------
// Recalculate the segment to parent matrix if we have a joint and it has
// changed
//-----------------------------------------------------------------------
//
if (jointPointer)
{
Check(jointPointer);
if (jointPointer->IsJointModified())
{
jointPointer->JointModified(False);
LinearMatrix
t1 = baseOffset,
t2;
switch(jointPointer->GetJointType())
{
case Joint::BallJointType:
{
LinearMatrix euler_angles = LinearMatrix::Identity;
euler_angles = jointPointer->GetEulerAngles();
t2.Invert(euler_angles);
segmentToParent.Multiply(t1,t2);
}
break;
case Joint::HingeXJointType:
case Joint::HingeYJointType:
case Joint::HingeZJointType:
{
LinearMatrix hinge_joint = LinearMatrix::Identity;
hinge_joint = jointPointer->GetHinge();
t2.Invert(hinge_joint);
segmentToParent.Multiply(t1,t2);
}
break;
case Joint::BallTranslationJointType:
{
//
//-------------------------------------
// We only want to invert the rotations
//-------------------------------------
//
LinearMatrix euler_angles = LinearMatrix::Identity;
euler_angles = jointPointer->GetEulerAngles();
segmentToParent.Invert(euler_angles);
t2.Multiply(t1,segmentToParent);
t1 = LinearMatrix::Identity;
t1 = jointPointer->GetTranslation();
segmentToParent.Multiply(t2,t1);
}
break;
}
}
}
return segmentToParent;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
const LinearMatrix&
EntitySegment::GetSegmentToEntity()
{
Check(this);
//
//---------------------------------------------------------------------
// Recalculate the segment to entity transform if something has changed
//---------------------------------------------------------------------
//
if (segmentModified && parentSegment)
{
Check(parentSegment);
segmentToEntity.Multiply(
GetSegmentToParent(),
parentSegment->GetSegmentToEntity()
);
ModifySegment(False);
}
return segmentToEntity;
}