Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I posted this in the original stack overflow then realized that a game-dev specific one exists.

I am working on personal project that requires me to have 4 points surrounding an object (1 at each of its furthest points) that will rotate/move when the object does.

These points are represented as simple coordinates (x,y,z) and rotational values (ry,rx,rz). Some other stuff exists in the class but it shouldn't be to relevant.

My object has coordinates in world space and can freely move around on the X and Z axis. The y value of the object and points are calculated elsewhere, separately using the X and Z values obtained by the points.

So Basically What I am asking is How do I attach my points to the Object and have them rotate when it does, move when it does etc. Keeping in mind I need the points coordinates in world space.

My knowledge of DirectX is a bit sketchy and basic concepts (change of coordinate systems, vector/matrix transformations etc) confuse me sometimes.

Any help is greatly appreciated.

This is the Constructor for the object, it initializes the points to areas around the object.

    Object::Object(ID3D10Device *renderingDevice, float mlength, float mwidth)
{
    pd3dDevice = renderingDevice;
    length = mlength;
    width = mwidth;
    A = new CollisionPoint(width,-length); //Front Left
    B = new CollisionPoint(-width,-length); //Front Right
    C = new CollisionPoint(width,length); //Back left
    D = new CollisionPoint(-width,length); //Back Right

}

This is the code that is meant to move and rotate the points.

 void Object::doBehaviour()
{
    //origin required for rotating of collisionbox
    D3DXVECTOR3 origin = D3DXVECTOR3(x,0,z);
    setUpWorldMatrix();
    moveForward();
    speed *= 0.99;

    //update collisionbox
    A->x = width;
    A->z = -length;
    A->rotateTo(0,ry,0);
    A->doBehaviour1(origin,world);

    B->x = -width;
    B->z = -length;
    B->ry = ry;
    B->doBehaviour1(origin,world);

    C->x = width;
    C->z = length;
    C->ry = ry;
    C->doBehaviour1(origin,world);

    D->x = -width;
    D->z = length;
    D->ry = ry;
    D->doBehaviour1(origin,world);

}

This is the code the collisionPoints use to move and rotate the points, ignore the int wheel bit.

    void CollisionPoint::moveAndRotate(D3DXVECTOR3 origin, int wheel)
{
    //1 = frontleft //2 = frontright //3 = backleft //4 = backright
    float xR = origin.x + cos(ry) * x - sin(ry) * z;
    float zR = origin.z - sin(ry) * x + cos(ry) * z;

    x = xR;
    z = zR;


}

void CollisionPoint::doBehaviour1(D3DXVECTOR3 origin, int wheel)
{
    moveAndRotate(origin, wheel);
    speed *= 0.99;
}

TLDR;

How do I:

  1. Convert coordinates to Object space.
  2. Rotate these coordinates along with an object based on its RY (rotation on the Y axis) value
  3. Obtain their coordinates in world space.
share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.