I am working on a Minecraft clone developed using Processing and PeasyCam. I will code the rest myself, with help from this forum. I need to know how to track mouse movement without having to left-click. That will be used for a first-person look-around feature. Here is the code right now:
import peasy.PeasyCam;
PeasyCam cam;
final float gravity = 1; //Inaccurate gravity simulation (impulse rather than force)
// ArrayLists for the class
//ArrayList<Box3D> boxes = new ArrayList();
//Box3D box;
// this is a very important size: size boxes
float sizeBox = 70.0;
float sizeLimit = 180;
float rotationX;
float rotationY;
float rotationZ;
float translatex=-sizeBox;
float translatey=-sizeBox;
float translatez=0;
float z = 1.0;
int objectNumber = 0;
// folded triangle
PShape s;
float offsetZ=400;
color colCurrent=color(0, 0, 255);
boolean showHelpText=true;
void setup() {
size(500, 500, P3D);
background(0);
sphereDetail(32);
cam = new PeasyCam(this, 400); // new
//box = new Box3D(0, 0, 0, 0, 0, color(255));
s = createShape();
s.beginShape();
s.fill(255, 0, 0);
s.stroke(177);
s.vertex(100, 0, -100);
s.vertex(-60, 0, 200);
s.vertex(-50, 60, -30);
s.vertex(110, 160, 40);
s.scale(0.4);
s.endShape(CLOSE);
}
void draw() {
background(0);
lights();
//for (Box3D b : boxes ) {
// box.display();
//}
noFill();
box(sizeLimit*2+sizeBox); // ?
showObject();
cam.beginHUD();
/**if (showHelpText) {
fill(255); // white
text ("Use PeasyCam. Use wasd and pl; r/g/b for colors, space bar to toggle object, RETURN to enter object to list.\n\n"
+"Use x to switch this text on and off. \n"
+"Use Mousewheel to zoom, double click to reset view. The box you move has a white outline. An item that has been added to the list is marked with a gray box.\n"
+"On adding to the list the placing box moves two units left. \n"
+"Current: "
+translatex
+", "
+translatey
+", "
+translatez,
19, 19);
}*/ //HUD disabled
if (keyPressed)
keyPressed_ForContinuusKeyinput();
cam.endHUD();
}
// -----------------------------------------------------------
void showObject() {
// show object
pushMatrix();
translatey+=gravity;
translatex=constrain(translatex,-sizeLimit,sizeLimit);
translatey=constrain(translatey,-sizeLimit,sizeLimit);
translatez=constrain(translatez,-sizeLimit,sizeLimit);
fill(colCurrent); // color
//translate(width/3, height/2, 0);
translate(translatex, translatey, translatez);
//rotateZ(rotationZ);
//rotateY(rotationY);
//rotateX(rotationX);
stroke(255);
if (objectNumber==0) {
//stroke(111);
box(sizeBox);
} else if (objectNumber==1) {
s.setFill(colCurrent);
shape(s, 0, 0);
} else if (objectNumber==2) {
//noStroke();
sphere(sizeBox);
}//else
popMatrix();
}
// -----------------------------------------------------------
void keyPressed_ForContinuusKeyinput() {
// keyPressed for registering a key throughout
float speed = 3.9;
//speed += gravity; //More accurate gravity simulation, may be removed
switch(key) {
case 'a':
translatex-=speed;
break;
case 'd':
translatex+=speed;
break;
case 'w':
case ' ':
translatey-=speed; //Conflicting keypress info: change object
break;
case SHIFT:
case 's':
translatey+=speed;
break;
// --
case 'p':
translatez-=speed;
break; //Unnecessary in 2D version, but useful
case 'l':
translatez+=speed;
break; //Unnecessary in 2D version, but useful
// -----
//
}//switch
//
}//func
// ----------------------------
void keyPressed() {
// keyPressed for registering a single key only
switch(key) {
/**
case ' ':
objectNumber++;
if (objectNumber>2)
objectNumber=0;
key=0;
break;
*/ //Object switch disabled in favor of jumping
/**
case RETURN:
case ENTER:
Box3D newBox = new Box3D (
translatex,
translatey,
translatez,
rotationY,
objectNumber,
colCurrent
);
boxes.add(newBox);
translatex-=sizeBox*2;
break;
*/ //New object function disabled
// ---
//colors
case 'r':
colCurrent=color(255, 0, 0);
break;
case 'b':
colCurrent=color(0, 0, 255);
break;
case 'g':
colCurrent=color(0, 255, 0);
break;
// --
case 'x':
showHelpText = !showHelpText;
break;
}//switch
//
} //func
//=============================================================
class Box3D {
float x=mouseX, y=410, z=mouseY;
float offsetX=0;
float offsetZ2=0;
float rotateY=0;
color colBox = color(255, 0, 0);
// type
final int boxTypeUndefined = -1;
final int boxType0 = 0;
final int boxType1 = 1;
final int boxType2 = 2;
// more needed !!!!! ????
int type = boxTypeUndefined;
// constr - full
Box3D(float x_,
float y_,
float z_,
float rotateY_,
int type_,
color col1_) {
//
x=x_;
y=y_;
z=z_;
rotateY= rotateY_;
type=type_;
colBox=col1_;
} // constr 2
void display() {
pushMatrix();
translate(x, y, z);
// rotateY(radians(rotateY));
fill(colBox);
noStroke();
// depending on the current buttons tag
//
switch (type) {
case boxTypeUndefined:
// undefined
break;
case boxType0:
stroke(111);
box(sizeBox);
break;
case boxType1:
s.setFill(colBox);
shape(s, 0, 0);
break;
case boxType2:
noStroke();
sphere(sizeBox);
break;
default:
// error
break;
}//switch
if (showHelpText) {
translate(sizeBox/2, -sizeBox/2, sizeBox/2);
fill(111);
stroke(0);
box(sizeBox/6);
}
popMatrix();
} // method
String toString() {
return
str(x) +","+
str(y) +","+
str(z) +","+
str(rotateY) +","+
str(type) +","+
str(red(colBox)) +","+
str(green(colBox)) +","+
str(blue(colBox)) ;
}
//
} // class
//
I understand there is a redundant class "Box3D", but I will handle that before implementing whatever solution you give me.