Quantcast
Channel: bugs, errors - openFrameworks
Viewing all articles
Browse latest Browse all 636

ofxBullet + second window disables object grabbing

$
0
0

Hello - I am just getting started with OF and C++ (migrating from Processing). I am not new to programming. I am using ofxBullet (and in this example ofxGui). As soon as I instantiate a second window, enableGrabbing() stops working. As far as I can tell, everything else in the physics works fine.

main.cpp

#include "ofMain.h"
#include "ofApp.h"
#include "GuiApp.h"
#include "ofAppGLFWWindow.h"

//========================================================================
int main( ){
	ofGLFWWindowSettings settings;

	settings.setSize(1920, 1080);
	settings.setPosition(glm::vec2(1920, 0));
	settings.resizable = true;
	shared_ptr<ofAppBaseWindow> mainWindow = ofCreateWindow(settings);


	settings.setSize(300, 300);
	settings.setPosition(glm::vec2(0, 0));
	settings.resizable = true;
	shared_ptr<ofAppBaseWindow> guiWindow = ofCreateWindow(settings);


	shared_ptr<GuiApp> guiApp(new GuiApp);
	shared_ptr<ofApp> mainApp(new ofApp);
	mainApp->gui = guiApp;


	ofRunApp(guiWindow, guiApp);
	ofRunApp(mainWindow, mainApp);
	ofRunMainLoop();

}

ofApp.h

#pragma once

#include "ofMain.h"
#include "ofxBullet.h"
#include "GuiApp.h"

class ofApp : public ofBaseApp{

	public:
		void setup();
		void update();
		void 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);

		ofxBulletWorldRigid			world;
		ofxBulletBox				ground;

		ofxBulletSphere*			sphere;

		ofCamera					camera;

		shared_ptr<GuiApp>			gui;
		
};

ofApp.cpp

#include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup(){

	ofSetFrameRate(60);
	ofSetVerticalSync(true);

	ofBackground(0);

	camera.setPosition(ofVec3f(0.f, -40.f, -60.f));
	camera.lookAt(ofVec3f(0, 0, 0), ofVec3f(0, -1, 0));

	world.setup();
	world.enableGrabbing();

	world.setCamera(&camera);
	world.setGravity(glm::uvec3(0., 60., 0.));

	ground.create(world.world, ofVec3f(0., 0., 0.), 0., 100.f, 1.f, 100.f);
	ground.setProperties(.25, .95);
	ground.add();

	sphere = new ofxBulletSphere();
	sphere->create(world.world, ofVec3f(0, -30, 0), 1., 2.5);
	sphere->add();

}

//--------------------------------------------------------------
void ofApp::update(){

	world.update();
	ofSetWindowTitle(ofToString(ofGetFrameRate(), 0));

}

//--------------------------------------------------------------
void ofApp::draw(){

	ofEnableDepthTest();
	camera.begin();
	
	ofSetColor(150);
	ground.draw();

	ofSetColor(0, 225, 0);
	sphere->draw();

	camera.end();

}

GuiApp.h

#pragma once

#include "ofMain.h"
#include "ofxGui.h"

class GuiApp : public ofBaseApp
{
public:
	void setup();
	void update();
	void draw();

	ofxPanel gui;

};

GuiApp.cpp

#include "GuiApp.h"

void GuiApp::setup() {

	ofBackground(0);
	ofSetVerticalSync(false);
}

void GuiApp::update() {

}

void GuiApp::draw() {

	ofSetColor(255);
	stringstream ss;
	ss << "framerate: " << ofToString(ofGetFrameRate(), 0) << endl;
	ofDrawBitmapString(ss.str().c_str(), 20, 20);

	gui.draw();
}

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 636

Trending Articles