ODE講座21:テクスãƒãƒ£ã‚’切り替ãˆã‚ˆã†ï¼ï¼ˆç”»åƒãƒ©ã‚¤ãƒ–ラリ)


テクスãƒãƒ£ã‚’切り替ãˆã‚‹ã‚µãƒ³ãƒ—ルプãƒã‚°ãƒ©ãƒ
ãƒãƒƒãƒ—ã•ã‚“ã‹ã‚‰ã€Œãƒ—ãƒã‚°ãƒ©ãƒ ã«é–¢ã™ã‚‹è³ªå•ãªã®ã§ã™ãŒã€ãƒ†ã‚¯ã‚¹ãƒãƒ£ã‚’ãŸãã•ん使ã†ã«ã¯ã©ã†ã™ã‚Œã°ã„ã„ã®ã§ã—ょã†ã‹ï¼ŸLOOPã®ä¸ã§fn.path_to_texturesã®ãƒ‘スを変ãˆã¦ã‚‚テクスãƒãƒ£ãŒå¤‰ã‚らãªãã¦æ‚©ã‚“ã§ã„ã¾ã™ã€‚ã¨ã„ã†ã”質å•ã‚’é ‚ãã¾ã—ãŸä»Šå›žã®ODE講座ã§å›žç”ã—ã¾ã™ã€‚
simloopã®ä¸ã§path_to_texturesã®ãƒ‘スを変ãˆã¦ã‚‚テクスãƒãƒ£ã¯å¤‰ã‚りã¾ã›ã‚“。
dsStartGraphics()を使ã†å¿…è¦ãŒã‚りã¾ã™ã€‚ãŸã ã—ã€drawstuff.hã®95行目ã®dsSimulationLoop()ã®ä¸‹ã«ä»¥ä¸‹ã®ä¸€è¡Œã‚’è¿½åŠ ã—ã¦ã€ode-0.9ã®ãƒ•ォルダã§make,make installã—ç›´ã—ã¦ãã ã•ã„。ode-0.8ã ã¨ã‚¨ãƒ©ãƒ¼ãŒå‡ºã‚‹ã‚ˆã†ã§ã™ã€‚
DS_API void dsStartGraphics(int window_width, int window_height, struct dsFunctions *fn);
ãªãŠã€ã‚·ãƒŸãƒ¥ãƒ¬ãƒ¼ã‚·ãƒ§ãƒ³ä¸ã®è¤‡æ•°ã®ç‰©ä½“ã«é•ã£ãŸãƒ†ã‚¯ã‚¹ãƒãƒ£ã‚’割り当ã¦ã‚‹ãŸã‚ã«ã¯ã€dsStartGraphics()ã‚’å„物体をæç”»ã™ã‚‹å‰ã«ã€å„物体毎ã«å‘¼ã³å‡ºã•ãªã‘れã°ã„ã‘ãšã€æç”»é€Ÿåº¦ãŒé…ããªã‚Šã¾ã™ã€‚drawstuffã®ã‚½ãƒ¼ã‚¹ã‚³ãƒ¼ãƒ‰ã«æ‰‹ã‚’åŠ ãˆã‚‹ã‹ã€ä»–ã®ï¼“Dグラフィクスライブラリを使用ã™ã‚‹ã“ã¨ã‚’ãŠå‹§ã‚ã—ã¾ã™ã€‚
ãã‚‚ãã‚‚drawstuffã¯ãƒ†ã‚¹ãƒˆãƒ—ãƒã‚°ãƒ©ãƒ ã®è¡¨ç¤ºç”¨ãƒ©ã‚¤ãƒ–ラリãªã®ã§å‡ã£ãŸã“ã¨ã¯ã§ãã¾ã›ã‚“。ãã®ä»£ã‚りã«ã‚½ãƒ¼ã‚¹ã‚‚çŸãコードも複雑ã§ã¯ãªã„ã®ã§OpenGLã®å‹‰å¼·ã«ã‚‚ピッタリã§ã™ã€‚
以下㫒t'ã‚ー㨒u'ã‚ーを押ã™ã¨ãƒ†ã‚¯ã‚¹ãƒãƒ£ãŒåˆ‡ã‚Šæ›¿ã‚るサンプルプãƒã‚°ãƒ©ãƒ を紹介ã—ã¾ã™ã®ã§å‚考ã«ã—ã¦ãã ã•ã„。ã“ã“ã‹ã‚‰ãƒ€ã‚¦ãƒ³ãƒãƒ¼ãƒ‰å¯èƒ½ã§ã™ã€‚
[code]
// texture.cpp: テクスãƒãƒ£ã®å¤‰æ›´ by Kosei Demura (2007-10-25)
#include
#include
#ifdef dDOUBLE
#define dsDrawBox dsDrawBoxD
#define dsDrawSphere dsDrawSphereD
#define dsDrawCylinder dsDrawCylinderD
#define dsDrawCapsule dsDrawCapsuleD
#endif
static dWorldID world;
static dSpaceID space;
static dGeomID capsule;
static int texture_flag = 0;
dsFunctions fn;
static void simLoop(int pause)
{
const dReal *pos;
const dReal *R;
dReal r, l;
pos = dGeomGetPosition(capsule);
R = dGeomGetRotation(capsule);
if (texture_flag == 0) dsSetTexture(DS_NONE);
else dsSetTexture(DS_WOOD);
fn.path_to_textures = "./textures";
dsSetColor(1.2, 1.2, 1.2);
dGeomCapsuleGetParams(capsule, &r, &l);
dsDrawCapsule(pos, R, l, r);
}
void command(int cmd)
{
switch (cmd) {
case ‘t’:
fn.path_to_textures = "./textures";
dsStartGraphics(640,480,&fn);
texture_flag = 1;
break;
case ‘u’:
fn.path_to_textures = "../../drawstuff/textures";
dsStartGraphics(640,480,&fn);
texture_flag = 0;
break;
}
}
void start()
{
static float xyz[3] = { 3.0, 0.0, 1.0};
static float hpr[3] = {-180.0, 0.0, 0.0};
dsSetViewpoint(xyz, hpr);
dsSetSphereQuality(3);
}
void setDrawStuff()
{
fn.version = DS_VERSION;
fn.start = &start;
fn.step = &simLoop;
fn.command = &command;
fn.stop = NULL;
fn.path_to_textures = "../../drawstuff/textures";
}
// カプセルジオメトリã®ç”Ÿæˆ
void makeCapsule()
{
dReal r = 0.1, l = 1.0;
capsule = dCreateCapsule(space, r, l); // 直方体ジオメトリã®ç”Ÿæˆ
dGeomSetPosition(capsule, 0, 0, 1); // ä½ç½®ã®è¨å®š
}
int main(int argc, char *argv[])
{
setDrawStuff();
world = dWorldCreate();
space = dHashSpaceCreate(0);
makeCapsule();
dsSimulationLoop(argc,argv,640,480,&fn);
dWorldDestroy(world);
return 0;
}
[/code]