Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
# Conflicts:
#	example-anchormanager/example-anchormanager.xcodeproj/project.xcworkspace/xcuserdata/joschow1.xcuserdatad/UserInterfaceState.xcuserstate
#	example-basic/example-basic.xcodeproj/project.xcworkspace/xcuserdata/joschow1.xcuserdatad/UserInterfaceState.xcuserstate
  • Loading branch information
sortasleepy committed Feb 18, 2018
2 parents b2323ec + a846ca7 commit 460081f
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 91 deletions.
24 changes: 6 additions & 18 deletions example-basic/src/ofApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,16 @@ class ofApp : public ofxiOSApp {
void gotMemoryWarning();
void deviceOrientationChanged(int newOrientation);


ofVbo vbo;


vector < matrix_float4x4 > mats;
vector<ARAnchor*> anchors;
ofCamera camera;
ofTrueTypeFont font;

//CVOpenGLESTextureRef createTextureFromPixelBuffer(CVPixelBufferRef pixelBuffer,int planeIndex);



ofImage img;

// ====== AR STUFF ======== //
ARSession * session;

ARRef processor;

/*
int32_t cameraWidth;
int32_t cameraHeight;
*/

ofImage img;


};

Expand Down
98 changes: 29 additions & 69 deletions example-basic/src/ofApp.mm
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,6 @@ void logSIMD(const simd::float4x4 &matrix)
output << std::endl;
}

ofMatrix4x4 matFromSimd(const simd::float4x4 &matrix){
ofMatrix4x4 mat;
mat.set(matrix.columns[0].x,matrix.columns[0].y,matrix.columns[0].z,matrix.columns[0].w,
matrix.columns[1].x,matrix.columns[1].y,matrix.columns[1].z,matrix.columns[1].w,
matrix.columns[2].x,matrix.columns[2].y,matrix.columns[2].z,matrix.columns[2].w,
matrix.columns[3].x,matrix.columns[3].y,matrix.columns[3].z,matrix.columns[3].w);
return mat;
}

//--------------------------------------------------------------
ofApp :: ofApp (ARSession * session){
this->session = session;
Expand All @@ -51,48 +42,20 @@ ofMatrix4x4 matFromSimd(const simd::float4x4 &matrix){

font.load("fonts/mono0755.ttf", fontSize);



processor = ARProcessor::create(session);

processor->setup();




}


vector < matrix_float4x4 > mats;

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

processor->update();

mats.clear();

if (session.currentFrame){
NSInteger anchorInstanceCount = session.currentFrame.anchors.count;

for (NSInteger index = 0; index < anchorInstanceCount; index++) {
ARAnchor *anchor = session.currentFrame.anchors[index];

// Flip Z axis to convert geometry from right handed to left handed
matrix_float4x4 coordinateSpaceTransform = matrix_identity_float4x4;
coordinateSpaceTransform.columns[2].z = -1.0;

matrix_float4x4 newMat = matrix_multiply(anchor.transform, coordinateSpaceTransform);
mats.push_back(newMat);
logSIMD(newMat);
//anchorUniforms->modelMatrix = matrix_multiply(anchor.transform, coordinateSpaceTransform);
}
}

}


ofCamera camera;
//--------------------------------------------------------------
void ofApp::draw() {
ofEnableAlphaBlending();
Expand All @@ -108,49 +71,36 @@ ofMatrix4x4 matFromSimd(const simd::float4x4 &matrix){
camera.begin();
processor->setARCameraMatrices();

for (int i = 0; i < mats.size(); i++){
for (int i = 0; i < session.currentFrame.anchors.count; i++){
ARAnchor * anchor = session.currentFrame.anchors[i];

// note - if you need to differentiate between different types of anchors, there is a
// "isKindOfClass" method in objective-c that could be used. For example, if you wanted to
// check for a Plane anchor, you could put this in an if statement.
// if([anchor isKindOfClass:[ARPlaneAnchor class]]) { // do something if we find a plane anchor}
// Not important for this example but something good to remember.

ofPushMatrix();
//mats[i].operator=(const simd_float4x4 &)
ofMatrix4x4 mat;
mat.set(mats[i].columns[0].x, mats[i].columns[0].y,mats[i].columns[0].z,mats[i].columns[0].w,
mats[i].columns[1].x, mats[i].columns[1].y,mats[i].columns[1].z,mats[i].columns[1].w,
mats[i].columns[2].x, mats[i].columns[2].y,mats[i].columns[2].z,mats[i].columns[2].w,
mats[i].columns[3].x, mats[i].columns[3].y,mats[i].columns[3].z,mats[i].columns[3].w);
ofMatrix4x4 mat = ARCommon::convert<matrix_float4x4, ofMatrix4x4>(anchor.transform);
ofMultMatrix(mat);

ofSetColor(255);
ofRotate(90,0,0,1);

float aspect = ARCommon::getNativeAspectRatio();
img.draw(-aspect/8,-0.125,aspect/4,0.25);


img.draw(-0.025 / 2, -0.025 / 2,0.025,0.025);


ofPopMatrix();
}

camera.end();
}

}
ofDisableDepthTest();
// ========== DEBUG STUFF ============= //
int w = MIN(ofGetWidth(), ofGetHeight()) * 0.6;
int h = w;
int x = (ofGetWidth() - w) * 0.5;
int y = (ofGetHeight() - h) * 0.5;
int p = 0;

x = ofGetWidth() * 0.2;
y = ofGetHeight() * 0.11;
p = ofGetHeight() * 0.035;

//ofSetColor(ofColor::black);
font.drawString("frame num = " + ofToString( ofGetFrameNum() ), x, y+=p);
font.drawString("frame rate = " + ofToString( ofGetFrameRate() ), x, y+=p);
font.drawString("screen width = " + ofToString( ofGetWidth() ), x, y+=p);
font.drawString("screen height = " + ofToString( ofGetHeight() ), x, y+=p);


processor->debugInfo.drawDebugInformation(font);


}

