Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

3d bearings (& ofCam)

$
0
0

@coding wrote:

Hi, ofCamera easyCam was broken in my tests (up vector 0 0 1, 0 -1 0) so I ended up coding a simple bearings example. Here is the behavior i was seeking.

#pragma once

#include "ofMain.h"

#include "Panel.h"

class ofApp : public ofBaseApp{
	public:

		Panel panel;


		void setup(){

			panel.clear();
			panel.setup( "bearings", ofPoint(20,20), ofPoint(255,15),0);

			panel.addSlider("fov", 45, 0,100);
			panel.addSlider("near", 0.1, 0,1000);
			panel.addSlider("far", 10000, 0,12500000);
			panel.addSlider("camx", 0, -1000,1000);
			panel.addSlider("camy", 0, -1000,1000);
			panel.addSlider("camz", 400, -1000,1000);
			panel.addSlider("eyex", 0, -1000,1000);
			panel.addSlider("eyey", 0, -1000,1000);
			panel.addSlider("eyez", 0, -1000,1000);
			panel.addSlider("upx", 0, -1,1);
			panel.addSlider("upy", -1, -1,1);
			panel.addSlider("upz", 0, -1,1);

		}
		void update(){
			panel.update();
		}
		void draw(){

			// ofBackground(0,255,0);
			ofBackground(200);

			glMatrixMode( GL_PROJECTION );
			glLoadIdentity();
			gluPerspective( panel.get("fov"), ofGetWidth()/ofGetHeight(),
						   panel.get("near"), panel.get("far") );

		   glMatrixMode( GL_MODELVIEW );
		   glLoadIdentity();

			ofPushMatrix();
				gluLookAt(
						panel.get("camx"),
						panel.get("camy"),
						panel.get("camz"),
						panel.get("eyex"),
						panel.get("eyey"),
						panel.get("eyez"),
						panel.get("upx"),
						panel.get("upy"),
						panel.get("upz")
				);


			ofSetColor(0);
			ofBox(100);

			ofPopMatrix();


			ofSetupScreen();
			ofSetColor(255);
			panel.draw();

		}

		// void keyPressed(int key);
		// void keyReleased(int key);
		// void mouseMoved(int x, int y);
		// void mouseDragged(int x, int y, int button);
		// void mousePressed(int x, int y, int button);
		// void mouseReleased(int x, int y, int button);
		// void mouseEntered(int x, int y);
		// void mouseExited(int x, int y);
		// void windowResized(int w, int h);
		// void dragEvent(ofDragInfo dragInfo);
		// void gotMessage(ofMessage msg);
};

Posts: 2

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles