Skip to content

Commit 8a20605

Browse files
authored
Fixes for some model rotations and cache camera orbit on mouse press … (#7382)
#changelog #examples * Fixes for some model rotations and cache camera orbit on mouse press so it maintains position while rotating. * back to first file path * readd verbose log level
1 parent 17b46af commit 8a20605

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

examples/3d/3DModelLoaderExample/src/ofApp.cpp

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Loads in the same 3D penguin model in various file types. Demonstrates how to lo
77
//--------------------------------------------------------------
88
void ofApp::setup(){
99
ofBackground(255,255,255);
10+
ofSetLogLevel(OF_LOG_VERBOSE);
1011

1112
ofSetVerticalSync(true);
1213

@@ -28,8 +29,13 @@ void ofApp::setup(){
2829
model.setRotation(0, 180, 1, 0, 0);
2930
model.setScale(0.9, 0.9, 0.9);
3031
light.setPosition(0, 0, 500);
32+
light.getShadow().setEnabled(false);
33+
// some models load in specular that is pure white, so tone it down a bit
34+
light.setSpecularColor( ofFloatColor(0.15, 1.0));
35+
light.setDiffuseColor( ofFloatColor(1.0, 1.0));
3136

32-
cameraOrbit = 0;
37+
cameraOrbit = 0.f;
38+
camLatOrbit = 0.f;
3339
cam.setDistance(700);
3440

3541
//set help text to display by default
@@ -38,8 +44,16 @@ void ofApp::setup(){
3844

3945
//--------------------------------------------------------------
4046
void ofApp::update(){
41-
cameraOrbit += ofGetLastFrameTime() * 20.; // 20 degrees per second;
42-
cam.orbitDeg(cameraOrbit, 0., cam.getDistance(), {0., 0., 0.});
47+
if( ofGetMousePressed() ) {
48+
// cache the camera orbit degrees in latitude and longitude
49+
cameraOrbit = 90.f-ofRadToDeg( ofWrapRadians( atan2(cam.getZ(), cam.getX() )) );
50+
camLatOrbit = -ofRadToDeg(asinf( cam.getPosition().y / cam.getDistance() ));
51+
} else {
52+
cameraOrbit += ofGetLastFrameTime() * 20.; // 20 degrees per second;
53+
cam.orbitDeg(cameraOrbit, camLatOrbit, cam.getDistance(), {0., 0., 0.});
54+
}
55+
56+
4357
}
4458

4559
//--------------------------------------------------------------
@@ -60,6 +74,7 @@ void ofApp::draw(){
6074
// draws all the other file types which are loaded into model.
6175
model.drawFaces();
6276
}
77+
6378
cam.end();
6479

6580
light.disable();
@@ -72,10 +87,9 @@ void ofApp::draw(){
7287
ss << "FPS: " << ofToString(ofGetFrameRate(),0) << endl << endl;
7388
ss << "(1/2/3/4/5/6): load different file types"<<endl;
7489
ss << "Current file info: " + curFileInfo <<endl;
75-
if(bUsingMesh){
76-
ss << "Use ofEasyCam mouse and key controls to navigate."<< endl <<endl;
77-
}
90+
ss << "Use ofEasyCam mouse and key controls to navigate."<< endl <<endl;
7891
ss <<"(h): Toggle help."<<endl;
92+
ofSetColor(60);
7993
ofDrawBitmapString(ss.str().c_str(), 20, 20);
8094
}
8195
}
@@ -102,23 +116,23 @@ void ofApp::keyPressed(int key){
102116
case '3':
103117
bUsingMesh = false;
104118
model.load("penguin.ply");
105-
model.setRotation(0, 90, 1, 0, 0);
119+
model.setRotation(0, -90, 1, 0, 0);
106120
model.setScale(0.9, 0.9, 0.9);
107121
cam.setDistance(700);
108122
curFileInfo = ".ply";
109123
break;
110124
case '4':
111125
bUsingMesh = false;
112126
model.load("penguin.obj");
113-
model.setRotation(0, 90, 1, 0, 0);
127+
model.setRotation(0, -90, 1, 0, 0);
114128
model.setScale(0.9, 0.9, 0.9);
115129
cam.setDistance(700);
116130
curFileInfo = ".obj";
117131
break;
118132
case '5':
119133
bUsingMesh = false;
120134
model.load("penguin.stl");
121-
model.setRotation(0, 90, 1, 0, 0);
135+
model.setRotation(0, -90, 1, 0, 0);
122136
model.setScale(0.9, 0.9, 0.9);
123137
cam.setDistance(700);
124138
curFileInfo = ".stl";

examples/3d/3DModelLoaderExample/src/ofApp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@ class ofApp : public ofBaseApp{
3939

4040
ofEasyCam cam;
4141
float cameraOrbit;
42+
float camLatOrbit;
4243
};
4344

0 commit comments

Comments
 (0)