Mercurial > hg > Members > kono > tree_dandy2
comparison Dandy.cc @ 32:8abcc221bbac
sgoex separation
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 21 May 2011 15:15:26 +0900 |
parents | 3b7e57614d93 |
children |
comparison
equal
deleted
inserted
replaced
31:3b7e57614d93 | 32:8abcc221bbac |
---|---|
1 #include "Dandy.h" | 1 #include "Dandy.h" |
2 #include "SgoexCerium.h" | |
2 #include <stdio.h> | 3 #include <stdio.h> |
3 #include <stdlib.h> | 4 #include <stdlib.h> |
4 #include <string.h> | 5 #include <string.h> |
5 #include <ctype.h> | 6 #include <ctype.h> |
6 #include <math.h> | 7 #include <math.h> |
72 | 73 |
73 const char *usr_help_str = "Usage: ./twice [-length data_length] [-count task_num]\n\ | 74 const char *usr_help_str = "Usage: ./twice [-length data_length] [-count task_num]\n\ |
74 -length Number of data (default DATA_NUM (Func.h))\n\ | 75 -length Number of data (default DATA_NUM (Func.h))\n\ |
75 -count Number of task (default 1)\n"; | 76 -count Number of task (default 1)\n"; |
76 | 77 |
77 static Viewer *sgroot; | 78 Viewer *droot; |
78 | 79 |
79 static int screen_w; | 80 static int screen_w; |
80 static int screen_h; | 81 static int screen_h; |
81 | 82 |
82 MainLoopPtr | 83 MainLoopPtr |
83 Dandy::init(Viewer *sgroot_, int w, int h) | 84 Dandy::init(Viewer *sgroot_, int w, int h) |
84 { | 85 { |
85 screen_w = w; | 86 screen_w = w; |
86 screen_h = h; | 87 screen_h = h; |
87 sgroot = sgroot_; | 88 droot = sgroot_; |
88 return sgroot; | 89 return droot; |
89 } | 90 } |
90 | 91 |
91 Application * | 92 Application * |
92 application() { | 93 application() { |
93 return new Dandy(); | 94 return new Dandy(); |
186 | 187 |
187 /** | 188 /** |
188 * timeprof があるんだけどね | 189 * timeprof があるんだけどね |
189 */ | 190 */ |
190 | 191 |
191 sgroot->createFromXMLfile("xml/character.xml"); | 192 droot->createFromXMLfile("xml/character.xml"); |
192 sgroot->createFromXMLfile("xml/font.xml"); | 193 droot->createFromXMLfile("xml/font.xml"); |
193 sgroot->createFromXMLfile("xml/effect.xml"); | 194 droot->createFromXMLfile("xml/effect.xml"); |
194 sgroot->createFromXMLfile("xml/boss.xml"); | 195 droot->createFromXMLfile("xml/boss.xml"); |
195 | 196 |
196 LightSysSwitch(sgroot); | 197 LightSysSwitch(droot); |
197 | 198 |
198 | 199 |
199 init_sprite(0,0,0,0); | 200 init_sprite(0,0,0,0); |
200 | 201 |
201 __debug("syokikaが呼びだされました\n"); | 202 __debug("syokikaが呼びだされました\n"); |
238 } | 239 } |
239 | 240 |
240 __debug("finished init_chara_list\n"); | 241 __debug("finished init_chara_list\n"); |
241 | 242 |
242 return 1; | 243 return 1; |
243 } | |
244 | |
245 SceneGraphPtr root; | |
246 | |
247 // extern void get_matrix(float *matrix, float *rxyz, float *txyz, float *scale, float *stack); | |
248 | |
249 static void | |
250 flip() | |
251 { | |
252 CameraPtr camera = sgroot->sgroot->getCamera(); | |
253 | |
254 sgroot->sgroot->flip(); | |
255 sgroot->sgroot->lightCalc(); | |
256 | |
257 root = sgroot->createSceneGraph(); | |
258 //root->xyz[0] = screen_w/2; | |
259 //root->xyz[1] = screen_h/2;; | |
260 root->xyz[0] = 0; | |
261 root->xyz[1] = 0; | |
262 root->xyz[2] = 30.0f; | |
263 | |
264 /*親の回転、座標から、子の回転、座標を算出*/ | |
265 get_matrix(root->matrix, root->angle, root->xyz, camera->matrix); | |
266 /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/ | |
267 get_matrix(root->real_matrix, root->angle, root->xyz, camera->real_matrix); | |
268 | |
269 sgroot->setSceneData(root); | |
270 } | 244 } |
271 | 245 |
272 | 246 |
273 static int | 247 static int |
274 dandy_main_loop(int gamef) | 248 dandy_main_loop(int gamef) |
525 } | 499 } |
526 return gamef; | 500 return gamef; |
527 } | 501 } |
528 | 502 |
529 | 503 |
530 SpriteTable sptable[DEFOBJ]; | |
531 | |
532 | |
533 void | |
534 DefSpriteEx(int number, short middlex, short middley) | |
535 { | |
536 sptable[number].mx = middlex; | |
537 sptable[number].my = middley; | |
538 } | |
539 | |
540 | |
541 void | |
542 DefSprite(int number, const char *name, float w, float h, int color, OBJECT *obj) | |
543 { | |
544 SpriteTable *m = &sptable[number]; | |
545 m->w = w; | |
546 m->h = h; | |
547 m->color = (color & 32); | |
548 m->mx = w / 2; | |
549 m->my = h / 2; | |
550 m->tex_w = power_of_two(m->w); | |
551 m->tex_h = power_of_two(m->h); | |
552 m->texture = (int *)name; | |
553 | |
554 } | |
555 | |
556 static float my_scale = 5; | |
557 | |
558 void | |
559 PutSprite(int zorder, short x, short y, int number) | |
560 { | |
561 SpriteTable *m = &sptable[number]; | |
562 char *name = (char *) m->texture; | |
563 if (!name) { | |
564 printf("PutSprite %d unknown\n",number); | |
565 return; | |
566 } | |
567 SceneGraphPtr object = sgroot->createSceneGraph(name); | |
568 //object->c_xyz[0] = m->mx; | |
569 //object->c_xyz[1] = m->my; | |
570 root->addChild(object); | |
571 | |
572 object->xyz[0] = x - object->c_xyz[0]*my_scale; | |
573 object->xyz[1] = y - object->c_xyz[1]*my_scale; | |
574 object->xyz[2] = zorder * 0.01; | |
575 | |
576 /*親の回転、座標から、子の回転、座標を算出*/ | |
577 get_matrix(object->matrix, object->angle, object->xyz, root->matrix); | |
578 | |
579 float scale[] = {my_scale,my_scale,1}; | |
580 float c_xyz[] = {0,0,0}; | |
581 scale_matrix(object->matrix, scale, c_xyz); | |
582 /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/ | |
583 get_matrix(object->real_matrix, object->angle, object->xyz, root->real_matrix); | |
584 } | |
585 | |
586 void | |
587 PutSpriteEx(int number, int x, int y, float scalex, float scaley, float angle) | |
588 { | |
589 if (1) { | |
590 PutSprite(1, x, y, number); | |
591 return; | |
592 } | |
593 | |
594 SpriteTable *m = &sptable[number]; | |
595 char *name = (char *) m->texture; | |
596 if (!name) { | |
597 printf("PutSpriteEx %d unknown\n",number); | |
598 return; | |
599 } | |
600 SceneGraphPtr object = sgroot->createSceneGraph(name); | |
601 root->addChild(object); | |
602 | |
603 float scale[] = {my_scale*scalex*4,my_scale*scaley*4,1}; | |
604 | |
605 /*親の回転、座標から、子の回転、座標を算出*/ | |
606 object->xyz[0] = x - object->c_xyz[0] * my_scale - m->w*my_scale; | |
607 object->xyz[1] = y - object->c_xyz[1] * my_scale - m->h*my_scale; | |
608 object->xyz[2] = number * 0.01; | |
609 //object->c_xyz[0] = m->mx; | |
610 //object->c_xyz[1] = m->my; | |
611 object->angle[3] = angle * (3.1415926*2/4096); | |
612 get_matrix(object->matrix, object->angle, object->xyz, root->matrix); | |
613 float c_xyz[] = {0,0,0}; | |
614 scale_matrix(object->matrix, scale, c_xyz); | |
615 /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/ | |
616 get_matrix(object->real_matrix, object->angle, object->xyz, root->real_matrix); | |
617 } | |
618 | |
619 | |
620 struct SGO_PAD pad[2]; | |
621 | |
622 | |
623 /* コントローラ状態の読み込み */ | |
624 void Pad(SDL_Joystick *joy) | |
625 { | |
626 Sint16 axis; | |
627 | |
628 SDL_JoystickUpdate(); | |
629 | |
630 if(SDL_JoystickGetButton(joy,PS2_CROSS)==SDL_PRESSED) | |
631 pad[0].k0++; | |
632 else | |
633 pad[0].k0=0; | |
634 | |
635 if(SDL_JoystickGetButton(joy,PS2_CIRCLE)==SDL_PRESSED) | |
636 pad[0].k1++; | |
637 else | |
638 pad[0].k1=0; | |
639 | |
640 if(SDL_JoystickGetButton(joy,PS2_SQUARE)==SDL_PRESSED) | |
641 pad[0].k3++; | |
642 else | |
643 pad[0].k3=0; | |
644 | |
645 if(SDL_JoystickGetButton(joy,PS2_TRIANGLE)==SDL_PRESSED) | |
646 pad[0].k4++; | |
647 else | |
648 pad[0].k4=0; | |
649 | |
650 if(SDL_JoystickGetButton(joy,PS2_L1)==SDL_PRESSED) | |
651 pad[0].l1++; | |
652 else | |
653 pad[0].l1=0; | |
654 | |
655 if(SDL_JoystickGetButton(joy,PS2_R1)==SDL_PRESSED) | |
656 pad[0].r1++; | |
657 else | |
658 pad[0].r1=0; | |
659 | |
660 if(SDL_JoystickGetButton(joy,PS2_L2)==SDL_PRESSED) | |
661 pad[0].l2++; | |
662 else | |
663 pad[0].l2=0; | |
664 | |
665 if(SDL_JoystickGetButton(joy,PS2_R2)==SDL_PRESSED) | |
666 pad[0].r2++; | |
667 else | |
668 pad[0].r2=0; | |
669 | |
670 if(SDL_JoystickGetButton(joy,PS2_START)==SDL_PRESSED) | |
671 pad[0].st++; | |
672 else | |
673 pad[0].st=0; | |
674 | |
675 if(SDL_JoystickGetButton(joy,PS2_SELECT)==SDL_PRESSED) | |
676 pad[0].se++; | |
677 else | |
678 pad[0].se=0; | |
679 | |
680 if(SDL_JoystickGetButton(joy,PS2_L3)==SDL_PRESSED) | |
681 pad[0].l3++; | |
682 else | |
683 pad[0].l3=0; | |
684 | |
685 if(SDL_JoystickGetButton(joy,PS2_R3)==SDL_PRESSED) | |
686 pad[0].r3++; | |
687 else | |
688 pad[0].r3=0; | |
689 //x | |
690 axis=SDL_JoystickGetAxis(joy,0); | |
691 if(axis>=3200){ | |
692 pad[0].left=0; | |
693 pad[0].right++; | |
694 } | |
695 else if(axis<=-3200){ | |
696 pad[0].right=0; | |
697 pad[0].left++; | |
698 } | |
699 else { | |
700 pad[0].right=0; | |
701 pad[0].left=0; | |
702 } | |
703 //y | |
704 axis=SDL_JoystickGetAxis(joy,1); | |
705 if(axis>=3200){ | |
706 pad[0].up=0; | |
707 pad[0].down++; | |
708 } | |
709 else if(axis<=-3200){ | |
710 pad[0].down=0; | |
711 pad[0].up++; | |
712 } | |
713 else { | |
714 pad[0].down=0; | |
715 pad[0].up=0; | |
716 } | |
717 | |
718 if ((pad[0].l1 != 0) && (pad[0].r1 != 0) && | |
719 (pad[0].l2 != 0) && (pad[0].r2 != 0) && | |
720 (pad[0].st != 0) && (pad[0].se != 0)) { | |
721 pad[0].quit = 1; | |
722 } else { | |
723 pad[0].quit = 0; | |
724 } | |
725 | |
726 } | |
727 | |
728 | |
729 void keybord() | |
730 { | |
731 SDL_PumpEvents(); | |
732 Uint8 *keys = SDL_GetKeyState(NULL); | |
733 | |
734 if (keys[SDLK_UP]) { | |
735 pad[0].up++; | |
736 } else { | |
737 pad[0].up = 0; | |
738 } | |
739 if (keys[SDLK_DOWN]) { | |
740 pad[0].down++; | |
741 } else { | |
742 pad[0].down = 0; | |
743 } | |
744 | |
745 if (keys[SDLK_RIGHT]) { | |
746 pad[0].right++; | |
747 } else { | |
748 pad[0].right = 0; | |
749 } | |
750 | |
751 if (keys[SDLK_LEFT]) { | |
752 pad[0].left++; | |
753 } else { | |
754 pad[0].left = 0; | |
755 } | |
756 | |
757 if (keys[SDLK_a]) { | |
758 pad[0].k0++; | |
759 } else { | |
760 pad[0].k0 = 0; | |
761 } | |
762 | |
763 if (keys[SDLK_z]) { | |
764 pad[0].k1++; | |
765 } else { | |
766 pad[0].k1 = 0; | |
767 } | |
768 | |
769 if (keys[SDLK_s]) { | |
770 pad[0].k3++; | |
771 } else { | |
772 pad[0].k3 = 0; | |
773 } | |
774 | |
775 if (keys[SDLK_x]) { | |
776 pad[0].k4++; | |
777 } else { | |
778 pad[0].k4 = 0; | |
779 } | |
780 | |
781 if (keys[SDLK_r]) { | |
782 pad[0].r2++; | |
783 } else { | |
784 pad[0].r2 = 0; | |
785 } | |
786 | |
787 if (keys[SDLK_e]) { | |
788 pad[0].r1++; | |
789 } else { | |
790 pad[0].r1 = 0; | |
791 } | |
792 | |
793 if (keys[SDLK_w]) { | |
794 pad[0].l1++; | |
795 } else { | |
796 pad[0].l1 = 0; | |
797 } | |
798 | |
799 if (keys[SDLK_q]) { | |
800 pad[0].l2++; | |
801 } else { | |
802 pad[0].l2 = 0; | |
803 } | |
804 | |
805 // START ボタンは Return が似合う気がする | |
806 //if(keys[SDLK_1]) | |
807 if (keys[SDLK_RETURN]) { | |
808 pad[0].st++; | |
809 } else { | |
810 pad[0].st = 0; | |
811 } | |
812 | |
813 if (keys[SDLK_2]) { | |
814 pad[0].se++; | |
815 } else { | |
816 pad[0].se = 0; | |
817 } | |
818 | |
819 if (keys[SDLK_ESCAPE]) { | |
820 SDL_Quit(); | |
821 exit(1); | |
822 //pad[0].st = 1; | |
823 //pad[0].se = 1; | |
824 } | |
825 | |
826 if (keys[SDLK_0]) { | |
827 pad[0].quit = 1; | |
828 } else { | |
829 pad[0].quit = 0; | |
830 } | |
831 } | |
832 | |
833 | 504 |
834 /* end */ | 505 /* end */ |