Expand All @@ -161,8 +111,18 @@ ofMatrix4x4 matFromSimd(const simd::float4x4 &matrix){

//--------------------------------------------------------------
void ofApp::touchDown(ofTouchEventArgs &touch){

processor->anchorController->addAnchor();
if (session.currentFrame){
ARFrame *currentFrame = [session currentFrame];

matrix_float4x4 translation = matrix_identity_float4x4;
translation.columns[3].z = -0.2;
matrix_float4x4 transform = matrix_multiply(currentFrame.camera.transform, translation);

// Add a new anchor to the session
ARAnchor *anchor = [[ARAnchor alloc] initWithTransform:transform];

[session addAnchor:anchor];
}
}

//--------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion example-basic/src/viewcontrollers/MyAppViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ - (void)loadView {
[super loadView];

ARCore::SFormat format;
format.enablePlaneTracking().enableLighting();
format.enableLighting();
self.session = ARCore::generateNewSession(format);


Expand Down
4 changes: 3 additions & 1 deletion src/ARAnchorManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
_onPlaneAdded = nullptr;
}

ARAnchorManager::ARAnchorManager(ARSession * session):shouldUpdatePlanes(false){
ARAnchorManager::ARAnchorManager(ARSession * session):
shouldUpdatePlanes(false),
maxTrackedPlanes(0){
this->session = session;
}

Expand Down
4 changes: 4 additions & 0 deletions src/ARCam.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ namespace ARCore {
//! draws the camera frame.
void draw();

//! Draws a scaled version of the camera image based on the properties passed in.
//! Will default to class properties if no new values are passed as parameters.
void drawScaled(int x=0,int y=0, float w = 0, float h = 0);

void updatePlaneTexCoords();

//! Allows you to force an orientation to make it easier to lock your device
Expand Down
60 changes: 59 additions & 1 deletion src/ARCam.mm
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,25 @@
cameraDimensions.y = y;
}

void ARCam::draw(){
void ARCam::drawScaled(int x, int y, float w, float h){


if(x == 0){
x = xShift;
}

if(y == 0){
y = yShift;
}

if(w == 0){
w = cameraDimensions.x;
}

if(h == 0){
h = cameraDimensions.y;
}

if(needsPerspectiveAdjustment){
// Adjust drawing as necessary .
switch(UIDevice.currentDevice.orientation){
Expand Down Expand Up @@ -145,6 +163,46 @@

}

void ARCam::draw(){
cameraConvertShader.begin();

switch(UIDevice.currentDevice.orientation){
case UIDeviceOrientationFaceUp:
cameraConvertShader.setUniform1i("isPortraitOrientation", true);
break;
case UIDeviceOrientationFaceDown:
break;

case UIDeviceOrientationUnknown:

cameraConvertShader.setUniform1i("isPortraitOrientation", true);
break;
case UIDeviceOrientationPortraitUpsideDown:

cameraConvertShader.setUniform1i("isPortraitOrientation", true);
break;

case UIDeviceOrientationPortrait:

cameraConvertShader.setUniform1i("isPortraitOrientation", true);

break;

case UIDeviceOrientationLandscapeLeft:

cameraConvertShader.setUniform1i("isPortraitOrientation", false);
break;

case UIDeviceOrientationLandscapeRight:

cameraConvertShader.setUniform1i("isPortraitOrientation", false);
break;
}

vMesh.draw(GL_TRIANGLE_STRIP, 0, 16);
cameraConvertShader.end();
}

//! Sets the x and y position of where the camera image is placed.
void ARCam::setCameraImagePosition(float xShift,float yShift){
this->xShift = xShift;
Expand Down
2 changes: 1 addition & 1 deletion src/ARDebugUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace ARDebugUtils {
break;

case ARTrackingStateReasonInsufficientFeatures:
font.drawString("Tracking state: Bad!",0,y + 100);
font.drawString("Tracking state: Bad!",x,y + 100);
break;
}

Expand Down

0 comments on commit 460081f

Please sign in to comment.