Using rotate() to roll rectangale on the X while keeping pitch on the Y
in
Programming Questions
•
4 months ago
Hello,
I'm trying to make an artificial horizon indicator. So far I can control the Pitch. but when I try to rotate the rectangle on the top center it all goes crazy.
I tried this from an example I found. it seems to work here, but not in my code
- // Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com - // Example 14-5: Rectangle rotating around center
- void setup() {
size(300,300);
} - void draw() {
background(255);
stroke(0);
fill(175);
// Translate origin to center
translate(width/2,height/8-100+mouseY+60);
// The greek letter, theta, is often used as the name of a variable to store an angle
// The angle ranges from 0 to PI, based on the ratio of mouseX location to the sketch's width.
float theta = PI*mouseX / width;
// Rotate by the angle theta
//translate(0,0-mouseY);
rotate(theta);
// Display rectangle with CENTER mode
rectMode(CENTER);
rect(0+50,0,100,100);
}
this is the code I have so far
- float Pitch;
float Roll;
float newX = map(mouseX, 0, 1000, -150, 150);
float newY = map(mouseY, 0, 300, -150, 150);
void setup()
{
size(1000,800);
rectMode(CENTER);
smooth();
} - void draw()
{
//println("X = " + mouseX);
//println("Y = " + mouseY);
Pitch= mouseY - 150;
Roll = (PI/2)*mouseX;
Horizon();
}
void Horizon()
{- noStroke();
fill(0, 180, 255); //Fill Sky color
rect(500, 200, 300, 300);
fill(252, 130, 8); //Fill ground color
rect(500,Pitch+300,300, 300);
translate(0,0);
// rotate(Roll); //<- this is my problem
stroke(250); // Draw cross hairs for visual alignment
line(375,200,625, 200);
line(500,75,500, 325);
noStroke();//Cover up background
fill(205);
rect(500, 600, 300, 500);
rect(500, 0, 300, 100);
}
1