Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Mathmatics and blending issues

Author
Message
Hangar18
18
Years of Service
User Offline
Joined: 13th Mar 2007
Location:
Posted: 28th Oct 2007 22:23
Having the following problems with DBC at the mo and was hoping something might be able to assist.

1) DBs mathematics is quite frankly driving me nuts. The problem is best explained via this example. Pretend this is in a for i = 1 to 300 loop and that the temp$(i) array is to 2 dps e.g. Temp$(1)="2008.08"

Temp#(i) = val(Temp$(i))*1000 + i*0.0001

Now maybe its just my version of DB (1.14 enhanced without the latest 1.2 update) but for some weird reason temp# = 2008080 and NOT 2008080.0001 (if i=1 say). I've tried a number of work arounds but to no avail.

2. I have a number of darkmatter's skyworld objects (these look like the interior of sphere that gives the impression of being on a planet) and want to put another object (a starport) in the sphere. The intention of course is to make it look like a world with a starport. The problem is the edges of the starport object are much sharper than the texture of the sphere and it doesnt look very realistic. How can i blend the edges of the starport object into the the planet sphere so it does looks realistic?

Cheers
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 28th Oct 2007 22:43
Math:

This has to do with how DBC rounds. There seems to be a maximum of 6 decimal places. But this declines as the number of digits before the decimal goes up. If there are already 6 digits before the decimal, then the decimal value disappears or rounds up the last digit befor the decimal:



You can write your own routine to display as long a float as you want and return it as a string, though that might not help you if you're requiring the precision of the float calculation. A user on the forums named Alien did a lot of work regarding large floats.

If you need the precision of the actual value and not a string, a math dll might help and also be pretty speedy.

Enjoy your day.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 29th Oct 2007 03:20
Quote: "Temp#(i) = val(Temp$(i))*1000 + i*0.0001"


DBC has a habit of sometimes assuming that if you use an integer in a formula, then you want an integer result - which may not be true. As integers are faster, I assume it could be classed as unwanted optimization!

To prevent this, you shouldn't use integer constants if you want float results. Try instead:

Temp#(i) = val(Temp$(i))*1000.0 + i*0.0001

Not saying it will fix the problem in this case, but worth trying...

TDK_Man

Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 29th Oct 2007 17:17
what they said
I haven't had experience of what TDK is saying when multiplying, but you can just add a point to the end "100 = 100." don't even need the last 0
You could also make i a float, you can't use floats in for loops though so put "i# = i" at the beginning of the loop.

"You must be someone's friend to make comments about them." - MySpace lied.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 30th Oct 2007 02:15
Quote: "You could also make i a float, you can't use floats in for loops though so put "i# = i" at the beginning of the loop."


Definitely not good programming practice to have two different types of variable with the same name. Aside from the programming ethics side of things, it's confusing to read, even if it works.

To be totally precise, it would be better to use:



but that shouldn't be necessary if you use 1000.0 instead of 1000.

TDK_Man

Hangar18
18
Years of Service
User Offline
Joined: 13th Mar 2007
Location:
Posted: 30th Oct 2007 11:39
Thanks guys, Im sort of glad to know its not a problem restricted to me. I was fearful my DB had become corrupt in someway. I even tried

Temp$ = str$(2008.08*1000)+str$(i*10)

which made temp$ = "200808010" if i=1 say
but when i did val(temp$), the "10" part disappeared!

Also, I presume there is no easy fix to my blending issue in Q2, which is good to know now before I proceed to produce a number of starports. I guess I will need to expirement a bit with what I have to see if a satisfactory result can be obtained. If not then I will most likley need to try a different track.
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 30th Oct 2007 19:15
Quote: "Also, I presume there is no easy fix to my blending issue in Q2"


I don't really understand that part of the question. Do you have a picture of what you are seeing? Is it that the starport is in the atmosphere of the planet and is inside a sphere - the texture of the sphere is of clouds and land and that is blurry compared to the starport? Or is the starport in space above the sphere, and the sphere looks blurry because of the texture?

It is possible to make a 2d background of the scene instead of having a textured object where the resolution can change, draw it to the back and have your 3d objects appear to be interacting with the environment.

Enjoy your day.

Login to post a reply

Server time is: 2025-05-31 21:08:01
Your offset time is: 2025-05-31 21:08:01