spotlight with the OCD library question.
in
Programming Questions
•
2 years ago
I'm having a dickens of a time getting a spotlight to orient the same direction as the camera. I'm using the OCD library and want the spotlight to act as a headlight as we move and turn through the space. Any help at this point would be greatly appreciated. I've included some rough code below.
w- forward
s - back
a - slide right
d - slide left
j - turn left
k - turn right
//
import damkjer.ocd.*;
import processing.opengl.*;
Camera camera1;
float moveX = 0;
float moveZ = 0;
float turn = 0;
float r = .1;
float px, pz, px2, pz2, px3, pz3, px4, pz4, shipx, shipy, shipz, speedx, speedy, thrust, sidethrust;
boolean moveleft, moveright, moveforward, backwardstop, leftstop, rightstop, movebackward, turnleft, turnright, forwardstop;
int triggerdistance = 35;
void setup() {
size(640, 360, OPENGL);
fill(204);
moveX = width/2;
moveZ = 150;
camera1 = new Camera(this, 200, 0, 0);
}
void draw() {
ambientLight(50, 50, 50);
background(200);
float[] position = camera1.position();
float[] camattitude = camera1.attitude();
pushMatrix();
rotateY (camattitude[0]);
spotLight(255, 255, 200, position[0],position[1],position[2], 0, 0, 1, PI/1, 5);
popMatrix();
camera1.dolly(thrust);
camera1.truck(sidethrust);
camera1.pan(radians(turn) / 2.0);
camera1.feed();
shipx = position[0];
shipz = position[2];
for (int i = -500; i< 501; i+= 100) {
for (int j = -500; j< 501; j+= 100) {
pushMatrix();
translate(i, 0, j);
fill(255, 255, 0);
box(40, 80, 40);
popMatrix();
}
}
pushMatrix();
translate(0, 40, 0);
fill(60, 20, 10);
box(-2000, 2, 2000);
fill(10, 10, 255, 50);
box(20, 1000, 20);
popMatrix();
if (moveleft == true && rightstop == false) {
sidethrust = -5;
}
else if (moveright == true && leftstop == false) {
sidethrust = 5;
}
else {
sidethrust = 0;
}
if (moveforward == true && forwardstop == false) {
thrust = -5;
}
else if (movebackward == true && backwardstop == false) {
thrust = 5;
}
else {
thrust = 0;
}
if (turnleft == true) {
turn = -5;
}
else if (turnright == true) {
turn = 5;
}
else {
turn = 0;
}
forwardstop = false;
backwardstop = false;
leftstop = false;
rightstop = false;
}
void keyPressed() {
if (key == 'g') {
triggerdistance += 1;
}
if (key == 't') {
triggerdistance -= 1;
}
if (key == 'a') {
moveleft = true;
}
if (key == 'd') {
moveright = true;
}
if (key == 'w') {
moveforward = true;
}
if (key == 's') {
movebackward = true;
}
if (key == 'j') {
turnleft = true ;
}
if (key == 'k') {
turnright = true;
}
}
void keyReleased() {
if (key == 'a') {
moveleft = false;
}
if (key == 'd') {
moveright = false;
}
if (key == 'w') {
moveforward = false;
}
if (key == 's') {
movebackward = false;
}
if (key == 'j') {
turnleft = false ;
}
if (key == 'k') {
turnright = false;
}
}
w- forward
s - back
a - slide right
d - slide left
j - turn left
k - turn right
//
import damkjer.ocd.*;
import processing.opengl.*;
Camera camera1;
float moveX = 0;
float moveZ = 0;
float turn = 0;
float r = .1;
float px, pz, px2, pz2, px3, pz3, px4, pz4, shipx, shipy, shipz, speedx, speedy, thrust, sidethrust;
boolean moveleft, moveright, moveforward, backwardstop, leftstop, rightstop, movebackward, turnleft, turnright, forwardstop;
int triggerdistance = 35;
void setup() {
size(640, 360, OPENGL);
fill(204);
moveX = width/2;
moveZ = 150;
camera1 = new Camera(this, 200, 0, 0);
}
void draw() {
ambientLight(50, 50, 50);
background(200);
float[] position = camera1.position();
float[] camattitude = camera1.attitude();
pushMatrix();
rotateY (camattitude[0]);
spotLight(255, 255, 200, position[0],position[1],position[2], 0, 0, 1, PI/1, 5);
popMatrix();
camera1.dolly(thrust);
camera1.truck(sidethrust);
camera1.pan(radians(turn) / 2.0);
camera1.feed();
shipx = position[0];
shipz = position[2];
for (int i = -500; i< 501; i+= 100) {
for (int j = -500; j< 501; j+= 100) {
pushMatrix();
translate(i, 0, j);
fill(255, 255, 0);
box(40, 80, 40);
popMatrix();
}
}
pushMatrix();
translate(0, 40, 0);
fill(60, 20, 10);
box(-2000, 2, 2000);
fill(10, 10, 255, 50);
box(20, 1000, 20);
popMatrix();
if (moveleft == true && rightstop == false) {
sidethrust = -5;
}
else if (moveright == true && leftstop == false) {
sidethrust = 5;
}
else {
sidethrust = 0;
}
if (moveforward == true && forwardstop == false) {
thrust = -5;
}
else if (movebackward == true && backwardstop == false) {
thrust = 5;
}
else {
thrust = 0;
}
if (turnleft == true) {
turn = -5;
}
else if (turnright == true) {
turn = 5;
}
else {
turn = 0;
}
forwardstop = false;
backwardstop = false;
leftstop = false;
rightstop = false;
}
void keyPressed() {
if (key == 'g') {
triggerdistance += 1;
}
if (key == 't') {
triggerdistance -= 1;
}
if (key == 'a') {
moveleft = true;
}
if (key == 'd') {
moveright = true;
}
if (key == 'w') {
moveforward = true;
}
if (key == 's') {
movebackward = true;
}
if (key == 'j') {
turnleft = true ;
}
if (key == 'k') {
turnright = true;
}
}
void keyReleased() {
if (key == 'a') {
moveleft = false;
}
if (key == 'd') {
moveright = false;
}
if (key == 'w') {
moveforward = false;
}
if (key == 's') {
movebackward = false;
}
if (key == 'j') {
turnleft = false ;
}
if (key == 'k') {
turnright = false;
}
}
1