Hello! I have created an application that loads a set of photos and spreads them by separate windows. Each window has 2 rows and 8 columns of photos. By pressing the "right" and "left" buttons, the "window ribbon" may be scrolled left and right. This is done by first preparing two images by drawing them on PGraphics canvas and copying to separate PImages. Then the same PGraphics canvas is used to draw these images progressing their position so as for the "scrolling" effect to occure. All PImage instances are pre-created, and the copy() method is used to cache the right and left window (there images are too drawn with the copy() method to the canvas) because I know that the renderer caches the images and there is a bug in OPENGL renderer that stores them indefinetely. That first bug took me a weak of sweating while trying to find an error in my code. Finally, I was surprised by finding that topic in the internet that says that it is a bug in OPENGL and that OPENGL2 or present P3D would do fine. I have first reimplemented the render through P3D, it was lagging waaaaay toooo muuuuuch! Then I have downloaded Processing 2.04a and used OPENGL2 (which is named just OPENGL there). Same memory leak! It is not huge, but it builds up and lets only about 50 scrollings to be done.
Could anyone comment on that?
Aside from that, I am interested, how would you implement scrolling? I use the pre-draw method because aside from the images, there are also many other things drawn and the effect that I acheive is that they are not drawn while go partially out of the canvas, the PGraphics cuts it out.
EDIT: Please note that all the other things drawn aside from images are not the cause. Since commenting out the single line responsible for drawing the images, eliminates the used heap growth. I use visualjvm to monitor the condition.
Still trying to realize how to align an object to a vector.
Now I have implemented the method which uses the cross and dot products of the original and targer vector. The code below seems to work except for the rotate method doing strange thing. By replacing theta in line 37 with smaller numbers such as 0.001 and 0.01 I have found that the rotate() does not rotate ok. It also translates and resizes everything. If the 0.001 or 0.01 is in place in line 37, then I can only see the box when I move both points close to each other in the bottom left of the screen, which is reeeeely strange for me. When theta is in place, the box is almost too big to fit on the screen even at that case. The similar (in my mind) method of glRotatef() on contrary, does nothing at all. How to make the rotate() method behave as expected? (use 'qweasd' to move the bottom point and 'uiojkl' to move the upper one).
I am trying to animate a 3d character with kinect. I have been successfull in getting all the joints data ok and I can make a stick man to reproduce my moves. The problem is that I cannot get a 3d model to do the same. I know, it is much harder. I am using objimport lib for importing OBJ files and the OpenGL renderer. Can anyone suggest anything about this? So far, I have been unable to find any relevant material on this topic. I would appreciate anything - suggestions, libraries, links...
During my attempt to create a fairly complex program using Processing core library i have spent several hours trying to find a mistake in my computations, until, being already desperate, I fell back to the Processing IDE and reproduced the situation in a very simple example. And that's where I was surprised! The 'rotateZ()' method does not what it's name claims for. I am not sure what it does, but definetely it is not rotation around the Z-axis (as opposed to it's ok-buddies rotateX() and rotateY()). Below is the sketch example which gives an idea what am I talking about. The idea is very simple - there is a prolongated box positioned exactly between two points. The points can be moved in the 3D space by 'qweasd' and 'uiojkl' keys respectively. The box is intended to maintain it's polarized orientation between the points. And it does NOT. Am I mistaking? What is the right way to acheive this?
There is some weird view distortion in my app when displaying meshes loaded from obj files. I am not sure if it is related to the error 1280, but it wasted everything (.
I have been searching for answers to this and looks like the error occures much, but there is no only reason for it and no uniform solution. I have been unable to find any sensible information regarding the error nature except for that it occures when there is some malformed data passed to OpenGL. For me it occures every time i load ANY obj file with Pixelnerve objimporter. The error seems to be not critical in terms that it does not crash the application, but if it's there, then there must be something wrong.
The application does not crush, but, however, there is something strange happening when it runs. After several hours trying to find a mistake in my computations, I have localized the cause in a very unexpected place. As only I try to display any loaded mesh, with this code:
...the image gets corrupted. It looks like that the projection matrix is turned by 90 degrees ccw around the Z axis (the bottom side now becomes the right side) and something happens to the focal length of the vision. Everything becomes smaller and stretches by several times across the Z axis. If I comment out the single line of drawing the model, all is fine!
I am not sure if the view distortion is somehow related to the error 1280 but I think that it might be some problems with the endDraw() and the matrices do not get correctly arranged or something.
I also have to say one more thing: the application is running in 16:9 mode, the transformation is done like that, at the begging of every draw cycle:
context.gl.glMatrixMode(GL.GL_PROJECTION);//setting up the far clipping plane and aspect
context.gl.glLoadIdentity();
context.gl.glFrustum(-1.77777, 1.77777, -1, 1, 1, 100000);//the 1.7777 / 1 thing is the 16:9 aspect ratio
context.gl.glMatrixMode(GL.GL_MODELVIEW); //returning to model drawing
The
context variable is of type
PGraphicsOpenGL which is actually cast from
GLGraphicsOffScreen from codeanticode OpenGL library for Processing. The resulted off-screen texture is then displayed as an image, composed with other graphics components such as 2D controls. However, I am not sure if this is somehow related to the problem since commenting these lines does not influence the distortion behavior, it still remains.
EDIT: The -90 degrees rotation is actually performed by my code. There is an option to rotate the context cw or ccw. But now I find that for some reason the keyboard button that does this, has no action when no model is displayed. The rotation is done through the rotateZ method, which looks like this in GLGraphicsOffscreen:
public void rotateZ(float angle) {
if (glMode) gl.glRotatef(PApplet.degrees(angle), 0.0f, 0.0f, 1.0f);
Hello! Using toxiclibs, I cannot find a method to calculate accurate spline curve length or something similar. Is there anything pre-built or do I have to do it manually?
As far as I understand, a serious benefit of Processing was that it used it's own P2D renderer instead of Java2D which is slow and much less versatile. Now I have read that the P2D and P3D renderers are going away with Processing 2.0!!!
Now I have this question - does it mean that developing 2D sketches in Processing would be not so fun anymore? Will they get slower in graphics? Or will I have to use OpenGL for everything instead of P2D? I made a heavy use of P2D so what would I want to do then? Would I just switch to the OpenGL renderer entirely? Is this change a loss or is it a gain?
1) Please tell me what are the main pros and cons of using OpenGL instead of a P*2 renderer in Processing?
2) How much rewrite is expected?
Please note, that I am pretty familiar with OpenGL, but only from the C++ perspective. Do not know about the Processing approach..
My application is a game.. where I need to display 2D interface as well as 2D map with units... Probably going to add a 3D depth, who knows... the graphics is in its early stage so I am asking his before everything, just for planning..
Hello.. I have come across a problem when I can't make an image transperant. My program loads images into a database, making black transperent (which works fine). Some of the images have to be half-transperent. I have modified the function which filters black (by putting absolutly transperrent pixels in place of black ones), so it would put half-transperent pixels instead of all. But it just does nothing. The only result I was able to get - is to either make the whole image transperent (unseen) or opaque. Here is the routine:
So, in my opinion, the red line should make alpha of value "CC". Which it does not. What is the trick? How can I make the image transperent? Using tint() is not an option, since the images are pre-loaded.
I have several threads... main thread, keyboard tracker thread, java nio connection manager and a number of some worker threads... my question is - do I need inserting a 'Sleep' command in each of them? I have heard that if a thread never sleeps, it loads the CPU up to the cap.. is it true? Do I need to put 'Sleep' in each of them? If so, then, in case with the Keyboard-Tracking thread, will it result in delayed key-watching (this is what concerns me the most)?
Some time ago I posted here a question on how to make my existing game java-nio-multiplayer enabled since I am totally new to network programming.. Alright, since then I have made everything going. And while the project is still in development, all is working fine. However, there is one more question on Java NIO that i can't answer myself: how to make the channel simultaneously bi-directional?
Let me explain what I mean. Java NIO philosophy is based on SelectionKeys that have some interesting ops set. For example, there are SelectionKey.OP_READ and SelectionKey.OP_WRITE interests. When one of these is set, the channel is considered operable in one of these ways (read/write). Thus the interest has to be changed accordingly to what am I going to do. The decision is based on fact that something is needed to be written to the channel. But there is no inherit way to determine if it is so. So, when finished sending all info, the sender, sends a NetworkReady message, and turns to OP_READ. All data on the receiver is read and processed. The last message that comes from sender is the NetworkReady. Upon receiving this message, the receiver changes his state to OP_WRITE. All this means that now the sender and receiver have swapped their roles. Let me illustrate:
A - OP_ACCEPT
W - OP_WRITE
R - OP_READ
HS - Handshake
D - Useful data
N - NetwrokReady
s - server
c - client
1. s(A) server awaits connections
2. s(A) <- c client connects
3. s(W) -HS+N-> с(R) after successful connection, client becomes R, server becomes W.
4. s(R) <-HS+N- с(W) client responds with handshake
5. s(W) -D+N--> c(R) starting to send useful data
6. s(R) <--D+N- c(W) this way
7. s(W) -D+N--> c(R) that way
8. s(R) <--D+N- c(W) this way
9. s(W) -D+N--> c(R) that way
.. s(R) <--D+N- c(W) this way
.... and so on.... and so on...
When a client needs to send something to the server, the server is already listening for it and waiting. When a server wants to send something, then client is ready and waiting. So everything is OK! It all works just fine! WITH ONE BIG EXCEPTION.
Usually the server is in R mode and the client is in W mode. This is fine because user may send new data to server.
When a second client joins, all work fine. But when one of the clients sends a message to the server, the server needs to send the situation update to the other client. However, the other client is in WRITING mode and CANNOT accept the situation update Useful Data despite it is queued on the server. When something is done on the second client, the roles are swapped and the queued Useful Data is sent.
So obviously, there is a flaw in the operation mode when server is always R and client is always W.
My question is: Is there a way to organize the connection so that both sides could send and receive messages freely?
My only guess is to create two distinct channels for the two distinct directions s(W) -> с(R) and с(W) -> s(R) which will never change their interests. However, this seems a little strange to me... is there any BETTER way to organize this?
I have come across a problem. When I debug my code in Eclipse, I set a breakpoint and it stops right there. This is ok. If I click Step In or Step Over, it again does all as expected. But when it eventually comes to the end of the main program loop, it turns out that it comes to the end of the draw() function, and then, as I understand, it tries to dig into Processing core.jar which source I do not have. Eclipse then stumbles with message that the source code is not available. This is ok, I do not need to debug Processing, I need to debug my code, but how can I acheive this? Is there any way to sort of "jump over" all the stuff that does not have sources?
Searching over the internet I have found the only solution - to download sources for the jars. This is really silly. Why can't Eclipse just skip them? Is there any way?
For I mean, will the indices be updated correctly in the second case as they are i the first one? Or in other words, if I do ArrayList.remove(0), will the element that was at position 1 become the element at position 0? Are there any unobvious consequences in such a situation? Any speed difference?
I have partly made a simple computer game and now I want to make it multiplayer ( I want to start multiplayering it while it is still in alpha, so there will be less problems later. The gameplay is already partly in place, so it is quite reasonable. ). Because the game is strategic and has a persistent world, I would like to make the network code based on NIO rather than on blocking sockets (so that it could hold many hundreds of clients and, as a side effect, I would gain a good knowledge of nio). I know there is a huge amount of work for me to do but it is ok because I know how to do everything except for NIO. The problem that I have is that I cannot figure out how to write the NIO code properly... All this NIO thing seems just alien in its logic to me (since I do not understand it YET).
To give an idea of what I want it to look like, here is a code of a server that I took as an example:
It has the Login, Lobby and Game sections. However, it has no auth section and is written using the blocking sockets. So I have read MUCH about NIO and written my server and client as in all these similar "basic" NIO examples (just plain boring "hello"-"hello" thing). But still I can't understand how to create the separate handshake, authorization, lobby and game rooms? From what I understand, there should be ONE selector for the server, which should manage all connections? What keys and interest ops should be used and how?
Could please anyone describe, how to write a server that has all these facilities? Which way to go?
The question this time is very clear, my friends... which way is faster? Direct access or getters/setters paradigm? How much is the gain in speed if it is at all? Please know that I do not mind making public everything that needs to be it since I make no mystery of my code and.. well it is even unlikely that someone else is going to use it sometime.. since I know this kind of concern to be one of the cornerstones of the getter-setter-blackbox thing...
Today there is a question about 2D zooming. First I explain my settings:
1) I have a 2d space (starmap), where objects(stars) are located arbitrary.
2) The screen only captures (screen.size.x, screen.size.y) area of the space thus allowing us to see just a little part of the map. Same as in all the RTS games.
3) The screens center position on map is called "offset".
4) The screens dimensions are called "size"
All in all, at the beginning, when the offset=0, we see the [-size/2 to +size/2] portion of the map. If the offset moves, we see [offset - size/2 to offset + size/2] region of the map.
Now everything was fine until i started implementing zoom.
5) The zoom is uniform (not differentiated by axis) and called "zoom"
6) The stars position on the map is called "position".
Using pen and paper I have came up with formula for projected star position (the x and y equations are not explicitly described here since they are same as the ones below except for the axis index like
size.x instead of
size):
and it all works! At least at zoom factor=1 when it is like there is no zoom. When i start zooming, it works too, but it seems to me that the
criterion has a flaw because stars start disappearing on the left and up edges of the screen before they get off-screen.
I understand this to be a simple math problem, consisting of several overlayed coordinate projections... however, I got stuck here a little. I would like someone to suggest corrections to these equations or some different equations that would do. I also want to be able to un-project mouse screen coords back to the map coords. This now works for zoom factor=1 but due to the mysterious errors in the equations, the mouse projection gets incorrectly altered on different zoom factors... please help!
I have a class Object, which gets extended by LowObject, HighObject, BigObject, SlowObject and other.. the class body of Object contains a
static int type = 0;
statement which represents it's type for switches in my program. Accordingly I have initiated similar things in all the other classes like
static int type = 1; //for LowObject
static int type = 2; //for HighObject
and so on...
Then when I get an Object, passed as a function parameter, I want my switch to know which type of object is it actually. Objects of class Object never meets in the program, it is merely a reference template. But then, in the switch(passedObject.type) statement, it always says that passedObject.type = 0!!! Actually this seems quite logical to me now.. but still I have this question: how can I effectively determine, which one of the extended classes does the passed object belong to?
If possible, I would not like to use reflection. Is there any memory and time cheap approach for such an issue?
So I have succeded creating the offscreen buffer with the createGraphics() function, drawing to it with the standard plotting functions and displaying it as a PImage object. However, I have noticed a strange behavior of the rendering.
1st strangeness: if I call the smooth() function after the beginDraw(), the resulting image gets smoothed and everything seems fine except for that at the time of actual display, it gets an unwanted offset of something like x+50 and y+50. That is, the image gets this offset by just one "smooth()" function. If I comment it out - all is fine. Does anyone has a clue if it is a bug and if is gonna be fixed?
2nd strangeness: the output picture gets truncated on the bottom and on the right. So instead a picture of, say, 600x500 i get only th first 400x400 portion of it or something like that (i did not measure it yet). I am almost sure that my plotting routines cannot be the reason of this. Is there any known technical reason and a workaround for it?
The two strangesses above are cumulative.
Notice: I cannot post my code here since it is big (I use Eclipse to handle it), there is much unrelated stuff, and sometimes broken incapsulation (due to my present faulty programming style, but I'm trying). Although, I can post parts of it if needed.
When using P5 with Eclipse, I have to reference the main applets graphical context from some objects of the program (say, in their display() functions). All in all with time it starts looking like this:
this.parentPlane.parentWorld.parentGame.parentTestProject.line(x, y, xx, yy);
Where
this is an object of class "Ship" which dwells in one of the Planes of the World which in turn is one of the Worlds of the Game which itself is a child of the main TestProject class which extends PApplet and posesses the main graphical context
g.
My question: is this ok that I have references of such length? Is there any other (better) way that programmers would use instead of this? My only guess is to replace multiple lines with this same reference with something like:
Hello everyone, I have this question, which may have been asked many times already, but I cannot find any reference on this topic regarding a method, applicable for Processing.
The point is that I want to be able to draw to an image thus creating my custom rendering canvas. The image is then to be placed into a custom GUI window. Thus the result will be a window inside my program, which holds an area, dedicated for graphical output. The main idea is to create a resizable and moveable rendering viewport inside my main programs window... How can I do this? Is there any better way than rendering to an image?
EDIT: I have found that an instruction like
PGraphics pg = createGraphics();
might save me but it confuses me that the reference says that the createGraphics() method returns Pimage!!! So should I manage to use these methods somehow? I want to be able to use the standard line(), image() and other functions for this my custom context..
Maybe this question is more about java, but probably somebody knows the answer...
I have an application which is intended to process some data. The data processing is done by executing a list of commands(program or script), stored in an ArrayList. The script may be loaded from a file and be something like this: GET (ITEM 1234) SET (33) and so on... nevermind.
All commands extend the basic class Command and look like this:
GetItem extends Command
{
String scriptName = "CREATE";
int argNum = 1;
Data data;
int itemNumber;
....
GetItem(Data data_, itemNumber_)
{
data = data_;
itemNumber = itemNumber_;
}
int execute()
{
return data.get(itemNumber_);
}
}
The question is this: can I let the application to load some custom classes describing commands? That is, can I make the list of available commands easily extensible? Say, all command are listed in some text file:
CREATE : CommandCreate.pde
Currently the application may only support the set of commands that were fused into it during creation. So is there any way to make it support adding custom commands as class files? Maybe some sort of try-catch would work?
I have no idea on how to create a server that can handle multiple clients (10 or 100 or 1000 or up to infinity, with known limitations...).
And a client.... well, i suppose, i understand a client well, from the processing network lib example.. but not server.
Say, if my server has 1000 clients active in average... do i need to store them in an ArrayList? I would like to be aware of each client that I have connected and also to be able to detect new connecting clients and clients that disconnect. Well, I think you understand, somthing like a chatroom, where on the server side I would be able to track any client and know any of his info.
Also, all the clients that are present, must be processed (listened to their messages, executing the commands embedded in their messages and sending them back the global server world situation update)
Hi, I am developing an application, where some objects move in a 3D space. I am using OCD as a camera lib. I need to somehow be able to project mouseX and mouseY to the 3D worlds "ground" plane so that if I click the mouse, the objects may get arranged around the point and so that i can select the objects with the mouse. Also I need to be able to project a 3D point to the screen to get some objects data displayed next to the objects.
Ideally the functions would look like this:
float[3] projectPointIn3D(mouseX, mouseY);
float[2] projectPointOnScreen(x, y ,z);
I know that all this is about ray/plane intersection but it involves too much math for me to dive into it right now. Do you know any library to help me with this? Or at least any good source of information where the math is described in a digestible way?
Maybe I have a stupid question, but tell me please how keyPressed with "key" and "keyCoded" handles multiple keystrokes. How to work properly with multiple keypresses?