View Single Post
  #4  
Old 11-26-2004, 03:08 AM
jbb
Hill Giant
 
Join Date: Mar 2003
Location: UK
Posts: 242
Default

Ok, my other PC isn't connected to the network at the moment so I'll have to retype some of this here... If you can't get it to work I'll be able to post my code later on probably.

I have this structure for placable objects

struct Object
{
long id;
long offset;
float x, y, z;
float rx, ry, rz;
float scale;
}

You're probably loading this already.
x, y, z are the locations in the world of the object and rx, ry, and rz are the rotations (In radians I guess, not sure) and scale is the scaling factor on the size of the object.

To draw it I have this code (which is using D3D vector objects and the vector math library)

D3DMATRIX tMat, rxMat, ryMat, rzMat;


D3DXMatrixTranslation(&tMat, mesh->x, mesh->y, mesh-z);

// Hmm, wierd swapping of coordinates below, can't remember why
D3DXMatrixRotationX(&rxMat, mesh->rz);
D3DXMatrixRotationY(&rxMat, mesh->ry);
D3DXMatrixRotationZ(&rxMat, mesh->rx);

// These are vector multiplies that the direct 3d library provides in their c++ classes
matWorld = mesh->scale * rzMat * ryMat * rxMat;
matWorld = matWorld * tMat;

m_pD3DDevice->SetTransform(D3DTS_WORLD, &matWorld);

So yes, basically I scale the object (in x y and z), then rotate it and then move it to it's place in the world. (I think the order of the matrix multiplies means I do it in this order)

Maybe you've got the order of these operations wrong so you're trying to scale an object which isn't at the coordinate system origin or something.

Also, the main terrain object has x, y, z coordinates and the placable objects are all positioned relative to the world object.... So you either need to add the x, y, z coordinates of the objects to those of the landscape model or do what I did and zero out the x, y, z coordinates of the terrain model before drawing it so that the placeable objects are in the same system.

Well, I'll post the actual code when I'm able to but this did seem to work for me.
Reply With Quote