util/viewer/GLscene.cpp
Go to the documentation of this file.
1 #include <cstdio>
2 #include <iostream>
3 #include <fstream>
4 #include <sys/time.h>
5 #ifdef __APPLE__
6 #include <OpenGL/gl.h>
7 #else
8 #include <GL/gl.h>
9 #endif
10 #include "hrpsys/util/GLcamera.h"
11 #include "hrpsys/util/GLlink.h"
12 #include "hrpsys/util/GLbody.h"
13 #include "hrpsys/util/LogManager.h"
14 #include "GLscene.h"
15 
16 using namespace OpenHRP;
17 using namespace hrp;
18 
20 {
21  if (m_log->index()<0) return;
22 
25  OpenHRP::WorldState &state = lm->state();
26  for (unsigned int i=0; i<state.characterPositions.length(); i++){
27  const CharacterPosition& cpos = state.characterPositions[i];
28  std::string cname(cpos.characterName);
29  GLbody *glbody = dynamic_cast<GLbody *>(body(cname).get());
30  if (!glbody) {
31  //std::cerr << "can't find a body named " << cname << std::endl;
32  continue;
33  }
34  for (unsigned int j=0; j<cpos.linkPositions.length(); j++){
35  const LinkPosition &lp = cpos.linkPositions[j];
36  double T[] = {lp.R[0], lp.R[3], lp.R[6],0,
37  lp.R[1], lp.R[4], lp.R[7],0,
38  lp.R[2], lp.R[5], lp.R[8],0,
39  lp.p[0], lp.p[1], lp.p[2],1};
40 #if 0
41  for (int i=0; i<4; i++){
42  for (int j=0; j<4; j++){
43  printf("%6.3f ", T[i*4+j]);
44  }
45  printf("\n");
46  }
47  printf("\n");
48 #endif
49  ((GLlink *)glbody->link(j))->setAbsTransform(T);
50  }
51  }
52 }
53 
55 {
58  OpenHRP::WorldState state;
59  if (!lm->state(state)) return;
60 
61  glBegin(GL_LINES);
62  glColor3f(1,0,0);
63  double e[3];
64  const CollisionSequence &cs = state.collisions;
65  for (unsigned int i=0; i<cs.length(); i++){
66  const CollisionPointSequence& cps = cs[i].points;
67  for (unsigned int j=0; j<cps.length(); j++){
68  glVertex3dv(cps[j].position);
69  for (int k=0; k<3; k++){
70  e[k] = cps[j].position[k] + cps[j].normal[k]*(cps[j].idepth*10+0.1);
71  }
72  glVertex3dv(e);
73  }
74  }
75  glEnd();
76 }
77 
79  : GLsceneBase(i_log)
80 {
81 }
82 
84 {
85 }
GLscene()
Definition: GLmodel.cpp:347
state
void drawAdditionalLines()
void updateScene()
png_uint_32 i
Definition: GLbody.h:11
def j(str, encoding="cp932")
Link * link(int index) const
T & state()
Definition: LogManager.h:140
~GLscene()
Definition: GLmodel.cpp:357


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Thu May 6 2021 02:41:50