Assign text to objects

Started by ErDetEnAnd?, March 09, 2008, 11:14:58 AM

Previous topic - Next topic

ErDetEnAnd?

Hello guys.

I want to assign text to objects. Putting the text at the objects transformed center is the goal. In my solution I have one "origin object" which has several childs attached to it, and the camera towards it.

Now, placing the text should be something like this (just after the framebuffer has been flushed):

SimpleVector origin = Interact2D.project3D2D(camera, buffer, originObject.getCenter());
int length = gFrame.getFontMetrics().stringWidth(originObject.getName());
length /= 2;
gFrame.drawString(originObject.getName(), (int)origin.x-length, (int)origin.y);


... but it's not. The origin object's name appear at coordinate (frame_width; frame_height), leaving 1/4 of the text visible at the buttom to the right. First question is why it that?

Rewriting last line to this:

gFrame.drawString(originObject.getName(), (int)origin.x-length-(getWidth()/2), (int)origin.y-(getHeight()/2));

...solves the wrong position. The text appears right in the center of the object.

Now for the child objects:

for (Object3D o3d: childObjects) {
    SimpleVector v = o3d.getTransformedCenter();
    v = Interact2D.project3D2D(camera, buffer, v);

    length = gFrame.getFontMetrics().stringWidth(o3d.getName());
    length /= 2;
    gFrame.drawString(o3d.getName(), (int)v.x-length-(getWidth()/2), (int)v.y-(getHeight()/2));
    // Still should be: gFrame.drawString(o3d.getName(), (int)v.x-length, (int)v.y);
}


The transformation is correct, but the positioning have some kind of offset, like the distance from object's transformed center and it's assigned text is like the distance from origin and transformed object * 2.



What am I doing wrong?

EgonOlsen

Are you using supersampling (i.e. SAMPLINGMODE_OGSS or SAMPLINGMODE_OGSS_FAST)? If so, you have to rescale the returned back buffer coordinates to fit your actual screen by dividing them by 2 (OGSS) or 1.5 (OGSS_FAST).

ErDetEnAnd?

AHA!

Thats the answer, rescaling does the trick.

Skide godt!