Camera mouse control in P3D
in
Programming Questions
•
2 months ago
Hello,
I try to make my control mouse camera without peasycam, I'm close but the algorithm is not really ok, that make a zoom when I move. I don't find a solution on the forum.
So if any body have an idea. I'm glad
Thx
I try to make my control mouse camera without peasycam, I'm close but the algorithm is not really ok, that make a zoom when I move. I don't find a solution on the forum.
So if any body have an idea. I'm glad
Thx
- void setup()
{
size( 800,800, P3D) ;
background(0) ;
//initialization camera
cameraP3Dsetup() ;
}
void draw() {
background(0) ;
PVector mouseInfo = new PVector (mouseX, mouseY, wheel) ;
wheel = 0 ;
PVector pos = new PVector (eyePos(mouseInfo).x, eyePos(mouseInfo).y, eyePos(mouseInfo).z ) ;
// the position of the scene is by default (width /2, height /2, 0 ) ;
// so if you wan move to the left, you must minus x, and go to the right add sommesthing to the "x",
// same idea for the top and the bottom, and the depth
PVector scene = new PVector (0,0,0) ;
// the direction of the cam is between (-1 to 1 ) , but I don't understand the concept
PVector dirCam = new PVector (0.0, 1.0, 0.0) ;
cameraP3Ddraw(pos, scene, dirCam) ;
println("distance between the scene and the camera " + pos.dist(scene)) ;
stroke(255,30,30) ;
pushMatrix() ;
translate(width/2, height / 2, 0);
box(300) ;
popMatrix() ;
}
PVector centerScene;
float distanceToFocus ;
void cameraP3Dsetup()
{
// give the start distance between the camera and the scene
if ( width > height ) distanceToFocus = width *3 ; else distanceToFocus = height *3 ;
//give the starting position of the scene in the display
centerScene = new PVector (width/2.0, height/2.0, 0) ;
//camedra direction
}
void cameraP3Ddraw(PVector posCam, PVector posScene, PVector dir ) {
camera(posCam.x, posCam.y, posCam.z,
centerScene.x +posScene.x , centerScene.y +posScene.y, centerScene.z +posScene.z,
dir.x, dir.y, dir.z);
}
PVector cyclusCamera ;
PVector eyePos(PVector mouse)
{
PVector pos = new PVector (0,0,0) ;
distanceToFocus += mouse.z ;
cyclusCamera = new PVector (map(mouse.x, 0, width, 0, TAU), map(mouse.y, 0, height, 0, TAU), map(mouse.x +mouse.y , 0, width +height, 0, TAU)) ;
PVector marge = new PVector((width -distanceToFocus *2.0) *.5,(height -distanceToFocus *2.0) *.5) ;
//THE PROBLEM SURE IS HERE !!!!!
float dataPosX = cos(cyclusCamera.x) *distanceToFocus ;
float dataPosY = sin(cyclusCamera.y) *distanceToFocus ;
float dataPosZ = sin(cyclusCamera.z) *distanceToFocus ;
pos = new PVector ( dataPosX, dataPosY, dataPosZ ) ;
return pos ;
}
// mouse wheel event
float wheel ;
float checkTheWheel ;
int countWheelAction ;
void mouseWheel(MouseEvent event) {
countWheelAction += 1 ;
checkTheWheel = wheel ;
wheel = event.getCount();
}
1