Loading...
Processing Forum
Recent Topics
All Forums
Screen name:
osovidiu
osovidiu's Profile
1
Posts
1
Responses
0
Followers
Activity Trend
Last 30 days
Last 30 days
Date Interval
From Date :
To Date :
Go
Loading Chart...
Posts
Responses
PM
Show:
All
Discussions
Questions
Expanded view
List view
Private Message
Why is the camera stopping from it's movement if I click the mouse ?
[3 Replies]
14-May-2013 11:24 PM
Forum:
Programming Questions
import processing.opengl.*;
import java.awt.event.*;
PMatrix3D currCameraMatrix;
PGraphics3D g3;
PImage grid_image;
int app_height = 700, app_width = 1200;
void setup()
{
size(app_width,app_height,OPENGL);
smooth();
strokeWeight(1);
grid_image = loadImage("grid_5.jpg");
g3 = (PGraphics3D)g;
addMouseWheelListener(new MouseWheelListener() {public void mouseWheelMoved(MouseWheelEvent mwe){mouseWheel(mwe.getWheelRotation());}});
}
void draw()
{
background(20);
grid();
camera_movement();
}
int distanta_camera = 1200;
int unghi_camera_x = 45;
int unghi_camera_y = 30;
int cameraX = int(distanta_camera*cos(unghi_camera_x*PI/180)*cos(unghi_camera_y*PI/180));
int cameraY = int(distanta_camera*sin(unghi_camera_x*PI/180)*cos(unghi_camera_y*PI/180));
int cameraZ = int(distanta_camera*sin(unghi_camera_y*PI/180));
void camera_movement()
{
if(keyPressed)
{
if(key=='a')
{
unghi_camera_x++;
cameraX = int(distanta_camera*cos(unghi_camera_x*PI/180)*cos(unghi_camera_y*PI/180));
cameraY = int(distanta_camera*sin(unghi_camera_x*PI/180)*cos(unghi_camera_y*PI/180));
}
else if(key=='d')
{
unghi_camera_x--;
cameraX = int(distanta_camera*cos(unghi_camera_x*PI/180)*cos(unghi_camera_y*PI/180));
cameraY = int(distanta_camera*sin(unghi_camera_x*PI/180)*cos(unghi_camera_y*PI/180));
}
else if(key=='w')
{
unghi_camera_y++;
if(unghi_camera_y>89)
unghi_camera_y = 89;
cameraX = int(distanta_camera*cos(unghi_camera_x*PI/180)*cos(unghi_camera_y*PI/180));
cameraY = int(distanta_camera*sin(unghi_camera_x*PI/180)*cos(unghi_camera_y*PI/180));
cameraZ = int(distanta_camera*sin(unghi_camera_y*PI/180));
}
else if(key=='s')
{
unghi_camera_y--;
if(unghi_camera_y<1)
unghi_camera_y = 1;
cameraX = int(distanta_camera*cos(unghi_camera_x*PI/180)*cos(unghi_camera_y*PI/180));
cameraY = int(distanta_camera*sin(unghi_camera_x*PI/180)*cos(unghi_camera_y*PI/180));
cameraZ = int(distanta_camera*sin(unghi_camera_y*PI/180));
}
else if(key=='A')
{
unghi_camera_x+=3;
cameraX = int(distanta_camera*cos(unghi_camera_x*PI/180)*cos(unghi_camera_y*PI/180));
cameraY = int(distanta_camera*sin(unghi_camera_x*PI/180)*cos(unghi_camera_y*PI/180));
}
else if(key=='D')
{
unghi_camera_x-=3;
cameraX = int(distanta_camera*cos(unghi_camera_x*PI/180)*cos(unghi_camera_y*PI/180));
cameraY = int(distanta_camera*sin(unghi_camera_x*PI/180)*cos(unghi_camera_y*PI/180));
}
else if(key=='W')
{
unghi_camera_y+=3;
if(unghi_camera_y>89)
unghi_camera_y = 89;
cameraX = int(distanta_camera*cos(unghi_camera_x*PI/180)*cos(unghi_camera_y*PI/180));
cameraY = int(distanta_camera*sin(unghi_camera_x*PI/180)*cos(unghi_camera_y*PI/180));
cameraZ = int(distanta_camera*sin(unghi_camera_y*PI/180));
}
else if(key=='S')
{
unghi_camera_y-=3;
if(unghi_camera_y<1)
unghi_camera_y = 1;
cameraX = int(distanta_camera*cos(unghi_camera_x*PI/180)*cos(unghi_camera_y*PI/180));
cameraY = int(distanta_camera*sin(unghi_camera_x*PI/180)*cos(unghi_camera_y*PI/180));
cameraZ = int(distanta_camera*sin(unghi_camera_y*PI/180));
}
}
camera( cameraX ,cameraY , cameraZ,
0.0, 0.0, 0.0,
0.0, 0.0, -1.0 );
hint(DISABLE_DEPTH_TEST);
currCameraMatrix = new PMatrix3D(g3.camera);
camera();
GUI();
g3.camera = currCameraMatrix;
hint(ENABLE_DEPTH_TEST);
}
void grid()
{
image(grid_image,-500,-500,1000,1000);
}
void mouseWheel(int delta)
{
distanta_camera += 100*delta;
//println(distanta_camera);
if(distanta_camera<200)
distanta_camera=200;
if(distanta_camera>5000)
distanta_camera=5000;
cameraX = int(distanta_camera*cos(unghi_camera_x*PI/180)*cos(unghi_camera_y*PI/180));
cameraY = int(distanta_camera*sin(unghi_camera_x*PI/180)*cos(unghi_camera_y*PI/180));
cameraZ = int(distanta_camera*sin(unghi_camera_y*PI/180));
}
void GUI()
{
fill(0,255,0,50);
rect(width-5,height-5,-200,-50);
fill(0,255,0);
text("Error Log:",width-200,height-40);
}
«Prev
Next »
Moderate user : osovidiu
Forum