views:

44

answers:

2

I am relatively new to Processing but have been working in Java for about 2 years now. I am facing difficulty though with the translate() function for objects as well as objects in general in processing. I went through the examples and tried to replicate the manners by which they instantiated the objects but cannot seem to even get the shapes to appear on the screen no less move them. I instantiate the objects into an array using a nested for loop and expect a grid of the objects to be rendered. However, nothing at all is rendered. My nested for loop structure to instantiate the tiles:

for(int i=0; i<102; i++){
   for(int j=0; j<102; j++){
      tiles[i][j]=new tile(i,0,j);
      tiles[i][j].display();
   }
}

And the constructors for the tile class:

tile(int x, int y, int z){
this.x=x;
this.y=y;
this.z=z;
beginShape();
 vertex(x,y,z);
 vertex(x+1,y,z);
 vertex(x+1,y,z-1);
 vertex(x,y,z-1);
endShape();
}

Nothing is rendered at all when this runs. Furthermore, if this is of any concern, my translations(movements) are done in a method I wrote for the tile class called move which simply calls translate. Is this the correct way? How should one approach this? I can't seem to understand at all how to render/create/translate individual objects/shapes. Thanks for any help any of you are able to provide!

A: 

Transformations (such as translate, rotate, etc) do not work if you use beginShape() as you're simply specifying direct coordinates to draw to. If you're relying on the result of a translate to put an object into a visible location that could be why you're not having any results.

Also, depending on how you're looking at your scene, you probably have z coming towards the camera, so your objects are being drawn with you looking at them on the side, and since they are 2d objects you won't see anything, try using x/y or y/z instead of x/z which you are doing right now.

Tyler
in that case, how would I correctly go about creating an initial grid of tiles and then raising them according to data points?
Zain
Could you be a bit more specific with what you're trying to do? If I get it right, you'd probably want to place an object at a point, with a size based on the data. So something like..rect(x_position, y_position, width, width); placing a rectangle at x,y with a given width.But again, I'm not sure what you mean by a grid of tiles.
Tyler
A: 

You can definitely use pushMatrix() and translate() with beginShape() and such, it may be not completely what you expect, but it will definitely move the things around from the default origin.

What is going wrong with your above example is that you are putting the drawing() code in the constructor where you should be putting it in the display function.

so:

public void display(Processing proc) { proc.beginShape() etc. }

display() also needs to be called in the draw() loop, so initialize your tiles once and then display them in draw().

alper