We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have been working with the camera function in open processing. I've made an app where I can see the cube from Different sides. But I can't see one of them. Could you help me to do it? here is my code in open processing:
function setup(){
createCanvas(windowWidth, windowHeight, WEBGL);
}
function draw(){
background(1);
translate(0, 0, 0);
r = 0;
d = 0;
ySpeed = mouseY + pmouseY;
r = r + ySpeed;
xSpeed = mouseX + pmouseX;
d = d + xSpeed;
camera(d / 1.5 - 1000, 300, -r + 800, 0, 0, 0, 0.5, 0.5, -d - 1000);
box(200);
}
Answers
please don't post duplicates
Why can't you see one of them? What specifically is going wrong? Is it that the mouse control is bad? Is something not rendering correctly? Can you describe the problem in more detail?
You are moving your camera on x and z axis
Consider to use cos and sin and to use the mouse values as degrees you feed into cos and sin (use radians())
Post your entire code
function setup(){ createCanvas(windowWidth,windowHeight,WEBGL); } function draw(){ background(1); translate(0,0,0); r = 0; d = 0; ySpeed = mouseY + pmouseY; r = r + ySpeed; xSpeed = mouseX + pmouseX; d = d + xSpeed; camera(300 * cos(radians(map(mouseX,0,width,0,375))),300,-r+800,0, 0,0, 0.5,0.5,-d-1000); box(200);
}
Please implement the sin clause for your Z value
You can make line breaks inside the camera statement
edit post, highlight code, press ctrl-o to format.
perfect, thank you so much
;-)
Explanation of my code above
My code has the cube fixed and rotates the camera around it.
The camera rotates on the circumference of a circle.
It works fully in the x-z-plane (horizontal circle in the plane defined by x and z axis), not so good in y direction (you could say I cheated there).
sin and cos are two functions that calculate the x and y positions of a point on the circumference of a circle on a given angle (or you could say it is defined in the context of a right triangle placed within the circle; see Wikipedia below). That’s where we place the camera, on the circumference of a circle.
Let's say the angle is 30° (degree which you have to convert to radians in processing, never mind) then
would give you the values you have to go from the circle center in x-direction and in y-direction to reach the point of the circumference at 30 degree, when the circle has a radius of 40 pixels.
Example
Here is a 2D example of sin and cos:
Reference
See reference for sin and cos and
https://www.processing.org/reference/
Tutorial
see tutorial trigonometry:
https://www.processing.org/tutorials/trig/
Wikipedia
See Wikipedia
Sine
https://en.wikipedia.org/wiki/Sine
Cosine
https://en.wikipedia.org/wiki/Trigonometric_functions#cosine
trigonometry
https://en.wikipedia.org/wiki/Trigonometric_functions