Jump to content

[SOLVED] Working with signed big numbers / working with transforms


photo

Recommended Posts

Posted (edited)

Hi,

What would you recommend to work with big signed numbers (especially negative) in Unigine as follow (example is from position):

            float x = -3.45554209;
            float y = -3.45553923;
            float res = x - y;  // = -2.86102295e-06 (at my machine)

I need to operate at such numbers with precision of 5 as Unigine use - to get such result:

            float xx = -3.45554; // rounded numer to 5 decimal
            float yy = -3.45554; // rounded numer to 5 decimal
            float result = xx - yy; // = 0.0

ps.

Multiplying or working with transform matrices gives the same result in the case of using substraction/negative numbers.

Something like: Math::round(-3.45554209 * 10000.0 ) / 10000.0 (or floor with +0.5) will need to have different scalar to get needed precision for each length of numer.

As I thing the round will be the solution. Or maybe something else (as operate on string? convert to int then make operations and back to float) ? If so do you have your own ideas which you use and can recommend ?  

Edited by Klimczak.Jan
Posted

Hi Jan,

What is the use-case of such calculations? What do you mean by "with precision of 5 as Unigine use"?

I've checked .world XML transform tag and there is more than 5 digits available:

<transform>0.63175809 -0.056467969 -0.7731564 0.0 0.69880027 0.47326344 0.53643543 0.0 0.33559451 -0.87912494 0.33842689 0.0 -2.9204376 -0.89930773 0.01935003 1.0</transform>

Thanks!

  • Like 1

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Posted (edited)

Hi @silent,

XML store full float numer. The 5 digits is displayed/available in Editor. The use case is to edit nodes files and to save them to disk. I am going to manipulate Node Reference in world multiplied by it's inner node Transforms but I want to see such transforms of inner node (not local or world transforms of node reference from world). 

Why I would like to compare exactly values (outside of Editor):
  a. start editing node reference in the world and set it's place as new origin (based on internal nodes transformations - it's not enought to based on node transforms parented to other node), 
  b. change transform of this node reference in the world,
  c. save changes (new position of node reference in the world and modify one of it's inner node of this node reference as add this modification based on start editing in node file).

To calculate such modifications I would like implement the same algorythm of rounding (calculating) values as Editor have to get the same math result. I thing that you could use just convert float to QString in QT to display such values in Editor. But I am courious how you are apply math for subtraction of negative floats internally ? Or maybe you just add it only ?

 

Thanks! 

Edited by Klimczak.Jan
Posted

Hi Jan,

The Editor widget is using Qstring::number method to round values:

double QDoubleSpinBoxPrivate::round(double value) const
{
    return QString::number(value, 'f', 5).toDouble();
}

 

Quote

But I am courious how you are apply math for subtraction of negative floats internally ?

AFAIK nothing fancy is used at all :)

  • Like 1

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Posted

Hi Jan,

If i understood you correctly,
I think the Editor doesn't compare values (internal or rounded) for deciding that "something has changed and it's time to save it to disk or register the Undo command". The action occurs when the user changes the field with a number or moves the manipulator's widget (translation, rotation, scale).

Best regards,
Alexander

  • Like 1
Posted

Thanks you both for all the informations :)

Cheers

  • silent changed the title to [SOLVED] Working with signed big numbers / working with transforms
×
×
  • Create New...