question

Mischa Spelt avatar image
0 Likes"
Mischa Spelt asked Phil BoBo edited

drawobject to exact size

Hi @phil.bobo and others,

I'd like to draw an object at an exact location with an exact size. Currently my code looks more or less like this:

drawtomodelscale( current );
fglPushMatrix();
fglTranslate( xPos, yPos, zPos );
fglScale( xSize, ySize, zSize );
fglRotate( 90, 1, 0, 0 );
drawobject( view, shapeIndex, textureIndex );
fglPopMatrix();

This works fine for a box, but as soon as I pass in, for example, the shape index of fs3d\FlowItem\Tote.3ds, things go horribly wrong. The reason seems to be that the dimension of the 3DS object is not 1 x 1 x 1. Is there a way to get drawobject to draw something that is exactly of dimensions xSize x ySize x zSize, either by telling drawobject to scale it to unit dimensions, or by getting the dimensions of the shape and scaling accordingly?

Thanks!

opengl3dsdrawobject
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Phil BoBo avatar image
2 Likes"
Phil BoBo answered Phil BoBo edited

You can use the applyshapefactors() command to have the Engine set the offset nodes on an object, which you can use to size the object the way you want:

See the attached example model. (I didn't test a shape with offset rotations, but I think the code that is there should handle it correctly.)

shapefactors-example.fsm


· 2
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Mischa Spelt avatar image Mischa Spelt commented ·

Thanks, it worked! I don't suppose that when I do this from C++, I can save that matrix off so I can reuse it in my next draw action? :)

0 Likes 0 ·
Phil BoBo avatar image Phil BoBo ♦♦ Mischa Spelt commented ·

Line 21 is purposefully making it so that it only enters the potentially slow code path on the first frame after you change the shape.

None of the rest of this code is going to affect performance enough that you need to cache anything.

You are trying to optimize prematurely.

1 Like 1 ·