Login x
User Name:
Password:
Social Links Facebook Twitter YouTube Steam RSS News Feeds

Members Online

»
1 Active | 90 Guests
Online:

LATEST FORUM THREADS

»
CoD: Battle Royale
CoD+UO Map + Mod Releases
Damaged .pk3's
CoD Mapping
heli to attack ai
CoD4 SP Mapping

Forums

»

Welcome to the MODSonline.com forums. Looking for Frequently Asked Questions? Check out our FAQs section or search it out using the SEARCH link below. If you are new here, you may want to check out our rules and this great user's guide to the forums and the website.
For more mapping and modding information, see our Wiki: MODSonWiki.com

Jump To:
Forum: All Forums : Call of Duty
Category: CoD Mapping
CoD mapping and level design.
Moderators: foyleman, Foxhound, Mystic, StrYdeR, batistablr, Welshy, DrBiggzz, supersword
Latest Posts
Subscribed Posts
Search
Restricted Access Topic is Locked subscribe
Author Topic: Rounding floats for display
RRMS-Gumby
General Member
Since: Jul 17, 2006
Posts: 10
Last: Jul 31, 2006
[view latest posts]
Level 0
Category: CoD Mapping
Posted: Tuesday, Jul. 25, 2006 06:53 pm
I have a float I'd like to display on the HUD, but I cannot find a way of rounding or truncating it, so I end up with numbers like 28.3337.

Can anyone tell me what function(s) I can use to either round or truncate floats? Barring that - how do I make it an int for display?

Secondary [q] - how do I get the width of a HUD element? I want to position HUD elements relative to each other.

Thanks!
Share |
The_Caretaker
General Member
Since: Jun 8, 2004
Posts: 11625
Last: Jul 7, 2009
[view latest posts]
Level 10
Category: CoD Mapping
Posted: Wednesday, Jul. 26, 2006 04:12 pm
the FloattoInt function should work in C++ and C.. maybe it will work in QuakeC too?

Else you can use fabs, but I think you need to have the math library for that to work and I've got no idea if CoD knows that much :p


As for the HUD element.. all elements are pictures.. so you can just open the picture and see what the width is.


Share |
RRMS-Gumby
General Member
Since: Jul 17, 2006
Posts: 10
Last: Jul 31, 2006
[view latest posts]
Level 0
Category: CoD Mapping
Posted: Wednesday, Jul. 26, 2006 04:31 pm
Caretaker:

Thanks for the response.

I will check again for any of those functions, but I didn't find anything which looked promising on my first time through.

With the HUD stuff...
I'm creating some of the elements dynamically, so there are no pictures to open. For example, when I display something like this using setValue() on the hud element:

Foo: 98.3

I want to then get the dimensions of it so I can place things around it. [I tried .length and .size, but no luck - thinking there might be a member var or function.]

edited on Jul. 26, 2006 12:32 pm by RRMS-Gumby
Share |
The_Caretaker
General Member
Since: Jun 8, 2004
Posts: 11625
Last: Jul 7, 2009
[view latest posts]
Level 10
Category: CoD Mapping
Posted: Wednesday, Jul. 26, 2006 04:37 pm
If the floattoint is not working you can always do it the other way:

Something like this.. from the top of my head.. no guarrentee for exact syntaxes etc.

I asume "number" is the number to convert

makeint()
{
counter=0;
convertnumber=number;
while (convertnumber >0)
{
convertnumber--;
counter++;
}
return counter;
}

now the number "counter" should be the rounded down number (1.99999) becomes 1 in this case.. (you can make it rounded up by setting counter to 1 in the begin)
Share |
RRMS-Gumby
General Member
Since: Jul 17, 2006
Posts: 10
Last: Jul 31, 2006
[view latest posts]
Level 0
Category: CoD Mapping
Posted: Sunday, Jul. 30, 2006 08:24 pm
Being your standard lazy programmer, I don't like having to roll my own basic functions... but as per Caretaker's suggestion, here's my solution:

Quote:

// Power() - returns 'base' to the 'exp' power
// Note: this is not meant for math-intensive computation
// Note: does not handle negative exponents
// RRMS-Gumby

Power( base, exp )
{
switch( exp )
{
case 0:
return( 1 );

case 1:
return( base );

case 2:
return( base * base );

case 3:
return( base * base * base );

default:
break;
}

if ( exp < 0 )
return( undefined );

result = 0.0;
result = result + base;

for ( i = 1; i < exp; i++ )
result = result * base;

return( result );
}

// RoundToDecimal() - returns 'number' rounded to 'numDecimals' decimal places
// Note: this is not meant for math-intensive computation
// RRMS-Gumby

RoundToDecimal( number, numDecimals )
{
if ( number == 0 )
return( 0.0 );

if ( numDecimals < 0 )
numDecimals = 0;

power10 = Power(10, numDecimals);

neg = false;
if ( number < 0 )
{
neg = true;
number = number * (-1.0);
}

shift_number = number * power10;

result = 0.0;

while ( shift_number > 1.0 )
{
shift_number = shift_number - 1.0;
result = result + 1.0;
}

if ( shift_number >= 0.5 )
result = result + 1.0;

if ( neg )
result = result * (-1.0);

return( result / power10 );
}


Hope someone finds it useful.

If anyone knows the built-in functions for any of this, please let me know!

[BTW - the CODE tag in this forum does funny things to the code and without it I lose all the indentation. Grrrr...]

edited on Jul. 30, 2006 04:25 pm by RRMS-Gumby
Share |
Restricted Access Topic is Locked subscribe
MODSonline.com Forums : Call of Duty : CoD Mapping

Latest Syndicated News

»
Codutility.com up and runn...
Nice, and there still using the logo and template for the screenshots, which...
Codutility.com up and runn...
dundy writes...Quote:Call of Duty modding and mapping is barly alive only a ...
Codutility.com up and runn...
Mystic writes...Quote:It seems to me the like the site is completely dead? ...
Codutility.com up and runn...
It seems to me the like the site is completely dead?

Partners & Friends

»