Skip to content

Commit 32b7531

Browse files
authored
Merge pull request #7 from artoolkitx/phil-misc-fixes
Phil misc fixes
2 parents 794fe86 + b1c8178 commit 32b7531

File tree

9 files changed

+101
-48
lines changed

9 files changed

+101
-48
lines changed

Android/app/src/main/res/layout/cameracalibrationactivity.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<FrameLayout
2222
android:id="@+id/content"
2323
android:layout_width="match_parent"
24-
android:layout_height="wrap_content"
24+
android:layout_height="0dp"
2525
app:layout_constraintBottom_toTopOf="@+id/toolbar"
2626
app:layout_constraintTop_toBottomOf="@+id/appbar">
2727
</FrameLayout>
2.95 KB
Loading
1.44 KB
Loading
4 KB
Loading
5.94 KB
Loading
7.52 KB
Loading

build.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,13 @@ if [ $BUILD_IOS ] ; then
192192
xcodebuild -target "artoolkitX Camera Calibration Utility" -configuration Release -destination generic/platform=iOS
193193
)
194194
fi
195-
# /BUILD_MACOS
195+
# /BUILD_IOS
196+
197+
if [ "$OS" = "Darwin" ] || [ "$OS" = "Linux" ] || [ "$OS" = "Windows" ] ; then
198+
# ======================================================================
199+
# Build platforms hosted by macOS/Linux/Windows
200+
# ======================================================================
201+
196202

197203
if [ $BUILD_ANDROID ] ; then
198204

@@ -211,12 +217,16 @@ if [ $BUILD_ANDROID ] ; then
211217
(cd "${OURDIR}/Android"
212218
echo "Building Android project"
213219
./gradlew assembleRelease
220+
if [[ ]] ; then
221+
zipalign -v -p 4 my-app-unsigned.apk my-app-unsigned-aligned.apk
222+
223+
fi
214224
)
215225
fi
216226
# /BUILD_ANDROID
217227

218228
fi
219-
# /Darwin
229+
# /Darwin/Linux/Windows
220230

221231
if [ "$OS" = "Linux" ] ; then
222232
# ======================================================================

calib_camera.cpp

Lines changed: 61 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,16 @@ int main(int argc, char *argv[])
636636
}
637637
#endif
638638
if (!gPostVideoSetupDone) {
639-
639+
#ifdef ANDROID
640+
char *toast;
641+
if (asprintf(&toast, "Camera: %dx%d", vs->getVideoWidth(), vs->getVideoHeight()) < 0) {
642+
ARLOGe("asprintf");
643+
} else {
644+
SDL_AndroidShowToast(toast, 1, -1, 0, 0); // int duration = 1 = long, int gravity = -1 = don't care, int xoffset, int yoffset
645+
free(toast);
646+
}
647+
#endif
648+
640649
gCameraIsFrontFacing = false;
641650
AR2VideoParamT *vid = vs->getAR2VideoParam();
642651

@@ -870,7 +879,7 @@ static void init(int argc, char *argv[])
870879
}
871880
}
872881

