17 axis[0] = i_si.rotation[0];
18 axis[1] = i_si.rotation[1];
19 axis[2] = i_si.rotation[2];
23 m_trans[ 0]=
R(0,0);m_trans[ 1]=
R(1,0);m_trans[ 2]=
R(2,0);m_trans[3]=0;
24 m_trans[ 4]=
R(0,1);m_trans[ 5]=
R(1,1);m_trans[ 6]=
R(2,1);m_trans[7]=0;
25 m_trans[ 8]=
R(0,2);m_trans[ 9]=
R(1,2);m_trans[10]=
R(2,2);m_trans[11]=0;
26 m_trans[12]=i_si.translation[0];m_trans[13]=i_si.translation[1];
27 m_trans[14]=i_si.translation[2];m_trans[15]=1;
29 m_near = i_si.specValues[0];
30 m_far = i_si.specValues[1];
31 m_fovy = i_si.specValues[2];
32 m_width = i_si.specValues[4];
33 m_height = i_si.specValues[5];
36 GLcamera::GLcamera(
int i_width,
int i_height,
double i_near,
double i_far,
double i_fovy) : m_near(i_near), m_far(i_far), m_fovy(i_fovy), m_width(i_width), m_height(i_height)
50 memcpy(o_trans,
m_trans,
sizeof(
double)*16);
58 glMatrixMode(GL_PROJECTION);
71 memcpy(
m_trans, i_trans,
sizeof(
double)*16);
75 memcpy(o_trans,
m_absTrans,
sizeof(
double)*16);
80 glReadPixels(0, i_row,
width(), 1, GL_DEPTH_COMPONENT, GL_FLOAT, o_depth);
84 GLlink::GLlink(
const LinkInfo &i_li, BodyInfo_var i_binfo) : m_parent(NULL), m_jointId(i_li.jointId){
88 for (
int i=0;
i<3;
i++){
89 m_axis[
i] = i_li.jointAxis[
i];
90 axis[
i] = i_li.rotation[
i];
103 m_list = glGenLists(1);
107 glNewList(m_list, GL_COMPILE);
109 ShapeInfoSequence_var sis = i_binfo->shapes();
110 AppearanceInfoSequence_var ais = i_binfo->appearances();
111 MaterialInfoSequence_var mis = i_binfo->materials();
112 const TransformedShapeIndexSequence& tsis = i_li.shapeIndices;
113 for (
unsigned int l=0;
l<tsis.length();
l++){
114 const TransformedShapeIndex &tsi = tsis[
l];
116 for (
int i=0;
i<3;
i++){
117 for (
int j=0;
j<4;
j++){
118 tform[
j*4+
i] = tsi.transformMatrix[
i*4+
j];
121 tform[3] = tform[7] = tform[11] = 0.0; tform[15] = 1.0;
124 glMultMatrixd(tform);
127 glBegin(GL_TRIANGLES);
128 short index = tsi.shapeIndex;
129 ShapeInfo& si = sis[index];
130 const float *vertices = si.vertices.get_buffer();
131 const LongSequence& triangles = si.triangles;
132 const AppearanceInfo& ai = ais[si.appearanceIndex];
133 const float *normals = ai.normals.get_buffer();
135 const LongSequence& normalIndices = ai.normalIndices;
137 const int numTriangles = triangles.length() / 3;
139 if (ai.materialIndex >= 0){
140 const MaterialInfo& mi = mis[ai.materialIndex];
141 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE,
144 std::cout <<
"no material" << std::endl;
146 for(
int j=0;
j < numTriangles; ++
j){
147 if (!ai.normalPerVertex){
149 if (normalIndices.length() == 0){
152 p = normalIndices[
j]*3;
154 glNormal3fv(normals+p);
156 for(
int k=0; k < 3; ++k){
157 if (ai.normalPerVertex){
158 int p = normalIndices[
j*3+k]*3;
159 glNormal3fv(normals+p);
161 long orgVertexIndex = si.triangles[
j * 3 + k];
162 int p = orgVertexIndex * 3;
163 glVertex3fv(vertices+p);
172 const SensorInfoSequence& sensors = i_li.sensors;
173 for (
unsigned int i=0;
i<sensors.length();
i++){
174 const SensorInfo& si = sensors[
i];
175 std::string
type(si.type);
176 if (type ==
"Vision"){
178 m_cameras.push_back(
new GLcamera(si,
this));
187 glMultMatrixd(m_T_j);
189 for (
unsigned int i=0;
i<m_children.size();
i++){
190 m_children[
i]->draw();
201 m_children.push_back(i_child);
207 m_T_j[ 0]=
R(0,0);m_T_j[ 1]=
R(1,0);m_T_j[ 2]=
R(2,0);m_T_j[3]=0;
208 m_T_j[ 4]=
R(0,1);m_T_j[ 5]=
R(1,1);m_T_j[ 6]=
R(2,1);m_T_j[7]=0;
209 m_T_j[ 8]=
R(0,2);m_T_j[ 9]=
R(1,2);m_T_j[10]=
R(2,2);m_T_j[11]=0;
210 m_T_j[12]=0; m_T_j[13]=0; m_T_j[14]=0; m_T_j[15]=1;
216 memcpy(
m_trans, i_trans,
sizeof(
double)*16);
224 std::string
name(i_name);
225 for (
unsigned int i=0;
i<m_cameras.size();
i++){
226 if (m_cameras[
i]->
name() ==
name)
return m_cameras[
i];
233 double trans1[16], trans2[16];
235 m_parent->computeAbsTransform(trans2);
238 memcpy(o_trans,
m_trans,
sizeof(
double)*16);
243 LinkInfoSequence_var lis = i_binfo->links();
245 for (
unsigned int i=0;
i<lis->length();
i++){
246 m_links.push_back(
new GLlink(lis[
i], i_binfo));
249 for (
unsigned int i=0;
i<m_links.size();
i++){
250 const LinkInfo &li = lis[
i];
251 if (li.parentIndex < 0) m_root = m_links[
i];
252 for (
unsigned int j=0;
j<li.childIndices.length();
j++){
253 m_links[
i]->addChild(m_links[li.childIndices[
j]]);
260 for (
unsigned int i=0;
i<m_links.size();
i++){
268 tform[ 0]=
R(0,0);tform[ 1]=
R(1,0);tform[ 2]=
R(2,0);tform[ 3]=0;
269 tform[ 4]=
R(0,1);tform[ 5]=
R(1,1);tform[ 6]=
R(2,1);tform[ 7]=0;
270 tform[ 8]=
R(0,2);tform[ 9]=
R(1,2);tform[10]=
R(2,2);tform[11]=0;
271 tform[12]=i_pos[0];tform[13]=i_pos[1];tform[14]=i_pos[2];tform[15]=1;
272 m_root->setTransform(tform);
273 for (
unsigned int i=0;
i<m_links.size();
i++){
274 int id = m_links[
i]->jointId();
276 m_links[
i]->setQ(i_angles[
id]);
286 for (
unsigned int i=0;
i<m_links.size();
i++){
287 GLcamera *camera = m_links[
i]->findCamera(i_name);
288 if (camera)
return camera;
294 m_bodies.push_back(i_body);
300 struct timeval tv1, tv2;
303 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
305 glMatrixMode(GL_MODELVIEW);
307 for (
unsigned int i=0;
i<m_bodies.size();
i++){
311 if (swap) glfwSwapBuffers();
313 gettimeofday(&tv2, NULL);
319 void mulTrans(
const double i_m1[16],
const double i_m2[16],
double o_m[16])
321 for (
int i=0;
i<4;
i++){
322 for (
int j=0;
j<4;
j++){
324 for (
int k=0; k<4; k++){
325 v += i_m1[
i*4+k]*i_m2[
j+k*4];
339 for (
int i=0;
i<4;
i++){
340 for (
int j=0;
j<4;
j++){
341 printf(
"%6.3f ", mat[
j*4+
i]);
350 double T[] = {0,1,0,0,
370 GLfloat light0pos[] = { 0.0, 4.0, 6.0, 1.0 };
371 GLfloat light1pos[] = { 6.0, 4.0, 0.0, 1.0 };
372 GLfloat
white[] = { 0.6, 0.6, 0.6, 1.0 };
374 glClearColor(0, 0, 0, 1.0);
375 glEnable(GL_DEPTH_TEST);
377 glEnable(GL_CULL_FACE);
380 glEnable(GL_LIGHTING);
383 glLightfv(GL_LIGHT0, GL_DIFFUSE, white);
384 glLightfv(GL_LIGHT0, GL_SPECULAR, white);
385 glLightfv(GL_LIGHT1, GL_DIFFUSE, white);
386 glLightfv(GL_LIGHT1, GL_SPECULAR, white);
387 glLightfv(GL_LIGHT0, GL_POSITION, light0pos);
388 glLightfv(GL_LIGHT1, GL_POSITION, light1pos);
394 glfwGetWindowSize(&w,&h);
395 unsigned char *
buffer =
new unsigned char[w*h*3];
398 std::ofstream ofs(i_fname, std::ios::out | std::ios::trunc | std::ios::binary );
401 ofs <<
"P6" << std::endl << buf << std::endl <<
"255" << std::endl;
402 for (
int i=0;
i<
h;
i++){
403 ofs.write((
char *)(buffer+
i*w*3), w*3);
411 glfwGetWindowSize(&w,&h);
412 glReadBuffer(GL_BACK);
413 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
414 for (
int i=0;
i<
h;
i++){
415 glReadPixels(0,(h-1-
i),w,1,GL_RGB,GL_UNSIGNED_BYTE,
422 if (!i_camera)
return;
std::vector< GLbody * > m_bodies
GLcamera * findCamera(const char *i_name)
double * getAbsTransform()
void save(const char *i_fname)
png_infop png_charp png_int_32 png_int_32 int * type
void addBody(GLbody *i_body)
png_infop png_charpp name
void printMatrix(double mat[16])
const std::string & name() const
OpenHRP::matrix33 Matrix33
png_infop png_bytep * trans
Matrix33 rotFromRpy(const Vector3 &rpy)
static GLscene * getInstance()
GLbody * body(unsigned int i_rank)
int gettimeofday(struct timeval *tv, struct timezone *tz)
GLcamera * m_default_camera
def j(str, encoding="cp932")
unsigned int numBodies() const
HRP_UTIL_EXPORT void calcRodrigues(Matrix44 &out_R, const Vector3 &axis, double q)
GLcamera * findCamera(const char *i_name)
void setTransform(double i_trans[16])
void setTransform(double i_trans[16])
GLcamera(int i_width, int i_height, double i_near, double i_far, double i_fovy, GLlink *i_link=NULL, int i_id=-1)
void getDepthOfLine(int i_row, float *o_depth)
void setPosture(const double *i_angles)
std::string sprintf(char const *__restrict fmt,...)
void setCamera(GLcamera *i_camera)
void mulTrans(const double i_m1[16], const double i_m2[16], double o_m[16])
png_infop png_bytep buffer
void computeAbsTransform()
void computeAbsTransform(double o_trans[16])
void addChild(GLlink *i_child)
void setParent(GLlink *i_parent)