4D星宇

c++

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  57 随笔 :: 0 文章 :: 39 评论 :: 0 Trackbacks

该项目使用INI来实现数据的读取。
比如:
1.节点读取
INI部分:
外观
Look
 Body
  model=impreza.3ds
  scale=1 1 1
 Wheels
  model=wheel.3ds
  scale=1 1 1
声音
Sound
 Engine
  wave=206_engine.wav
  pitch_low=0.2
  pitch_high=1.5
程序部分:
//load car

 body.node=loadModel(cfg, "Look/Body/", device, sm, driver);

 body.node_debug=sm->addCubeSceneNode(1, 0, -1, core::vector3df(0, 0, 0), core::vector3df(0, 0, 0),
  cfg.Getval_vector("Body/Chassis/1/scale", core::vector3df(1, 1, 1))
  );
 body.node_debug->setMaterialTexture(0, driver->getTexture("data/misc/checked.jpg"));
2.车轮的属性
 Wheel #default
  damp=30000
  spring=50000
  radius=0.38
  weight=20
  width=0.10 #not yet used if user specifies wheel model
  brakes=0 # 0.0 - 1.0
 Wheel_1 #fl
  pos=1.39 -0.145 0.823
  attr=STEER
  brakes=0.8
  rotation_z=1.5707963 #used just by client part
 Wheel_2 #fr
  pos=1.39 -0.145 -0.823
  attr=STEER
  brakes=0.8
  rotation_z=4.7123889
 Wheel_3 #rl
  pos=-1.350 -0.15 0.823
  attr=STRAIGHT|THURST
  brakes=0.2
  rotation_z=1.5707963
 Wheel_4 #rr
  pos=-1.350 -0.15 -0.823
  attr=STRAIGHT|THURST
  brakes=0.2
  rotation_z=4.7123889
for (int i=0; ; i++) {
  char buf2[128];

  sprintf(buf2, "Body/Wheel_%d/", i+1);
  buf=buf2;

  if (!cfg.Getval_exists(buf+"attr")) break;

  double radius=cfg.Getval_double((string)buf+"radius", cfg.Getval_double("Body/Wheel/radius", 1));
  double width=cfg.Getval_double((string)buf+"width", cfg.Getval_double("Body/Wheel/width", 1));

  scene::ISceneNode* node=loadModel(cfg, "Look/Wheels/", device, sm, driver);
  CModelAttr wm;

  scene::IMesh* cm=CreateCylinder(25, 2, 1);
  scene::ISceneNode* node_debug=sm->addMeshSceneNode(cm);
  node_debug->setScale(core::vector3df((f32)(radius), (f32)width, (f32)(radius)));
  node_debug->setMaterialTexture(0, driver->getTexture("data/misc/checked.jpg"));
  node_debug->getMaterial(0).EmissiveColor.set(255,255,255,255);

  wm.arot=core::vector3df((f32)cfg.Getval_double(buf+"rotation_x", 0),
    (f32)cfg.Getval_double(buf+"rotation_y", 0),
    (f32)cfg.Getval_double(buf+"rotation_z", 0));
  wm.node=node;
  wm.node_debug=node_debug;

  wheels.push_back(wm);
 }
3.声音---车开动时的轰鸣声
 //load sounds
 try {
  snd_engine = new openalpp::Source((ALbyte*)("data/cars/"+profile+"/"+cfg.Getval_str("Sound/Engine/wave")).c_str());
  if (!snd_engine.valid())
   DBGCOUT("ALUT", "Coulnd't load file", ("data/cars/"+profile+"/"+cfg.Getval_str("Sound/Engine/wave")).c_str());
  else {
   snd_engine->setGain(1);
   snd_engine->setPosition(0.0,0.0,0.0);
   snd_engine->setLooping(true);
  }
  snd_engine_pitch_low=cfg.Getval_double("Sound/Engine/pitch_low");
  snd_engine_pitch_high=cfg.Getval_double("Sound/Engine/pitch_high");
 } catch(openalpp::Error e) {
  std::cerr << e << "\n";
 }

posted on 2008-05-08 10:31 bloodbao 阅读(194) 评论(0)  编辑 收藏 引用 所属分类: c++

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理