873-
static void drawBackground(const float width, const float height, const float x, const float y, const bool drawBorder)
882+
static void drawBackground(const float width, const float height, const float x, const float y, const bool drawBorder, const GLfloat p[16])
874883
{
875884
GLfloat vertices[4][2];
876885
#if HAVE_GLES2
@@ -884,7 +893,7 @@ static void drawBackground(const float width, const float height, const float x,
884893
vertices[3][0] = x; vertices[3][1] = height + y;
885894

886895
#if !HAVE_GLES2
887-
glLoadIdentity();
896+
glLoadIdentity(); // Reset to ortho origin. Assumes MODELVIEW mode.
888897
glDisable(GL_DEPTH_TEST);
889898
glDisable(GL_LIGHTING);
890899
glDisable(GL_TEXTURE_2D);
@@ -903,6 +912,8 @@ static void drawBackground(const float width, const float height, const float x,
903912
glDrawArrays(GL_LINE_LOOP, 0, 4);
904913
}
905914
#else
915+
glUseProgram(program);
916+
glUniformMatrix4fv(uniforms[UNIFORM_MODELVIEW_PROJECTION_MATRIX], 1, GL_FALSE, p);
906917
glStateCacheDisableDepthTest();
907918
glStateCacheBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
908919
glStateCacheEnableBlend();
@@ -921,15 +932,17 @@ static void drawBackground(const float width, const float height, const float x,
921932

922933
// An animation while we're waiting.
923934
// Designed to be drawn on background of at least 3xsquareSize wide and tall.
924-
static void drawBusyIndicator(int positionX, int positionY, int squareSize, struct timeval *tp)
935+
static void drawBusyIndicator(int positionX, int positionY, int squareSize, struct timeval *tp, const GLfloat p[16])
925936
{
926-
#if !HAVE_GLES2
927937
const GLfloat square_vertices [4][2] = { {0.5f, 0.5f}, {squareSize - 0.5f, 0.5f}, {squareSize - 0.5f, squareSize - 0.5f}, {0.5f, squareSize - 0.5f} };
928938
int i;
929939

930940
int hundredthSeconds = (int)tp->tv_usec / 1E4;
941+
int secDiv255 = (int)tp->tv_usec / 3921;
942+
int secMod6 = tp->tv_sec % 6;
931943

932944
// Set up drawing.
945+
#if !HAVE_GLES2
933946
glPushMatrix();
934947
glLoadIdentity();
935948
glDisable(GL_DEPTH_TEST);
@@ -941,14 +954,28 @@ static void drawBusyIndicator(int positionX, int positionY, int squareSize, stru
941954
glDisableClientState(GL_NORMAL_ARRAY);
942955
glClientActiveTexture(GL_TEXTURE0);
943956
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
957+
#else
958+
GLfloat mvp[16];
959+
glStateCacheDisableDepthTest();
960+
glStateCacheDisableBlend();
961+
glVertexAttribPointer(ATTRIBUTE_VERTEX, 2, GL_FLOAT, GL_FALSE, 0, square_vertices);
962+
glEnableVertexAttribArray(ATTRIBUTE_VERTEX);
963+
#endif
944964

945965
for (i = 0; i < 4; i++) {
966+
float tx = (float)(positionX + ((i + 1)/2 != 1 ? -squareSize : 0.0f));
967+
float ty = (float)(positionY + (i / 2 == 0 ? 0.0f : -squareSize));
968+
#if !HAVE_GLES2
946969
glLoadIdentity();
947-
glTranslatef((float)(positionX + ((i + 1)/2 != 1 ? -squareSize : 0.0f)), (float)(positionY + (i / 2 == 0 ? 0.0f : -squareSize)), 0.0f); // Order: UL, UR, LR, LL.
970+
glTranslatef(tx, ty , 0.0f); // Order: UL, UR, LR, LL.
971+
#else
972+
mtxLoadMatrixf(mvp, p);
973+
mtxTranslatef(mvp, tx, ty, 0.0f);
974+
glUseProgram(program);
975+
glUniformMatrix4fv(uniforms[UNIFORM_MODELVIEW_PROJECTION_MATRIX], 1, GL_FALSE, mvp);
976+
#endif
948977
if (i == hundredthSeconds / 25) {
949978
unsigned char r, g, b;
950-
int secDiv255 = (int)tp->tv_usec / 3921;
951-
int secMod6 = tp->tv_sec % 6;
952979
if (secMod6 == 0) {
953980
r = 255; g = secDiv255; b = 0;
954981
} else if (secMod6 == 1) {
@@ -962,13 +989,24 @@ static void drawBusyIndicator(int positionX, int positionY, int squareSize, stru
962989
} else {
963990
r = 255; g = 0; b = secDiv255;
964991
}
992+
#if !HAVE_GLES2
965993
glColor4ub(r, g, b, 255);
994+
#else
995+
const float color[4] = {(float)r/255.0f, (float)g/255.0f, (float)b/255.0f, 1.0f};
996+
glUniform4fv(uniforms[UNIFORM_COLOR], 1, color);
997+
#endif
966998
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
967999
}
1000+
#if !HAVE_GLES2
9681001
glColor4ub(255, 255, 255, 255);
1002+
#else
1003+
const float colorWhite[4] = {1.0f, 1.0f, 1.0f, 1.0f};
1004+
glUniform4fv(uniforms[UNIFORM_COLOR], 1, colorWhite);
1005+
#endif
9691006
glDrawArrays(GL_LINE_LOOP, 0, 4);
9701007
}
9711008

1009+
#if !HAVE_GLES2
9721010
glPopMatrix();
9731011
#endif // !HAVE_GLES2
9741012
}
@@ -1127,20 +1165,26 @@ void drawView(void)
11271165
//
11281166
// Setup for drawing on top of video frame, in viewPort coordinates.
11291167
//
1130-
#if 0
1131-
glMatrixMode(GL_PROJECTION);
1132-
glLoadIdentity();
1168+
#if 0 // NOT USED
11331169
bottom = 0.0f;
11341170
top = (float)(viewPort[viewPortIndexHeight]);
11351171
left = 0.0f;
11361172
right = (float)(viewPort[viewPortIndexWidth]);
1173+
# if !HAVE_GLES2
1174+
glMatrixMode(GL_PROJECTION);
1175+
glLoadIdentity();
11371176
glOrthof(left, right, bottom, top, -1.0f, 1.0f);
11381177
glMatrixMode(GL_MODELVIEW);
11391178
glLoadIdentity();
1140-
1179+
# else
1180+
mtxLoadIdentityf(p);
1181+
mtxOrthof(p, left, right, bottom, top, -1.0f, 1.0f);
1182+
glUseProgram(program);
1183+
glUniformMatrix4fv(uniforms[UNIFORM_MODELVIEW_PROJECTION_MATRIX], 1, GL_FALSE, p);
1184+
# endif
11411185
EdenGLFontSetViewSize(right, top);
11421186
EdenMessageSetViewSize(right, top, gDisplayDPI);
1143-
#endif
1187+
#endif // 0
11441188

11451189
//
11461190
// Setup for drawing on screen, with correct orientation for user.
@@ -1152,12 +1196,11 @@ void drawView(void)
11521196
right = (float)contextWidth;
11531197
mtxLoadIdentityf(p);
11541198
mtxOrthof(p, left, right, bottom, top, -1.0f, 1.0f);
1155-
mtxLoadIdentityf(m);
11561199
#if !HAVE_GLES2
11571200
glMatrixMode(GL_PROJECTION);
11581201
glLoadMatrixf(p);
11591202
glMatrixMode(GL_MODELVIEW);
1160-
glLoadMatrixf(m);
1203+
glLoadIdentity();
11611204
#else
11621205
glUseProgram(program);
11631206
glUniformMatrix4fv(uniforms[UNIFORM_MODELVIEW_PROJECTION_MATRIX], 1, GL_FALSE, p);
@@ -1170,7 +1213,7 @@ void drawView(void)
11701213

11711214
// Draw status bar with centred status message.
11721215
if (statusBarMessage[0]) {
1173-
drawBackground(right, statusBarHeight, 0.0f, 0.0f, false);
1216+
drawBackground(right, statusBarHeight, 0.0f, 0.0f, false, p);
11741217
glDisable(GL_BLEND);
11751218
EdenGLFontDrawLine(0, p, statusBarMessage, 0.0f, 2.0f, H_OFFSET_VIEW_CENTER_TO_TEXT_CENTER, V_OFFSET_VIEW_BOTTOM_TO_TEXT_BASELINE);
11761219
}
@@ -1187,8 +1230,8 @@ void drawView(void)
11871230
h = MAX(FONT_SIZE, 3*squareSize) + 2*4.0f /* box margin */;
11881231
x = right - (w + 2.0f);
11891232
y = statusBarHeight + 2.0f;
1190-
drawBackground(w, h, x, y, true);
1191-
if (status == 1) drawBusyIndicator((int)(x + 4.0f + 1.5f*squareSize), (int)(y + 4.0f + 1.5f*squareSize), squareSize, &time);
1233+
drawBackground(w, h, x, y, true, p);
1234+
if (status == 1) drawBusyIndicator((int)(x + 4.0f + 1.5f*squareSize), (int)(y + 4.0f + 1.5f*squareSize), squareSize, &time, p);
11921235
EdenGLFontDrawLine(0, p, (unsigned char *)uploadStatus, x + 4.0f + 3*squareSize, y + (h - FONT_SIZE)/2.0f, H_OFFSET_VIEW_LEFT_EDGE_TO_TEXT_LEFT_EDGE, V_OFFSET_VIEW_BOTTOM_TO_TEXT_BASELINE);
11931236
}
11941237
}

iOS/ARViewController.mm

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -665,34 +665,31 @@ - (void) drawBackgroundWidth:(const float)width height:(const float)height x:(co
665665

666666
// An animation while we're waiting.
667667
// Designed to be drawn on background of at least 3xsquareSize wide and tall.
668-
- (void) drawBusyIndicatorPositionX:(int)positionX positionY:(int)positionY squareSize:(int)squareSize tp:(struct timeval *)tp
668+
- (void) drawBusyIndicatorPositionX:(int)positionX positionY:(int)positionY squareSize:(int)squareSize tp:(struct timeval *)tp projection:(GLfloat [16])p
669669
{
670-
#if 0
671670
const GLfloat square_vertices [4][2] = { {0.5f, 0.5f}, {squareSize - 0.5f, 0.5f}, {squareSize - 0.5f, squareSize - 0.5f}, {0.5f, squareSize - 0.5f} };
672671
int i;
673672

674673
int hundredthSeconds = (int)tp->tv_usec / 1E4;
674+
int secDiv255 = (int)tp->tv_usec / 3921;
675+
int secMod6 = tp->tv_sec % 6;
675676

676677
// Set up drawing.
677-
glPushMatrix();
678-
glLoadIdentity();
679-
glDisable(GL_DEPTH_TEST);
680-
glDisable(GL_LIGHTING);
681-
glDisable(GL_TEXTURE_2D);
682-
glDisable(GL_BLEND);
683-
glVertexPointer(2, GL_FLOAT, 0, square_vertices);
684-
glEnableClientState(GL_VERTEX_ARRAY);
685-
glDisableClientState(GL_NORMAL_ARRAY);
686-
glClientActiveTexture(GL_TEXTURE0);
687-
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
678+
GLfloat mvp[16];
679+
glStateCacheDisableDepthTest();
680+
glStateCacheDisableBlend();
681+
glVertexAttribPointer(ATTRIBUTE_VERTEX, 2, GL_FLOAT, GL_FALSE, 0, square_vertices);
682+
glEnableVertexAttribArray(ATTRIBUTE_VERTEX);
688683

689684
for (i = 0; i < 4; i++) {
690-
glLoadIdentity();
691-
glTranslatef((float)(positionX + ((i + 1)/2 != 1 ? -squareSize : 0.0f)), (float)(positionY + (i / 2 == 0 ? 0.0f : -squareSize)), 0.0f); // Order: UL, UR, LR, LL.
685+
float tx = (float)(positionX + ((i + 1)/2 != 1 ? -squareSize : 0.0f));
686+
float ty = (float)(positionY + (i / 2 == 0 ? 0.0f : -squareSize));
687+
mtxLoadMatrixf(mvp, p);
688+
mtxTranslatef(mvp, tx, ty, 0.0f);
689+
glUseProgram(program);
690+
glUniformMatrix4fv(uniforms[UNIFORM_MODELVIEW_PROJECTION_MATRIX], 1, GL_FALSE, mvp);
692691
if (i == hundredthSeconds / 25) {
693-
char r, g, b;
694-
int secDiv255 = (int)tp->tv_usec / 3921;
695-
int secMod6 = tp->tv_sec % 6;
692+
unsigned char r, g, b;
696693
if (secMod6 == 0) {
697694
r = 255; g = secDiv255; b = 0;
698695
} else if (secMod6 == 1) {
@@ -706,15 +703,14 @@ - (void) drawBusyIndicatorPositionX:(int)positionX positionY:(int)positionY squa
706703
} else {
707704
r = 255; g = 0; b = secDiv255;
708705
}
709-
glColor4ub(r, g, b, 255);
706+
const float color[4] = {(float)r/255.0f, (float)g/255.0f, (float)b/255.0f, 1.0f};
707+
glUniform4fv(uniforms[UNIFORM_COLOR], 1, color);
710708
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
711709
}
712-
glColor4ub(255, 255, 255, 255);
710+
const float colorWhite[4] = {1.0f, 1.0f, 1.0f, 1.0f};
711+
glUniform4fv(uniforms[UNIFORM_COLOR], 1, colorWhite);
713712
glDrawArrays(GL_LINE_LOOP, 0, 4);
714713
}
715-
716-
glPopMatrix();
717-
#endif
718714
}
719715

720716
- (void)tearDownGL
@@ -768,7 +764,7 @@ - (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
768764

769765
if (!gPostVideoSetupDone) {
770766

771-
[ARViewController displayToastWithMessage:[NSString stringWithFormat:@"Camera: %dx%d", vs->getVideoWidth(), vs->getVideoHeight()]];
767+
[ARViewController displayToastWithMessage:[NSString stringWithFormat:@"Camera: %dx%d", vs->getVideoWidth(), vs->getVideoHeight()] durationSeconds:5.0f];
772768

773769
gCameraIsFrontFacing = false;
774770
AR2VideoParamT *vid = vs->getAR2VideoParam();
@@ -1028,7 +1024,7 @@ - (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
10281024
x = right - (w + 2.0f);
10291025
y = statusBarHeight + 2.0f;
10301026
[self drawBackgroundWidth:w height:h x:x y:y border:true projection:p];
1031-
if (status == 1) [self drawBusyIndicatorPositionX:(int)(x + 4.0f + 1.5f*squareSize) positionY:(int)(y + 4.0f + 1.5f*squareSize) squareSize:squareSize tp:&time];
1027+
if (status == 1) [self drawBusyIndicatorPositionX:(int)(x + 4.0f + 1.5f*squareSize) positionY:(int)(y + 4.0f + 1.5f*squareSize) squareSize:squareSize tp:&time projection:p];
10321028
EdenGLFontDrawLine(0, p, (unsigned char *)uploadStatus, x + 4.0f + 3*squareSize, y + (h - FONT_SIZE)/2.0f, H_OFFSET_VIEW_LEFT_EDGE_TO_TEXT_LEFT_EDGE, V_OFFSET_VIEW_BOTTOM_TO_TEXT_BASELINE);
10331029
}
10341030
}
@@ -1382,7 +1378,7 @@ - (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionControl
13821378

13831379
}
13841380

1385-
+ (void)displayToastWithMessage:(NSString *)toastMessage
1381+
+ (void)displayToastWithMessage:(NSString *)toastMessage durationSeconds:(float)durationSeconds
13861382
{
13871383
[[NSOperationQueue mainQueue] addOperationWithBlock:^ {
13881384
UIWindow * keyWindow = [[UIApplication sharedApplication] keyWindow];
@@ -1400,7 +1396,7 @@ + (void)displayToastWithMessage:(NSString *)toastMessage
14001396

14011397
[keyWindow addSubview:toastView];
14021398

1403-
[UIView animateWithDuration: 3.0f
1399+
[UIView animateWithDuration: durationSeconds
14041400
delay: 0.0
14051401
options: UIViewAnimationOptionCurveEaseOut
14061402
animations: ^{
@@ -1413,6 +1409,10 @@ + (void)displayToastWithMessage:(NSString *)toastMessage
14131409
}];
14141410
}
14151411

1412+
+ (void)displayToastWithMessage:(NSString *)toastMessage {
1413+
[ARViewController displayToastWithMessage:toastMessage durationSeconds:3.5f];
1414+
}
1415+
14161416
@end
14171417

14181418
// Save parameters file and index file with info about it, then signal thread that it's ready for upload.

0 commit comments

Comments
 (0)