View Full Version : Space bar echoes ?
Hi Petr, (or any one else who knows)
Because of the complex view and a clearer look in 2D, I tried to make a switch via the space-bar.
Seems only a very short touch works (the keystate is reset in the loop - program a delay ?? ).
(program uses the arrow keys for rotations, and PgUp/Dn for changing the parameters)
Thanks in advance
Rob
Petr Schreiber
09-10-2013, 19:31
Hi Rob,
I have two tips for you:
move tbgl_resetKeyState before while loop
use TBGL_GetWindowKeyOnce instead of TBGL_GetWindowKeyState
Let me know,
Petr
Petr Schreiber
09-10-2013, 19:41
And one more tip - I noticed you add to the variables like:
If TBGL_GetWindowKeyState(hWnd, %VK_LEFT) Then rx=rx-3
Coding this way in while cycle will result in different speed on different PCs.
The basic way around this is to think - how much I want the value to change over 1 second?
Let's say we want the rotation to be 360 degress per second. All you need to do is to scale the addition relatively to current framerate:
If TBGL_GetWindowKeyState(hWnd, %VK_LEFT) Then rx=rx-360/FrameRate
' -- Alternative
If TBGL_GetWindowKeyState(hWnd, %VK_LEFT) Then rx -= 360/FrameRate
This will make your graph rotate at the same speed on PCs with different performance.
Petr
P.S. The script producess really impressive visualization, very nice!
Thanks Petr,
TBGL...once works ! (with ..reset.. outside the loop).
Framerate : thanks, I will remember .. but on my old 'puter I take all the speed I can get (at least for these kind of programs).
There's something else , this programs uses the same method both for 2D and 3D - only the z=0 for 2D. The matrix contains exactly the same number of coordinates, yet rotations seem to go faster in the pseudo-2D - seems some filtering is done (at pixel level) - is that a TBGL or an (open)GL mechanism ??
It doesn't matter much here, it's a dynamic model any way - but for static objects (without "inbetween" calculations), I intended to write some algorithms filtering duplicate data - but if TB/Open GL already does so, there's no need.
These quadratic mappings are rather tricky , a certain point (x,y) may have several z values ... and even worse , points can start generating closed curves and repeating themselves - (at pixel level)
Thanks again, Rob
Petr Schreiber
10-10-2013, 19:14
Hi Rob,
that is interesting observation you have, it makes me suspicious regarding your OpenGL drivers.
Could you please check this thread:
TBGL Troubleshooting (http://www.thinbasic.com/community/showthread.php?t=7848)
and download & run the OpenGL_GetInfo.tBasic from there, and post the results please?
Petr
Hi Petr,
Software emulation :-( .. started when installing Win7, also used the recovery partition for a Linux distribution.
(it's an old recycled computer, on the one I have for the job, everything runs much smoother ).
best
Rob
Petr Schreiber
11-10-2013, 15:06
Okay - that means you use Microsoft OpenGL implementation, all computed on CPU.
Try to find out the name of your graphic card/accelerator - you will see that after installing the proper driver, which I will help you to find, the speed will boost up significantly, even if you have Intel GPU.
Petr
Dobri Den ! (IIRC - been a while since been in CZ republic - for a while I have been working for a Russian chemical Cy)
Thanks again ( I think I'm some Urquell's in debt now ;-)
I used a nice little program to investigate the architecture of the computer (I attached it , it can be at use for you when digging into computers).
Went to the Intel site, but no drivers above XP available.
After some googling, found other people with a similar problem - and it seems someone made a hack for Win7.
Works perfectly (though, I had to change some settings before Win7 wanted to run it).
All sunshine now .. Your program outputs .. OpenGL correct installed ;-)
No slow-downs ani more, everything runs at a constant speed (though 64 Mb is nothing compared against what is exhibited here -- never mind, forces me into smart programming ;-)
(btw : do not know you have a mathematical background -- but in case of the twin primes , after some thinking about them, I found their sum is always (except the first one) a multiple of 12 (or 12) - this knowledge speeds up calculations 6x. The proof is very easy, but one has to look for such things ... )
thanks again Rob
Petr Schreiber
13-10-2013, 00:33
Dobrư večer! :),
thank you for good news, I am happy OpenGL now runs as designed! 64 MB is actually lot of memory, I remember beautiful game called Giants: Citizen Kabuto used just 16MB, if I am not mistaken, and yet it looked amazing.
I didn't knew the feature of primes you mention, interesting indeed. When I need prime numbers in range, I usually go the dirty way - going in the range and testing with IsPrime, but that is the approach of the lazy one :)
Petr
Hi Petr,
The speed-up comes from the fact that when the sum of two twin primes is a multiple of 12, the "parent" (the number between them) is a multiple of 6, and you only have to test these.
n + (n+2) = k.12
2(n + 1) = k.12
n+1 = k.6
The difference in speed can be tested with the attached program.
The speed of TB is good, after all one pixel-width represents 1000 numbers.
best Rob
Petr Schreiber
13-10-2013, 14:51
Very nice,
I can notice the speed difference even on my Core i5 PC:
Brute force: 0.590s
Smart: 0.185s
The visualization using canvas looks great...
Petr
;)Hi Petr,
"Smart Oxygen" was still missing.
I cheated a little , the (boolean prime/not prime) sieve is already made before the "start" button can be clicked - i don't use IsPrime this time ... difficult to time (unless you split it in two) -- but it should be very fast.
Putting up a table/matrix before the program starts was not uncommon -- I do remember the GFA compiler had functions as SinQ / CosQ etc.. , the value was not calculated but taken from a pre-defined array (with 1 degree intervals -- for games (etc) more than accurate enough) -
best, Rob
(because of static images, I did not use TBGL , but the slower Canvas methods )