Mercurial > hg > old > magoroku_racing
view SgoexCerium.cc @ 122:5219bf3d5e71
title_draw
author | e085768 |
---|---|
date | Mon, 27 Jun 2011 19:44:46 +0900 |
parents | 31dd5c07f7c1 |
children |
line wrap: on
line source
#include "matrix_calc.h" #include "TaskManager.h" #include "SceneGraph.h" #include "Application.h" #include "SgoexCerium.h" #include "gSprite.h" extern Viewer *droot; static SceneGraphPtr root; void flip() { CameraPtr camera = droot->sgroot->getCamera(); droot->sgroot->flip(); droot->sgroot->lightCalc(); root = droot->createSceneGraph(); //root->xyz[0] = screen_w/2; //root->xyz[1] = screen_h/2;; root->xyz[0] = 0; root->xyz[1] = 0; root->xyz[2] = 30.0f; /*親の回転、座標から、子の回転、座標を算出*/ get_matrix(root->matrix, root->angle, root->xyz, camera->matrix); /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/ get_matrix(root->real_matrix, root->angle, root->xyz, camera->real_matrix); droot->setSceneData(root); } SpriteTable sptable[DEFOBJ]; void DefSpriteEx(int number, short middlex, short middley) { sptable[number].mx = middlex; sptable[number].my = middley; } void DefSprite(int number, const char *name, float w, float h, int color, OBJECT *obj) { SpriteTable *m = &sptable[number]; m->w = w; m->h = h; m->color = (color & 32); m->mx = w / 2; m->my = h / 2; m->tex_w = power_of_two(m->w); m->tex_h = power_of_two(m->h); m->texture = (int *)name; } static float my_scale = 5; void PutSprite(int zorder, short x, short y, int number) { SpriteTable *m = &sptable[number]; char *name = (char *) m->texture; if (!name) { printf("PutSprite %d unknown\n",number); return; } SceneGraphPtr object = droot->createSceneGraph(name); //object->c_xyz[0] = m->mx; //object->c_xyz[1] = m->my; root->addChild(object); object->xyz[0] -= object->c_xyz[0]*my_scale; object->xyz[1] -= object->c_xyz[1]*my_scale; object->xyz[2] -= object->c_xyz[2]; object->xyz[0] += x+m->mx; object->xyz[1] += y+m->my; object->xyz[2] += zorder * 0.01; float scale[] = {my_scale,my_scale,1}; //float c_xyz[] = {0,0,0}; //scale_matrix(object->matrix, scale, c_xyz); /*親の回転、座標から、子の回転、座標を算出*/ // get_matrix_scale(object->matrix, object->angle, object->xyz, scale, root->matrix); /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/ // get_matrix(object->real_matrix, object->angle, object->xyz, root->real_matrix); } void PutSpriteEx(int number, int x, int y, float scalex, float scaley, float angle) { if (1) { PutSprite(1, x, y, number); return; } SpriteTable *m = &sptable[number]; char *name = (char *) m->texture; if (!name) { printf("PutSpriteEx %d unknown\n",number); return; } SceneGraphPtr object = droot->createSceneGraph(name); root->addChild(object); float scale[] = {my_scale*scalex*4,my_scale*scaley*4,1}; /*親の回転、座標から、子の回転、座標を算出*/ object->xyz[0] = x - object->c_xyz[0] * my_scale - m->w*my_scale; object->xyz[1] = y - object->c_xyz[1] * my_scale - m->h*my_scale; object->xyz[2] = number * 0.01; //object->c_xyz[0] = m->mx; //object->c_xyz[1] = m->my; object->angle[3] = angle * (3.1415926*2/4096); get_matrix(object->matrix, object->angle, object->xyz, root->matrix); float c_xyz[] = {0,0,0}; scale_matrix(object->matrix, scale, c_xyz); /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/ // get_matrix(object->real_matrix, object->angle, object->xyz, root->real_matrix); } struct SGO_PAD pad[2]; /* コントローラ状態の読み込み */ void Pad(SDL_Joystick *joy) { Sint16 axis; SDL_JoystickUpdate(); if(SDL_JoystickGetButton(joy,PS2_CROSS)==SDL_PRESSED) pad[0].k0++; else pad[0].k0=0; if(SDL_JoystickGetButton(joy,PS2_CIRCLE)==SDL_PRESSED) pad[0].k1++; else pad[0].k1=0; if(SDL_JoystickGetButton(joy,PS2_SQUARE)==SDL_PRESSED) pad[0].k3++; else pad[0].k3=0; if(SDL_JoystickGetButton(joy,PS2_TRIANGLE)==SDL_PRESSED) pad[0].k4++; else pad[0].k4=0; if(SDL_JoystickGetButton(joy,PS2_L1)==SDL_PRESSED) pad[0].l1++; else pad[0].l1=0; if(SDL_JoystickGetButton(joy,PS2_R1)==SDL_PRESSED) pad[0].r1++; else pad[0].r1=0; if(SDL_JoystickGetButton(joy,PS2_L2)==SDL_PRESSED) pad[0].l2++; else pad[0].l2=0; if(SDL_JoystickGetButton(joy,PS2_R2)==SDL_PRESSED) pad[0].r2++; else pad[0].r2=0; if(SDL_JoystickGetButton(joy,PS2_START)==SDL_PRESSED) pad[0].st++; else pad[0].st=0; if(SDL_JoystickGetButton(joy,PS2_SELECT)==SDL_PRESSED) pad[0].se++; else pad[0].se=0; if(SDL_JoystickGetButton(joy,PS2_L3)==SDL_PRESSED) pad[0].l3++; else pad[0].l3=0; if(SDL_JoystickGetButton(joy,PS2_R3)==SDL_PRESSED) pad[0].r3++; else pad[0].r3=0; //x axis=SDL_JoystickGetAxis(joy,0); if(axis>=3200){ pad[0].left=0; pad[0].right++; } else if(axis<=-3200){ pad[0].right=0; pad[0].left++; } else { pad[0].right=0; pad[0].left=0; } //y axis=SDL_JoystickGetAxis(joy,1); if(axis>=3200){ pad[0].up=0; pad[0].down++; } else if(axis<=-3200){ pad[0].down=0; pad[0].up++; } else { pad[0].down=0; pad[0].up=0; } if ((pad[0].l1 != 0) && (pad[0].r1 != 0) && (pad[0].l2 != 0) && (pad[0].r2 != 0) && (pad[0].st != 0) && (pad[0].se != 0)) { pad[0].quit = 1; } else { pad[0].quit = 0; } } void keybord() { SDL_PumpEvents(); Uint8 *keys = SDL_GetKeyState(NULL); if (keys[SDLK_UP]) { pad[0].up++; } else { pad[0].up = 0; } if (keys[SDLK_DOWN]) { pad[0].down++; } else { pad[0].down = 0; } if (keys[SDLK_RIGHT]) { pad[0].right++; } else { pad[0].right = 0; } if (keys[SDLK_LEFT]) { pad[0].left++; } else { pad[0].left = 0; } if (keys[SDLK_a]) { pad[0].k0++; } else { pad[0].k0 = 0; } if (keys[SDLK_z]) { pad[0].k1++; } else { pad[0].k1 = 0; } if (keys[SDLK_s]) { pad[0].k3++; } else { pad[0].k3 = 0; } if (keys[SDLK_x]) { pad[0].k4++; } else { pad[0].k4 = 0; } if (keys[SDLK_r]) { pad[0].r2++; } else { pad[0].r2 = 0; } if (keys[SDLK_e]) { pad[0].r1++; } else { pad[0].r1 = 0; } if (keys[SDLK_w]) { pad[0].l1++; } else { pad[0].l1 = 0; } if (keys[SDLK_q]) { pad[0].l2++; } else { pad[0].l2 = 0; } // START ボタンは Return が似合う気がする //if(keys[SDLK_1]) if (keys[SDLK_RETURN]) { pad[0].st++; } else { pad[0].st = 0; } if (keys[SDLK_2]) { pad[0].se++; } else { pad[0].se = 0; } if (keys[SDLK_ESCAPE]) { SDL_Quit(); exit(1); //pad[0].st = 1; //pad[0].se = 1; } if (keys[SDLK_0]) { pad[0].quit = 1; } else { pad[0].quit = 0; } } /* end */