getting Object Size and Units

Started by MSL, November 26, 2013, 02:55:56 PM

Previous topic - Next topic

MSL

Hi,

When I integrated with Vuforia, the CUBE was usually lying behind the marker. Hence, it had a odd rotating feeling when we moved camera around it. This was solved by translating CUBE by its SIZE in the z-axis. If I need to display any model, now I have to do the same adjustment i.e translate the model by its SIZE in the z-axis. (Since my model will lay on the marker I think I need height of the model to use in translation)
How can I achieve this?
What method I need to use which will get me the SIZE(or height) of the model?

Above questions resulted me in getting few basic questions. They may be trivial or may be answered. I checked few posts here on this topic I was unable to get satisfactory answers. Here are the questions:

1- What does model units mean when we load them in jpct(i.e any relation between units used while creating the model in a 3D software and jpct)?
2- What are the steps that need to be taken care before loading models in jpct which will ensure "proper" sizing(and probably orientation) during rendering? (in 3D software and in jpct)
3- Is there any way of getting the size (in some units) of the model at run time (apart from getScale)?
4- What is the basis for scaling?
5- One question regarding the object position after scaling which I didnt know how to ask, so I have attached an image. If you refer the image, if the "Dist" need to be constant then on every scaling operation, I have to calculate the distance and translate the object with that distance. Is there any easy of doing this?

If anyone can answer taking consideration of model with only 1 object and model with multiple objects will be great.
For modelling I use 3DS Max.

Thanks


[attachment deleted by admin]

EgonOlsen

Quote from: MSL on November 26, 2013, 02:55:56 PM
1- What does model units mean when we load them in jpct(i.e any relation between units used while creating the model in a 3D software and jpct)?
jPCT loads everything like the exporter of the 3d modeller has written it into the file. There are no conversions done except that some loader methods have a scale parameter, which will be multiplied with the file's values.
Quote from: MSL on November 26, 2013, 02:55:56 PM
2- What are the steps that need to be taken care before loading models in jpct which will ensure "proper" sizing(and probably orientation) during rendering? (in 3D software and in jpct)
None, i would say. It's more about scaling it after loading.
Quote from: MSL on November 26, 2013, 02:55:56 PM
3- Is there any way of getting the size (in some units) of the model at run time (apart from getScale)?
Kind of. You can obtain the Mesh instance of an Object3D and that instance has a float[] that contains the bounding box in objects space (after calling build();). You can use the values in this float[] to calculate the dimensions simply by subtracting the min from the max values for each axis. You can then use setScale() to scale your models based on a reference size that you know that fits. You can make the scaling permanent as well if you do something like setScale(x);rotateMesh();setScale(1);
Quote from: MSL on November 26, 2013, 02:55:56 PM
4- What is the basis for scaling?
I don't get this question. Scaling is a just multiplication of the vertex coordinates with some value.
Quote from: MSL on November 26, 2013, 02:55:56 PM
5- One question regarding the object position after scaling which I didnt know how to ask, so I have attached an image. If you refer the image, if the "Dist" need to be constant then on every scaling operation, I have to calculate the distance and translate the object with that distance. Is there any easy of doing this?
You should be able to calculate the required translation once you have the bounding box and your required scale value.

TRowland

I think the issue that you are talking about - the object appearing as if it is 'behind' the marker is an issue caused by a mistake in the tutorial. I was facing the same issue until I noticed the setFovAngle and setYFovAngle functions in the javadocs for the camera class. The functions FOV setting methods are described like this in the JPCT javadocs:

void    setFOV(float tanFOV)
          Sets the FOV (within the limits set by setFOVLimits).
void    setFovAngle(float radians)
          An alternative to setFOV, which works directly with the angle.

and the instruction on the wiki is to calculate:

float fovYRadians = 2.0f * atan(0.5f * size.data[1] / focalLength.data[1]);
float fovRadians = 2.0f * atan(0.5f * size.data
  • / focalLength.data
  • );

    Which gives the angle for the FOV in radians, so setFovAngle(float radians) is required and not setFOV(float tanFOV) as the wiki has it. Alternatively, two atan calls can be saved if the calculation in the native code is changed to be:

    float fovYRadians = size.data[1] / focalLength.data[1];
    float fovRadians =  size.data
  • / focalLength.data
  • ;

    and setFOV(float tanFOV) is kept.

EgonOlsen

I've modified that part of the tutorial.