Author Topic: Is It Quicker to Work with Single Variables When Using _MAPTRIANGLE(3D)?  (Read 4079 times)

0 Members and 1 Guest are viewing this topic.

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
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?

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Is It Quicker to Work with Single Variables When Using _MAPTRIANGLE(3D)?
« Reply #1 on: January 29, 2019, 12:33:13 pm »
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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Is It Quicker to Work with Single Variables When Using _MAPTRIANGLE(3D)?
« Reply #2 on: January 29, 2019, 01:16:27 pm »
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.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Is It Quicker to Work with Single Variables When Using _MAPTRIANGLE(3D)?
« Reply #3 on: January 29, 2019, 02:16:51 pm »
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.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Is It Quicker to Work with Single Variables When Using _MAPTRIANGLE(3D)?
« Reply #4 on: January 29, 2019, 02:54:05 pm »
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.
« Last Edit: January 29, 2019, 03:04:58 pm by Petr »

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: Is It Quicker to Work with Single Variables When Using _MAPTRIANGLE(3D)?
« Reply #5 on: January 30, 2019, 05:09:24 am »
Thanks, Petr, this is really what I had thought.  I will use Single variables for all _MAPTRIANGLE(3D) calculations in future.

Richard