Original Post
After getting the rotation finally working (kinda - probably needs some more maths calculations) I noticed that my cameras and primitives had identical code relating to their information in World Space. So I thought I would create a WorldObject class that they could both be based on. So a recap on the hierarchy of the classes I have: DXWorld - holds the x, y, z position and deals with the matrices for the object DXWorldObject - talks to the DXWorld class and handles orbiting manouvers and setting of the world information DXPrimitive - the base class for drawing primitives on the screen DXPrimitiveList - an ArrayList of Primitives DXCamera - nuff said DXCameraList - an ArrayList of Cameras DXWorld-DXWorldObject-DXCamera DXWorld-DXWorldObject-DXPrimitive object variables used in the program m_CamPrimList = List of Primitives that are the Camera's visual element m_CameraList = List of Cameras m_PrimitiveList = List of Primitives Steps I took to convert from a non WorldObject class program. Compiled and run after each step. I didn't continue until I saw it working as expected. 1. Create WorldObject and teach it about World 2. Adjust Camera to use WorldObject and its related code in the main program 3. Adjust Primitive to use WorldObject and its related code in the main program At this point it fails when drawing the primitives I'll try and post the code in, in the order it executes: First we make sure we are using updated world information. This and the block of code after are executed in that order. Then we draw the primitives themselves - in this case my triangles and camerapoints. It never gets as far as CamPrimList->Draw though. The call to PrimitiveLists and CamPrimLists then goes here It then calls this routine which transforms the object. The transform call then goes here. It skips over the m_Center test as these objects don't orbit anything and calls the standard Transform code. However it executes the last Console::WriteLine command and displays the information but then fails to return the value calculated on the next line but instead quits out with the StackOverflow error. I can't see why though as it never calls itself without a center point. This is the console output. I've relayed out the Matrix values but not altered their values. As a note the first primitive has Zero coordinates and thus positioned in the center of space. A brief overview of world space links. Camera->Primitive CamPrim->Primitive Primtive->Nothing I could understand if it had a problem with CamPrim transforming and overflowing as it runs the code twice, once for itself and once for its center but this is clearly not the case. As said, the code worked great until I introduced the worldobject class to the primitive class. If anyone can see anything wrong I would be much appreciative. Thanks for reading this loooong post. [Edited by - Xrystal on August 14, 2006 2:09:42 AM]
for (int i = 0; i < m_CameraList->Count - 1; i++)
{
m_CameraList->Camera->LookAt = m_PrimitiveList->Primitive->WorldCoords;
m_CameraList->Camera->OrbitalCenter = m_PrimitiveList->Primitive->World;
m_CameraList->Camera->Orbit();
}
for (int i = 0; i < m_CamPrimList->Count - 1; i++)
{
m_CamPrimList->Primitive->WorldCoords = m_CameraList->Camera->WorldCoords;
m_CamPrimList->Primitive->OrbitalCenter = m_CameraList->Camera->OrbitalCenter;
m_CamPrimList->Primitive->Orbit();
}
if (m_ActiveCamera)
{
m_ActiveCamera->ActivateView();
}
Console::WriteLine("Drawing Primitives");
m_PrimitiveList->Draw(PrimitiveType::TriangleList);
Console::WriteLine("Drawing CameraPoints");
m_CamPrimList->Draw(PrimitiveType::PointList);
void DXPrimitiveList::Draw(PrimitiveType primitiveType)
{
IEnumerator* ie = m_Primitives->GetEnumerator();
while(ie->MoveNext())
{
Console::WriteLine(String::Format("Drawing Primitive : {0}",__box(dynamic_cast<DXPrimitive*>(ie->Current)->ID)));
dynamic_cast<DXPrimitive*>(ie->Current)->Draw(primitiveType);
}
}
bool DXPrimitive::Draw(PrimitiveType primitiveType)
{
Console::WriteLine("Transforming World with Primitive Coordinates");
m_device->Transform->World = m_WorldSpace->Transform();
Console::WriteLine("Do we have a mesh to draw?");
if (m_mesh)
{
Console::WriteLine("Drawing Mesh");
m_mesh->DrawSubset(0);
return true;
}
else
{
Console::WriteLine("Drawing Primitive");
return Draw(primitiveType,0,m_vertexCount);
}
}
Matrix DXWorld::Transform(void)
{
if (m_Center)
{
Console::WriteLine("Transforming World with a Center");
return this->m_scale * this->m_rotate * this->m_translate * this->m_Center->Transform();
}
Console::WriteLine("Transforming World without a Center");
Console::WriteLine(String::Format("Scale={0}\n,Rotate={1}\n,Translate={2}\n\n",m_scale.ToString() , m_rotate.ToString() , m_translate.ToString()));
return this->m_scale * this->m_rotate * this->m_translate;
}
Drawing Primitives
Drawing Primitive : 0
Transforming World with Primitive Coordinates
Transforming World without a Center
Scale=Determinant: 1
M11: 1 M12: 0 M13: 0 M14: 0
M21: 0 M22: 1 M23: 0 M24: 0
M31: 0 M32: 0 M33: 1 M34: 0
M41: 0 M42: 0 M43: 0 M44: 1
,Rotate=Determinant: 1
M11: 1 M12: 0 M13: 0 M14: 0
M21: 0 M22: 1 M23: 0 M24: 0
M31: 0 M32: 0 M33: 1 M34: 0
M41: 0 M42: 0 M43: 0 M44: 1
,Translate=Determinant: 1
M11: 1 M12: 0 M13: 0 M14: 0
M21: 0 M22: 1 M23: 0 M24: 0
M31: 0 M32: 0 M33: 1 M34: 0
M41: 0 M42: 0 M43: 0 M44: 1