|
Author |
Topic: Starting with Processing - few questions (Read 763 times) |
|
Andre_Michelle
|
Starting with Processing - few questions
« on: Jul 20th, 2004, 9:06pm » |
|
hi all, just starting with processing and having a few questions: Is it not possible to detect 2 Key simultanous ? I'm dealing with a reaycastengine with processing. Or is it better to handle the 3d engine from processing ? What is the fastest way to check, if and Array entry is valued ? (try and catch seems to be very slow in a loop.) -- aM
|
« Last Edit: Jul 21st, 2004, 12:27am by Andre_Michelle » |
|
|
|
|
mattgilbert
|
Re: Starting with Processing - few questions
« Reply #1 on: Jul 21st, 2004, 2:47am » |
|
regarding your keyboard question: the "key" variable gives you the last key pressed. you could keep track of what keys have been pressed by storing their values in an array or ArrayList or something from the mousePressed() method, and then removing them when they are released, using the mouseReleased() method. i don't know about your 3D question, and i don't understand try/catch stuff well enough to help you there. matt
|
|
|
|
narain
|
Re: Starting with Processing - few questions
« Reply #2 on: Jul 21st, 2004, 6:03am » |
|
"if and Array entry is valued"? If I understand you correctly, either you mean 1. does the array location exist, ie. is it within the range of the array? or 2. is there anything stored in that location? 1. You can get the size of the array by array.length, which is an int. All locations from 0 through array.length-1 are accessible. 2. If it's an array of numbers (ints or floats), all locations are initialised to zero by default. Otherwise they contain the special (non-)value null. The fastest and simplest check is just if (array[i]), which just checks whether array[i] != null.
|
|
|
|
TomC
|
Re: Starting with Processing - few questions
« Reply #3 on: Jul 21st, 2004, 11:28am » |
|
on Jul 21st, 2004, 6:03am, narain wrote: The fastest and simplest check is just if (array[i]), which just checks whether array[i] != null. |
| Not quite. That's valid in C, I think, but in Java you have to explicitly check if (array[i] != null). For tracking multiple keys, you need to use the keyPressed and keyReleased functions - fry describes this method here: http://processing.org/discourse/yabb/board_Contribution_Physica_l_action_display_num_1082541220_start_1.html (can somebody add this as a technote, or a tutorial example)
|
|
|
|
narain
|
Re: Starting with Processing - few questions
« Reply #4 on: Jul 21st, 2004, 12:33pm » |
|
Oops... my mistake. I assumed it would get typecast, but Java doesn't do that.
|
|
|
|
Andre_Michelle
|
Re: Starting with Processing - few questions
« Reply #5 on: Jul 21st, 2004, 5:29pm » |
|
Thanks you guys, i didn't receive an email, that my post was moved. First here is my first processing thing: http://www.andre-michelle.com/processing/raycasting/ -- @mattgilbert: Did I have a keyUp Event ? Havn't noticed, yet. Ok. Build in @narain: Please take a short look in my sourcecode (class Camera, method 'render'). I have to scan a 2D Array for entries and must break the loop, if the entry isn't defined. First time I took a try/catch construct, but the performance descreases to much. You can see now, that I have implement a lot of if's... More Questions at all: Even a empty Processing file can only have up to 50 frames per second ? In the moment I use 'image()' to draw the stripes, but this seems very slow. any suggestions ? thanks, it will be fun to make more
|
« Last Edit: Jul 21st, 2004, 5:53pm by Andre_Michelle » |
|
|
|
|
Andre_Michelle
|
Re: Starting with Processing - few questions
« Reply #6 on: Jul 21st, 2004, 6:11pm » |
|
Find some weird things. background() to clear the last frame in a loop lower the fps about 100(!) on my machine. A for loop through the pixels Array is about 50% faster.
|
|
|
|
narain
|
Re: Starting with Processing - few questions
« Reply #7 on: Jul 22nd, 2004, 6:59am » |
|
"Even a empty Processing file can only have up to 50 frames per second ?" Maybe so; or maybe maintaining a fps counter is slowing it down (all those millis() calls...) I can't say I can help much with your array/loop problem; I don't really know what that method is doing. All I can say for now is, well, if you're accessing an array at arbitrary locations, you generally can't avoid putting in such if/else's. (They don't really reduce performance much, anyway.) One thing you can try is to write the loop itself in such a way that it stays within the bounds of the array, but that's not always possible.
|
|
|
|
fry
|
Re: Starting with Processing - few questions
« Reply #8 on: Jul 23rd, 2004, 5:05pm » |
|
i'm not sure what you'd do with more than 50 frames per second, unless your eyes are 20 fps faster than the rest of us humans. the framerate of an empty sketch is limited by the speed of java (and your machine), and there's not a whole lot we can do about it. clearing the screen with background() is a very slow operation, unfortunately. haven't found a way to speed it up. methods specific to java 1.4 will probably let us do this, but 60% of web users seem to be using 1.1 still. i should also note that the goal of processing is that of a kind of sketchbook or learning tool. if you're looking for high frame rates, c++ and opengl is where it's at. and the reason that clearing the pixels array yourself is 50% faster is because you're only doing half the work: you're not clearing the z-buffer of all its 3D information. (fwiw, by the time beta rolls around, the zbuffer will no longer be kept for apps that are 2D only)
|
|
|
|
lunetta
|
Re: Starting with Processing - few questions
« Reply #9 on: Jul 23rd, 2004, 10:22pm » |
|
on Jul 23rd, 2004, 5:05pm, fry wrote:i'm not sure what you'd do with more than 50 frames per second, unless your eyes are 20 fps faster than the rest of us humans. |
| http://www.100fps.com/how_many_frames_can_humans_see.htm here's some useful information on fps debate...
|
|
|
|
Andre_Michelle
|
Re: Starting with Processing - few questions
« Reply #10 on: Jul 28th, 2004, 4:40pm » |
|
thanks for your answers. I have changed the draw routine of the slices by placing pixel per pixel (not using image()) and it pretty fast now. See the updates here, if you like http://www.andre-michelle.com/processing/raycasting/ @fry: I have problems to get a smooth fps by setting it with framerate(x). Even when I set the framerate to 30 it can be, that the movie runs with 40 fps, but the movie seems to stutter, even though it can run faster (over 50fps). Maybe I find a solution for that myself. I have another strange behavior on different windows machines (fast enough, IE). On some machines, the keys won't captured (even on keyfocus). The engine seems to work, but you cannot move. Just take a look in the source. I handle Booleans for the keys status. Any suggestions ?
|
|
|
|
fry
|
Re: Starting with Processing - few questions
« Reply #11 on: Jul 28th, 2004, 5:26pm » |
|
re: framerate(), i've run across that as well, though i haven't had a chance to look into it further. i'm guessing it's something like the thread being just behind the refresh rate, causing little hiccups. it's on the list to be looked into. i've heard of key problems with applets that have a 'code' folder, but i haven't heard of keys just having trouble in general (aside from the operating system's key repeat causing a key on/off event to happen even though the user still has the key down). you can also override java's "public void keyPressed(KeyEvent e)" and keyReleased to fully handle the key events yourself instead of letting p5 do it.
|
|
|
|
|