• R/O
  • HTTP
  • SSH
  • HTTPS

android: Commit

FermiSurfer for android


Commit MetaInfo

Revision9deaed391b59be69e32f78cf57ca606560e90b6b (tree)
Zeit2019-08-31 22:21:24
Autormitsuaki1987 <kawamitsuaki@gmai...>
Commitermitsuaki1987

Log Message

Enable zoomup/zoomdown
turn off color-bar

Ändern Zusammenfassung

Diff

--- a/Android1.NativeActivity/main.cpp
+++ b/Android1.NativeActivity/main.cpp
@@ -176,6 +176,8 @@ struct saved_state {
176176 int32_t y;
177177 int32_t x0;
178178 int32_t y0;
179+ int32_t zoom;
180+ int32_t zoom0;
179181 };
180182 /**
181183 * アプリの保存状態です。
@@ -273,46 +275,50 @@ static int engine_init_display(struct engine* engine) {
273275 /**
274276 * ディスプレイ内の現在のフレームのみ。
275277 */
276-static void engine_draw_frame(struct engine* engine) {
278+static void engine_draw_frame(struct engine* engine, int flag) {
277279 int i, j;
278280 GLfloat dx, dy, a, rot0[3][3], rot1[3][3], ax, ay, sx = 1.0/engine->width, sy = 1.0/engine->height;
279-
280- /*
281- Translation of mousepointer from starting point
282- */
283- dx = (engine->state.x - engine->state.x0) * sx;
284- dy = (engine->state.y - engine->state.y0) * sy;
285- /*
286- Distanse from starting point
287- */
288- a = sqrtf(dx * dx + dy * dy);
289- /**/
290- if (a != 0.0) {
281+ if (flag == 0) {
282+ scl *= expf((GLfloat)(engine->state.zoom0 - engine->state.zoom) * sy);
283+ }
284+ else if (flag == 1) {
291285 /*
292- Compute rotational matrix from translation of mousepointer
286+ Translation of mousepointer from starting point
293287 */
294- ax = -dy;
295- ay = dx;
296- /**/
297- a = a * 10.0f;
298- /**/
299- rot0[0][0] = (ax * ax + ay * ay * cosf(a)) / (ax * ax + ay * ay);
300- rot0[0][1] = ax * ay * (cosf(a) - 1.0f) / (ax * ax + ay * ay);
301- rot0[0][2] = ay * sinf(a) / sqrtf(ax * ax + ay * ay);
302- rot0[1][0] = ax * ay * (cosf(a) - 1.0f) / (ax * ax + ay * ay);
303- rot0[1][1] = (ax * ax * cosf(a) + ay * ay) / (ax * ax + ay * ay);
304- rot0[1][2] = ax * sinf(a) / sqrtf(ax * ax + ay * ay);
305- rot0[2][0] = -ay * sinf(a) / sqrtf(ax * ax + ay * ay);
306- rot0[2][1] = -ax * sinf(a) / sqrtf(ax * ax + ay * ay);
307- rot0[2][2] = cosf(a);
308- /**/
309- for (i = 0; i < 3; i++) for (j = 0; j < 3; j++) rot1[i][j] = rot[i][j];
288+ dx = (engine->state.x - engine->state.x0) * sx;
289+ dy = (engine->state.y - engine->state.y0) * sy;
290+ /*
291+ Distanse from starting point
292+ */
293+ a = sqrtf(dx * dx + dy * dy);
310294 /**/
311- for (i = 0; i < 3; i++) {
312- for (j = 0; j < 3; j++) {
313- rot[i][j] = rot0[i][0] * rot1[0][j]
314- + rot0[i][1] * rot1[1][j]
315- + rot0[i][2] * rot1[2][j];
295+ if (a != 0.0) {
296+ /*
297+ Compute rotational matrix from translation of mousepointer
298+ */
299+ ax = -dy;
300+ ay = dx;
301+ /**/
302+ a = a * 10.0f;
303+ /**/
304+ rot0[0][0] = (ax * ax + ay * ay * cosf(a)) / (ax * ax + ay * ay);
305+ rot0[0][1] = ax * ay * (cosf(a) - 1.0f) / (ax * ax + ay * ay);
306+ rot0[0][2] = ay * sinf(a) / sqrtf(ax * ax + ay * ay);
307+ rot0[1][0] = ax * ay * (cosf(a) - 1.0f) / (ax * ax + ay * ay);
308+ rot0[1][1] = (ax * ax * cosf(a) + ay * ay) / (ax * ax + ay * ay);
309+ rot0[1][2] = ax * sinf(a) / sqrtf(ax * ax + ay * ay);
310+ rot0[2][0] = -ay * sinf(a) / sqrtf(ax * ax + ay * ay);
311+ rot0[2][1] = -ax * sinf(a) / sqrtf(ax * ax + ay * ay);
312+ rot0[2][2] = cosf(a);
313+ /**/
314+ for (i = 0; i < 3; i++) for (j = 0; j < 3; j++) rot1[i][j] = rot[i][j];
315+ /**/
316+ for (i = 0; i < 3; i++) {
317+ for (j = 0; j < 3; j++) {
318+ rot[i][j] = rot0[i][0] * rot1[0][j]
319+ + rot0[i][1] * rot1[1][j]
320+ + rot0[i][2] * rot1[2][j];
321+ }
316322 }
317323 }
318324 }
@@ -347,16 +353,29 @@ static void engine_term_display(struct engine* engine) {
347353 static int32_t engine_handle_input(struct android_app* app, AInputEvent* event) {
348354 struct engine* engine = (struct engine*)app->userData;
349355 if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION) {
350- if (AMotionEvent_getAction(event) == AMOTION_EVENT_ACTION_DOWN) {
351- engine->state.x = AMotionEvent_getX(event, 0);
352- engine->state.y = AMotionEvent_getY(event, 0);
356+ if (AMotionEvent_getX(event, 0) > 0.95* engine->width ||
357+ AMotionEvent_getX(event, 0) < 0.05 * engine->width) {
358+ if (AMotionEvent_getAction(event) == AMOTION_EVENT_ACTION_DOWN) {
359+ engine->state.zoom = AMotionEvent_getY(event, 0);
360+ }
361+ else if (AMotionEvent_getAction(event) == AMOTION_EVENT_ACTION_MOVE) {
362+ engine->state.zoom0 = engine->state.zoom;
363+ engine->state.zoom = AMotionEvent_getY(event, 0);
364+ engine_draw_frame(engine, 0);
365+ }
353366 }
354- else if (AMotionEvent_getAction(event) == AMOTION_EVENT_ACTION_MOVE) {
355- engine->state.x0 = engine->state.x;
356- engine->state.y0 = engine->state.y;
357- engine->state.x = AMotionEvent_getX(event, 0);
358- engine->state.y = AMotionEvent_getY(event, 0);
359- engine_draw_frame(engine);
367+ else {
368+ if (AMotionEvent_getAction(event) == AMOTION_EVENT_ACTION_DOWN) {
369+ engine->state.x = AMotionEvent_getX(event, 0);
370+ engine->state.y = AMotionEvent_getY(event, 0);
371+ }
372+ else if (AMotionEvent_getAction(event) == AMOTION_EVENT_ACTION_MOVE) {
373+ engine->state.x0 = engine->state.x;
374+ engine->state.y0 = engine->state.y;
375+ engine->state.x = AMotionEvent_getX(event, 0);
376+ engine->state.y = AMotionEvent_getY(event, 0);
377+ engine_draw_frame(engine, 1);
378+ }
360379 }
361380 return 1;
362381 }
@@ -378,7 +397,9 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
378397 // ウィンドウが表示されています。準備してください。
379398 if (engine->app->window != NULL) {
380399 engine_init_display(engine);
381- engine_draw_frame(engine);
400+ engine->state.zoom = 0;
401+ engine->state.zoom0 = 0;
402+ engine_draw_frame(engine, 0);
382403 }
383404 break;
384405 case APP_CMD_TERM_WINDOW:
@@ -389,7 +410,7 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
389410 break;
390411 case APP_CMD_LOST_FOCUS:
391412 // また、アニメーションを停止します。
392- engine_draw_frame(engine);
413+ engine_draw_frame(engine, 0);
393414 break;
394415 }
395416 }
@@ -414,6 +435,7 @@ void android_main(struct android_app* state) {
414435 }
415436
416437 color_scale = read_file();
438+ lcolorbar = 0;
417439 interpol_energy();
418440 init_corner();
419441 bragg_vector();
Show on old repository browser