I am using processing to draw terrain for a simple game. It is a hexagonal grid and I have got it to draw 2d hexagons correctly and then I setup a camera in 3d space. I am using OpenGl.
The grid draws with 30 fps quite nicely at 50 x 50 hexagons but when i up this to 100x100 it slows down greatly, to about 15-20fps.
I assume this is because I am drawing many more hexagons but some of them appear off screen.
Is there a way to calculate which hexagons will be on the screen, draw these, and those that are not going to be onscreen, it skips over?
Also, will backface cullling have any effect towards improving performance?
import processing.core.*;
import processing.opengl.*;
public class Test extends PApplet {
Hexagon gametile;
float xTrans;
float yTrans;
float mouseWheel;
float cameraHeight;
float cameraEyeX;
float cameraEyeY;
float mouseXOffset;
float mouseYOffset;
static final float MIN_CAMERA_HEIGHT = 70;
static final float MAX_CAMERA_HEIGHT = 800;
static final float MIN_X_BOUND = 30;
static final float MAX_X_BOUND = 570;
static final float MIN_Y_BOUND = 30;
static final float MAX_Y_BOUND = 570;
PFont font;
public void setup(){
size(600,600, OPENGL);
background(0);
frameRate(30);
//smooth();
font = createFont("Arial Bold",48);
cameraEyeX = mouseX;
cameraEyeY = mouseY;
mouseXOffset =0;
mouseYOffset=0;
//START: MATH FOR CALCULATING THE TESSELATION OF THE HEXAGONS