QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: Qwerkey on January 29, 2019, 11:01:59 am
-
When putting images on screen, it is often convenient and most sensible to use Integer-type variables for x- and y- positions: the screen has only integer pixel positions, of course.
However, when using _MAPTRIANGLE(3D) the QB64 software converts the x-, y- and z- values to screen positions using some form of perspective mathematics to convert to the final (integer) screen positions. I suppose, then, that using Integers in the program calculations would use no less CPU computational effort than using Single-type variables. In fact, may using Single-type variables actually be quicker? In these days of GHz processing speeds I presume that any differences will be hardly noticeable, but is there a theoritcal difference that should guide us in setting the variable type used?
-
I can only speak to the old days, when using integers in QBasic was definitely faster. Using variables that require less memory storage is probably just faster, period, but less noticeable today the much with faster cpu speeds. I used to put DEFINT A-L at the top of my code to keep variables a-l as integers, without typing a % sign behind them. That also made coding faster! :D Anyway, Fell may have the more up to date answer here. I'm just making a presumption.
Pete
-
From my personal testing, it seems to me as if the rule of thumb is: Stick to whatever data type you're using.
Floats calculate fastest with other floats.
Integers calculate fastest with other integers.
When you mix the two, things tend to slow down from the internal conversion processes.
Again though, this is just my personal testing results, and may not apply to all PCs or operating systems. I tend to work exclusively in Windows 64-bit, so things may not be the same across the board for everyone else. It's just the general practice which I try to adhere to, personally.
-
My guess is that _MAPTRIANGLE(3D) will be working with tons of real numbers to provide a 3D effect on a 2D screen AND if converting slows things down then use numbers with decimals.
-
For MAPTRIANGLE (3D), use SINGLE variables. I also used the DOUBLE and FLOAT types but such high accuracy is not required (according to my experience so far). I'll issue another program soon with this command. Better (and a lot) than what I gave last.
edit:
Steve - it's true, but the 3D command MAPTRIANGLE is an intermediary, the converter between QB64 and OpenGL. In one part of the command, INTEGER coordinates are used (as with all normal images in QB64, that is the first part that determines what to take from the texture) but the second part of the 3D version uses the OpenGL coordinate system, meaning that the starting position is 0, 0, -1. The X to the left is negative, the accuracy is one thousandth, or higher. X right is positive. Z is the axis in and out, if Z is greater than -1 , then that is located in front of the monitor, that is, it will not be displayed. The starting point 0, 0, -1 is the camera, so if Z is behind the camera, it can not be seen. From the inside into the space is Z negative, again it is distinguished to thousands or more. The Y axis is up and down, from the center of the monitor where there is a point of 0.0, -1 if you go up, Y is positive if you go down, Y is negative. All this OpenGL coordinates are SINGLE type.
-
Thanks, Petr, this is really what I had thought. I will use Single variables for all _MAPTRIANGLE(3D) calculations in future.
Richard