Add spaces around comparison operators in render/ and ui/ source files.

PiperOrigin-RevId: 536001297
Change-Id: Ia0d97bf9f886aea03b8363e4d97e18301520909f
This commit is contained in:
Yuval Tassa
2023-05-28 07:04:06 -07:00
committed by Copybara-Service
parent 455b1cd2e2
commit d1c6561f1c
5 changed files with 509 additions and 500 deletions
+90 -90
View File
@@ -62,7 +62,7 @@ static void listAllocate(GLuint* base, GLsizei* range, GLsizei newrange) {
*range = newrange; *range = newrange;
if (newrange) { if (newrange) {
*base = glGenLists(*range); *base = glGenLists(*range);
if (*base<=0) { if (*base <= 0) {
mju_error("Could not allocate display lists"); mju_error("Could not allocate display lists");
} }
} }
@@ -79,8 +79,8 @@ static void makePlane(const mjModel* m, mjrContext* con) {
// count planes // count planes
nplane = 0; nplane = 0;
for (int i=0; i<m->ngeom; i++) { for (int i=0; i < m->ngeom; i++) {
if (m->geom_type[i]==mjGEOM_PLANE) { if (m->geom_type[i] == mjGEOM_PLANE) {
nplane++; nplane++;
} }
} }
@@ -93,8 +93,8 @@ static void makePlane(const mjModel* m, mjrContext* con) {
glBegin(GL_QUADS); glBegin(GL_QUADS);
glNormal3d(0, 0, 1); glNormal3d(0, 0, 1);
double d = 2.0/m->vis.quality.numquads; double d = 2.0/m->vis.quality.numquads;
for (int x=0; x<m->vis.quality.numquads; x++) { for (int x=0; x < m->vis.quality.numquads; x++) {
for (int y=0; y<m->vis.quality.numquads; y++) { for (int y=0; y < m->vis.quality.numquads; y++) {
glVertex3d(d*(x+0)-1, d*(y+0)-1, 0); glVertex3d(d*(x+0)-1, d*(y+0)-1, 0);
glVertex3d(d*(x+1)-1, d*(y+0)-1, 0); glVertex3d(d*(x+1)-1, d*(y+0)-1, 0);
glVertex3d(d*(x+1)-1, d*(y+1)-1, 0); glVertex3d(d*(x+1)-1, d*(y+1)-1, 0);
@@ -106,16 +106,16 @@ static void makePlane(const mjModel* m, mjrContext* con) {
// construct planes, offset by 1 // construct planes, offset by 1
nplane = 0; nplane = 0;
for (int i=0; i<m->ngeom; i++) { for (int i=0; i < m->ngeom; i++) {
if (m->geom_type[i]==mjGEOM_PLANE) { if (m->geom_type[i] == mjGEOM_PLANE) {
// get sizes // get sizes
sz[0] = m->geom_size[3*i]; sz[0] = m->geom_size[3*i];
sz[1] = m->geom_size[3*i+1]; sz[1] = m->geom_size[3*i+1];
// loop over (x, y) // loop over (x, y)
for (int k=0; k<2; k++) { for (int k=0; k < 2; k++) {
// regular dimension // regular dimension
if (sz[k]>0) { if (sz[k] > 0) {
// limit number of grid lines, leave room for padding // limit number of grid lines, leave room for padding
sz2 = mju_max(m->geom_size[3*i+2], sz[k]/(mjMAXPLANEGRID-2)); sz2 = mju_max(m->geom_size[3*i+2], sz[k]/(mjMAXPLANEGRID-2));
@@ -128,14 +128,14 @@ static void makePlane(const mjModel* m, mjrContext* con) {
nn[k] += 2; nn[k] += 2;
// make grid // make grid
for (int x=0; x<nn[k]; x++) { for (int x=0; x < nn[k]; x++) {
// compute left, right (which is bottom, top for y) // compute left, right (which is bottom, top for y)
if (x==0) { if (x == 0) {
left = -sz[k]; left = -sz[k];
right = left + pad; right = left + pad;
} else { } else {
left = -sz[k] + pad + (x-1)*sz2*2; left = -sz[k] + pad + (x-1)*sz2*2;
right = left + (x==nn[k]-1 ? pad : sz2*2); right = left + (x == nn[k]-1 ? pad : sz2*2);
} }
// record // record
@@ -149,7 +149,7 @@ static void makePlane(const mjModel* m, mjrContext* con) {
// get size increment // get size increment
mjtNum sX; mjtNum sX;
int matid = m->geom_matid[i]; int matid = m->geom_matid[i];
if (matid>=0 && m->mat_texrepeat[2*matid+k]>0) { if (matid >= 0 && m->mat_texrepeat[2*matid+k] > 0) {
sX = 2/m->mat_texrepeat[2*matid+k]; sX = 2/m->mat_texrepeat[2*matid+k];
} else { } else {
sX = 2.1*zfar/(mjMAXPLANEGRID-2); sX = 2.1*zfar/(mjMAXPLANEGRID-2);
@@ -157,7 +157,7 @@ static void makePlane(const mjModel* m, mjrContext* con) {
// create grid, larger than skybox // create grid, larger than skybox
d = (2.1*zfar + 2*sX)/mjMAXPLANEGRID; d = (2.1*zfar + 2*sX)/mjMAXPLANEGRID;
for (int x=0; x<=mjMAXPLANEGRID; x++) { for (int x=0; x <= mjMAXPLANEGRID; x++) {
grid[k][x] = d*x - d*(mjMAXPLANEGRID/2); grid[k][x] = d*x - d*(mjMAXPLANEGRID/2);
} }
@@ -172,8 +172,8 @@ static void makePlane(const mjModel* m, mjrContext* con) {
glNormal3d(0, 0, 1); glNormal3d(0, 0, 1);
// make grid // make grid
for (int x=0; x<nn[0]; x++) { for (int x=0; x < nn[0]; x++) {
for (int y=0; y<nn[1]; y++) { for (int y=0; y < nn[1]; y++) {
glVertex3d(grid[0][x+0], grid[1][y+0], 0); glVertex3d(grid[0][x+0], grid[1][y+0], 0);
glVertex3d(grid[0][x+1], grid[1][y+0], 0); glVertex3d(grid[0][x+1], grid[1][y+0], 0);
glVertex3d(grid[0][x+1], grid[1][y+1], 0); glVertex3d(grid[0][x+1], grid[1][y+1], 0);
@@ -199,7 +199,7 @@ static void makeMesh(const mjModel* m, mjrContext* con) {
listAllocate(&con->baseMesh, &con->rangeMesh, 2*m->nmesh); listAllocate(&con->baseMesh, &con->rangeMesh, 2*m->nmesh);
// process meshes // process meshes
for (int i=0; i<m->nmesh; i++) { for (int i=0; i < m->nmesh; i++) {
mjr_uploadMesh(m, con, i); mjr_uploadMesh(m, con, i);
} }
} }
@@ -212,7 +212,7 @@ void mjr_uploadMesh(const mjModel* m, const mjrContext* con, int meshid) {
float normal[3], *v1, *v2, *v3, *n1, *n2, *n3, *t1, *t2, *t3; float normal[3], *v1, *v2, *v3, *n1, *n2, *n3, *t1, *t2, *t3;
// check index // check index
if (meshid<0 || meshid>=m->nmesh) { if (meshid < 0 || meshid >= m->nmesh) {
mju_error("Invalid mesh index %d", meshid); mju_error("Invalid mesh index %d", meshid);
} }
@@ -241,7 +241,7 @@ void mjr_uploadMesh(const mjModel* m, const mjrContext* con, int meshid) {
n3 = m->mesh_normal + 3*(m->mesh_facenormal[3*face+2] + normaladr); n3 = m->mesh_normal + 3*(m->mesh_facenormal[3*face+2] + normaladr);
// compute texcoord addresses // compute texcoord addresses
if (texcoordadr>=0) { if (texcoordadr >= 0) {
t1 = m->mesh_texcoord + 2*(m->mesh_facetexcoord[3*face] + texcoordadr); t1 = m->mesh_texcoord + 2*(m->mesh_facetexcoord[3*face] + texcoordadr);
t2 = m->mesh_texcoord + 2*(m->mesh_facetexcoord[3*face+1] + texcoordadr); t2 = m->mesh_texcoord + 2*(m->mesh_facetexcoord[3*face+1] + texcoordadr);
t3 = m->mesh_texcoord + 2*(m->mesh_facetexcoord[3*face+2] + texcoordadr); t3 = m->mesh_texcoord + 2*(m->mesh_facetexcoord[3*face+2] + texcoordadr);
@@ -296,14 +296,14 @@ void mjr_uploadMesh(const mjModel* m, const mjrContext* con, int meshid) {
glEndList(); glEndList();
// render convex hull if present // render convex hull if present
if (m->mesh_graphadr[meshid]>=0) { if (m->mesh_graphadr[meshid] >= 0) {
// get sizes of convex hull // get sizes of convex hull
numvert = m->mesh_graph[m->mesh_graphadr[meshid]]; numvert = m->mesh_graph[m->mesh_graphadr[meshid]];
numface = m->mesh_graph[m->mesh_graphadr[meshid]+1]; numface = m->mesh_graph[m->mesh_graphadr[meshid]+1];
glNewList(con->baseMesh + 2*meshid+1, GL_COMPILE); glNewList(con->baseMesh + 2*meshid+1, GL_COMPILE);
glBegin(GL_TRIANGLES); glBegin(GL_TRIANGLES);
for (int face=0; face<numface; face++) { for (int face=0; face < numface; face++) {
// face address in graph // face address in graph
int j = m->mesh_graphadr[meshid] + 2 + 3*numvert + 3*numface + 3*face; int j = m->mesh_graphadr[meshid] + 2 + 3*numvert + 3*numface + 3*face;
@@ -313,7 +313,7 @@ void mjr_uploadMesh(const mjModel* m, const mjrContext* con, int meshid) {
v3 = m->mesh_vert + 3*(m->mesh_graph[j+2] + vertadr); v3 = m->mesh_vert + 3*(m->mesh_graph[j+2] + vertadr);
// compute texcoord addresses // compute texcoord addresses
if (texcoordadr>=0) { if (texcoordadr >= 0) {
t1 = m->mesh_texcoord + 2*(m->mesh_graph[j] + texcoordadr); t1 = m->mesh_texcoord + 2*(m->mesh_graph[j] + texcoordadr);
t2 = m->mesh_texcoord + 2*(m->mesh_graph[j+1] + texcoordadr); t2 = m->mesh_texcoord + 2*(m->mesh_graph[j+1] + texcoordadr);
t3 = m->mesh_texcoord + 2*(m->mesh_graph[j+2] + texcoordadr); t3 = m->mesh_texcoord + 2*(m->mesh_graph[j+2] + texcoordadr);
@@ -364,7 +364,7 @@ static void addVert(float x, float y, float z, float sclz, struct vertbuf* buf)
buf->nvert++; buf->nvert++;
// triangle ready // triangle ready
if (buf->nvert>=3) { if (buf->nvert >= 3) {
// compensate for alternating orientation // compensate for alternating orientation
if (buf->nvert%2) { if (buf->nvert%2) {
mjr_makeNormal(normal, buf->vert1, buf->vert2, buf->vert3); mjr_makeNormal(normal, buf->vert1, buf->vert2, buf->vert3);
@@ -390,7 +390,7 @@ static void makeHField(const mjModel* m, mjrContext* con) {
listAllocate(&con->baseHField, &con->rangeHField, m->nhfield); listAllocate(&con->baseHField, &con->rangeHField, m->nhfield);
// uploaed all heightfields // uploaed all heightfields
for (int i=0; i<m->nhfield; i++) { for (int i=0; i < m->nhfield; i++) {
mjr_uploadHField(m, con, i); mjr_uploadHField(m, con, i);
} }
} }
@@ -405,7 +405,7 @@ void mjr_uploadHField(const mjModel* m, const mjrContext* con, int hfieldid) {
float* data; float* data;
// check index // check index
if (hfieldid<0 || hfieldid>=m->nhfield) { if (hfieldid < 0 || hfieldid >= m->nhfield) {
mju_error("Invalid height field index %d", hfieldid); mju_error("Invalid height field index %d", hfieldid);
} }
@@ -421,7 +421,7 @@ void mjr_uploadHField(const mjModel* m, const mjrContext* con, int hfieldid) {
height = 0.5f * (m->hfield_nrow[hfieldid]-1); height = 0.5f * (m->hfield_nrow[hfieldid]-1);
// convert size to float // convert size to float
for (int r=0; r<4; r++) { for (int r=0; r < 4; r++) {
sz[r] = (float)m->hfield_size[4*hfieldid+r]; sz[r] = (float)m->hfield_size[4*hfieldid+r];
} }
@@ -429,9 +429,9 @@ void mjr_uploadHField(const mjModel* m, const mjrContext* con, int hfieldid) {
glBegin(GL_TRIANGLES); glBegin(GL_TRIANGLES);
int nr = m->hfield_nrow[hfieldid]; int nr = m->hfield_nrow[hfieldid];
int nc = m->hfield_ncol[hfieldid]; int nc = m->hfield_ncol[hfieldid];
for (int r=0; r<nr-1; r++) { for (int r=0; r < nr-1; r++) {
buf.nvert = 0; buf.nvert = 0;
for (int c=0; c<nc; c++) { for (int c=0; c < nc; c++) {
addVert(sz[0]*(c/width-1.0f), sz[1]*((r+d1)/height-1.0f), data[(r+d1)*nc+c], sz[2], &buf); addVert(sz[0]*(c/width-1.0f), sz[1]*((r+d1)/height-1.0f), data[(r+d1)*nc+c], sz[2], &buf);
addVert(sz[0]*(c/width-1.0f), sz[1]*((r+d2)/height-1.0f), data[(r+d2)*nc+c], sz[2], &buf); addVert(sz[0]*(c/width-1.0f), sz[1]*((r+d2)/height-1.0f), data[(r+d2)*nc+c], sz[2], &buf);
} }
@@ -440,7 +440,7 @@ void mjr_uploadHField(const mjModel* m, const mjrContext* con, int hfieldid) {
// render sides as quads // render sides as quads
glBegin(GL_QUADS); glBegin(GL_QUADS);
for (int r=0; r<nr-1; r++) { for (int r=0; r < nr-1; r++) {
// left // left
glNormal3f(-1, 0, 0); glNormal3f(-1, 0, 0);
glVertex3f(-sz[0], sz[1]*((r+1)/height-1.0f), -sz[3]); glVertex3f(-sz[0], sz[1]*((r+1)/height-1.0f), -sz[3]);
@@ -456,7 +456,7 @@ void mjr_uploadHField(const mjModel* m, const mjrContext* con, int hfieldid) {
glVertex3f(+sz[0], sz[1]*((r+0)/height-1.0f), data[(r+0)*nc + nc-1]*sz[2]); glVertex3f(+sz[0], sz[1]*((r+0)/height-1.0f), data[(r+0)*nc + nc-1]*sz[2]);
} }
for (int c=0; c<nc-1; c++) { for (int c=0; c < nc-1; c++) {
// front // front
glNormal3f(0, -1, 0); glNormal3f(0, -1, 0);
glVertex3f(sz[0]*((c+0)/width-1.0f), -sz[1], -sz[3]); glVertex3f(sz[0]*((c+0)/width-1.0f), -sz[1], -sz[3]);
@@ -478,8 +478,8 @@ void mjr_uploadHField(const mjModel* m, const mjrContext* con, int hfieldid) {
// bottom // bottom
glNormal3f(0, 0, -1); glNormal3f(0, 0, -1);
for (int r=0; r<m->vis.quality.numquads; r++) { for (int r=0; r < m->vis.quality.numquads; r++) {
for (int c=0; c<m->vis.quality.numquads; c++) { for (int c=0; c < m->vis.quality.numquads; c++) {
glVertex3f(sz[0]*((c+0)/width-1.0f), sz[1]*((r+0)/height-1.0f), -sz[3]); glVertex3f(sz[0]*((c+0)/width-1.0f), sz[1]*((r+0)/height-1.0f), -sz[3]);
glVertex3f(sz[0]*((c+0)/width-1.0f), sz[1]*((r+1)/height-1.0f), -sz[3]); glVertex3f(sz[0]*((c+0)/width-1.0f), sz[1]*((r+1)/height-1.0f), -sz[3]);
glVertex3f(sz[0]*((c+1)/width-1.0f), sz[1]*((r+1)/height-1.0f), -sz[3]); glVertex3f(sz[0]*((c+1)/width-1.0f), sz[1]*((r+1)/height-1.0f), -sz[3]);
@@ -516,7 +516,7 @@ static void halfSphere(int sign, int nSlice, int nStack) {
// pole: use triangles // pole: use triangles
glBegin(GL_TRIANGLES); glBegin(GL_TRIANGLES);
el1 = (mjPI/2.0f * sign * (nStack-1)) / (float)nStack; el1 = (mjPI/2.0f * sign * (nStack-1)) / (float)nStack;
for (int j=0; j<nSlice; j++) { for (int j=0; j < nSlice; j++) {
az1 = (2.0f*mjPI * (j+0.0f)) / (float)nSlice; az1 = (2.0f*mjPI * (j+0.0f)) / (float)nSlice;
az2 = (2.0f*mjPI * (j+1.0f)) / (float)nSlice; az2 = (2.0f*mjPI * (j+1.0f)) / (float)nSlice;
@@ -529,7 +529,7 @@ static void halfSphere(int sign, int nSlice, int nStack) {
n3[2] = sign; n3[2] = sign;
// make triangle // make triangle
if (sign>0) { if (sign > 0) {
glNormal3fv(n1); glNormal3fv(n1);
glVertex3fv(v1); glVertex3fv(v1);
glNormal3fv(n2); glNormal3fv(n2);
@@ -549,11 +549,11 @@ static void halfSphere(int sign, int nSlice, int nStack) {
// the rest: use quads // the rest: use quads
glBegin(GL_QUADS); glBegin(GL_QUADS);
for (int i=0; i<nStack-1; i++) { for (int i=0; i < nStack-1; i++) {
el1 = (mjPI/2.0f * sign * (i+0)) / (float)nStack; el1 = (mjPI/2.0f * sign * (i+0)) / (float)nStack;
el2 = (mjPI/2.0f * sign * (i+1)) / (float)nStack; el2 = (mjPI/2.0f * sign * (i+1)) / (float)nStack;
for (int j=0; j<nSlice; j++) { for (int j=0; j < nSlice; j++) {
az1 = (2.0f*mjPI * (j+0)) / (float)nSlice; az1 = (2.0f*mjPI * (j+0)) / (float)nSlice;
az2 = (2.0f*mjPI * (j+1)) / (float)nSlice; az2 = (2.0f*mjPI * (j+1)) / (float)nSlice;
@@ -564,7 +564,7 @@ static void halfSphere(int sign, int nSlice, int nStack) {
setVertexSphere(v4, n4, az1, el2, sign); setVertexSphere(v4, n4, az1, el2, sign);
// make quad // make quad
if (sign>0) { if (sign > 0) {
glNormal3fv(n1); glNormal3fv(n1);
glVertex3fv(v1); glVertex3fv(v1);
glNormal3fv(n2); glNormal3fv(n2);
@@ -598,9 +598,9 @@ static void sphere(int nSlice, int nStack) {
// poles: use triangles // poles: use triangles
glBegin(GL_TRIANGLES); glBegin(GL_TRIANGLES);
for (int sign=-1; sign<=1; sign+=2) { for (int sign=-1; sign <= 1; sign+=2) {
el1 = (0.5*mjPI * sign * (nStack/2-1)) / (float)(nStack/2); el1 = (0.5*mjPI * sign * (nStack/2-1)) / (float)(nStack/2);
for (int j=0; j<nSlice; j++) { for (int j=0; j < nSlice; j++) {
az1 = (2.0f*mjPI * (j+0.0f)) / (float)nSlice; az1 = (2.0f*mjPI * (j+0.0f)) / (float)nSlice;
az2 = (2.0f*mjPI * (j+1.0f)) / (float)nSlice; az2 = (2.0f*mjPI * (j+1.0f)) / (float)nSlice;
@@ -613,7 +613,7 @@ static void sphere(int nSlice, int nStack) {
n3[2] = sign; n3[2] = sign;
// make triangle // make triangle
if (sign>0) { if (sign > 0) {
glNormal3fv(n1); glNormal3fv(n1);
glVertex3fv(v1); glVertex3fv(v1);
glNormal3fv(n2); glNormal3fv(n2);
@@ -634,12 +634,12 @@ static void sphere(int nSlice, int nStack) {
// the rest: use quads // the rest: use quads
glBegin(GL_QUADS); glBegin(GL_QUADS);
for (int sign=-1; sign<=1; sign+=2) { for (int sign=-1; sign <= 1; sign+=2) {
for (int i=0; i<nStack/2-1; i++) { for (int i=0; i < nStack/2-1; i++) {
el1 = (0.5*mjPI * sign * (i+0)) / (float)(nStack/2); el1 = (0.5*mjPI * sign * (i+0)) / (float)(nStack/2);
el2 = (0.5*mjPI * sign * (i+1)) / (float)(nStack/2); el2 = (0.5*mjPI * sign * (i+1)) / (float)(nStack/2);
for (int j=0; j<nSlice; j++) { for (int j=0; j < nSlice; j++) {
az1 = (2.0f*mjPI * (j+0)) / (float)nSlice; az1 = (2.0f*mjPI * (j+0)) / (float)nSlice;
az2 = (2.0f*mjPI * (j+1)) / (float)nSlice; az2 = (2.0f*mjPI * (j+1)) / (float)nSlice;
@@ -650,7 +650,7 @@ static void sphere(int nSlice, int nStack) {
setVertexSphere(v4, n4, az1, el2, 0); setVertexSphere(v4, n4, az1, el2, 0);
// make quad // make quad
if (sign>0) { if (sign > 0) {
glNormal3fv(n1); glNormal3fv(n1);
glVertex3fv(v1); glVertex3fv(v1);
glNormal3fv(n2); glNormal3fv(n2);
@@ -689,13 +689,13 @@ static void setVertexDisk(float* v, float az, float r, int sign) {
static void disk(int sign, int nSlice, int nStack) { static void disk(int sign, int nSlice, int nStack) {
float az1, az2, r1, r2; float az1, az2, r1, r2;
float v1[3], v2[3], v3[3], v4[3]; float v1[3], v2[3], v3[3], v4[3];
float normal[3] = {0, 0, (sign==0 ? -1 : sign)}; float normal[3] = {0, 0, (sign == 0 ? -1 : sign)};
// pole: use triangles // pole: use triangles
glBegin(GL_TRIANGLES); glBegin(GL_TRIANGLES);
glNormal3fv(normal); glNormal3fv(normal);
r1 = 1.0f / (float)nStack; r1 = 1.0f / (float)nStack;
for (int j=0; j<nSlice; j++) { for (int j=0; j < nSlice; j++) {
az1 = (2.0f*mjPI * (j+0)) / (float)nSlice; az1 = (2.0f*mjPI * (j+0)) / (float)nSlice;
az2 = (2.0f*mjPI * (j+1)) / (float)nSlice; az2 = (2.0f*mjPI * (j+1)) / (float)nSlice;
@@ -706,7 +706,7 @@ static void disk(int sign, int nSlice, int nStack) {
v3[2] = sign; v3[2] = sign;
// make triangle // make triangle
if (sign>0) { if (sign > 0) {
glVertex3fv(v1); glVertex3fv(v1);
glVertex3fv(v2); glVertex3fv(v2);
glVertex3fv(v3); glVertex3fv(v3);
@@ -721,11 +721,11 @@ static void disk(int sign, int nSlice, int nStack) {
// the rest: use quads // the rest: use quads
glBegin(GL_QUADS); glBegin(GL_QUADS);
glNormal3fv(normal); glNormal3fv(normal);
for (int i=0; i<nStack-1; i++) { for (int i=0; i < nStack-1; i++) {
r1 = (i+1) / (float)nStack; r1 = (i+1) / (float)nStack;
r2 = (i+2) / (float)nStack; r2 = (i+2) / (float)nStack;
for (int j=0; j<nSlice; j++) { for (int j=0; j < nSlice; j++) {
az1 = (2.0f*mjPI * (j+0)) / (float)nSlice; az1 = (2.0f*mjPI * (j+0)) / (float)nSlice;
az2 = (2.0f*mjPI * (j+1)) / (float)nSlice; az2 = (2.0f*mjPI * (j+1)) / (float)nSlice;
@@ -736,7 +736,7 @@ static void disk(int sign, int nSlice, int nStack) {
setVertexDisk(v4, az1, r1, sign); setVertexDisk(v4, az1, r1, sign);
// make quad // make quad
if (sign>0) { if (sign > 0) {
glVertex3fv(v1); glVertex3fv(v1);
glVertex3fv(v2); glVertex3fv(v2);
glVertex3fv(v3); glVertex3fv(v3);
@@ -779,7 +779,7 @@ static void cone(int nSlice, int nStack) {
// pole: use triangles // pole: use triangles
glBegin(GL_TRIANGLES); glBegin(GL_TRIANGLES);
r1 = 1.0f / (float)nStack; r1 = 1.0f / (float)nStack;
for (int j=0; j<nSlice; j++) { for (int j=0; j < nSlice; j++) {
az1 = (2.0f*mjPI * (j+0)) / (float)nSlice; az1 = (2.0f*mjPI * (j+0)) / (float)nSlice;
az2 = (2.0f*mjPI * (j+1)) / (float)nSlice; az2 = (2.0f*mjPI * (j+1)) / (float)nSlice;
@@ -805,11 +805,11 @@ static void cone(int nSlice, int nStack) {
// the rest: use quads // the rest: use quads
glBegin(GL_QUADS); glBegin(GL_QUADS);
for (int i=0; i<nStack-1; i++) { for (int i=0; i < nStack-1; i++) {
r1 = (i+1) / (float)nStack; r1 = (i+1) / (float)nStack;
r2 = (i+2) / (float)nStack; r2 = (i+2) / (float)nStack;
for (int j=0; j<nSlice; j++) { for (int j=0; j < nSlice; j++) {
az1 = (2.0f*mjPI * (j+0)) / (float)nSlice; az1 = (2.0f*mjPI * (j+0)) / (float)nSlice;
az2 = (2.0f*mjPI * (j+1)) / (float)nSlice; az2 = (2.0f*mjPI * (j+1)) / (float)nSlice;
@@ -855,11 +855,11 @@ static void cylinder(int nSlice, int nStack) {
// use quads everywhere // use quads everywhere
glBegin(GL_QUADS); glBegin(GL_QUADS);
for (int i=0; i<nStack; i++) { for (int i=0; i < nStack; i++) {
h1 = 2*(i+0)/(float)nStack - 1; h1 = 2*(i+0)/(float)nStack - 1;
h2 = 2*(i+1)/(float)nStack - 1; h2 = 2*(i+1)/(float)nStack - 1;
for (int j=0; j<nSlice; j++) { for (int j=0; j < nSlice; j++) {
az1 = (2.0f*mjPI * (j+0)) / (float)nSlice; az1 = (2.0f*mjPI * (j+0)) / (float)nSlice;
az2 = (2.0f*mjPI * (j+1)) / (float)nSlice; az2 = (2.0f*mjPI * (j+1)) / (float)nSlice;
@@ -907,11 +907,11 @@ static void haze(int nSlice, float r, const float* rgba) {
glNormal3f(0, 0, 1); glNormal3f(0, 0, 1);
// stacks = 2 // stacks = 2
for (int i=0; i<2; i++) { for (int i=0; i < 2; i++) {
float h1 = (i==0 ? 0 : h); float h1 = (i == 0 ? 0 : h);
float h2 = (i==0 ? h : 1); float h2 = (i == 0 ? h : 1);
for (int j=0; j<nSlice; j++) { for (int j=0; j < nSlice; j++) {
float az1 = (2.0f*mjPI * (j+0)) / (float)nSlice; float az1 = (2.0f*mjPI * (j+0)) / (float)nSlice;
float az2 = (2.0f*mjPI * (j+1)) / (float)nSlice; float az2 = (2.0f*mjPI * (j+1)) / (float)nSlice;
@@ -923,8 +923,8 @@ static void haze(int nSlice, float r, const float* rgba) {
setVertexHaze(v4, az1, h2, r); setVertexHaze(v4, az1, h2, r);
// colors at elevation h1 and h2 // colors at elevation h1 and h2
float c1 = (i==1); float c1 = (i == 1);
float c2 = (i==0); float c2 = (i == 0);
// make quad, with colors // make quad, with colors
glColor4f(rgba[0], rgba[1], rgba[2], c1); glColor4f(rgba[0], rgba[1], rgba[2], c1);
@@ -985,8 +985,8 @@ static void makeBuiltin(const mjModel* m, mjrContext* con) {
// box // box
glNewList(con->baseBuiltin + mjrBOX, GL_COMPILE); glNewList(con->baseBuiltin + mjrBOX, GL_COMPILE);
glBegin(GL_QUADS); glBegin(GL_QUADS);
for (int x=0; x<numquads; x++) { for (int x=0; x < numquads; x++) {
for (int y=0; y<numquads; y++) { for (int y=0; y < numquads; y++) {
glNormal3f(0, 0, 1); // top glNormal3f(0, 0, 1); // top
glVertex3f(d*(x+0)-1, d*(y+0)-1, 1); glVertex3f(d*(x+0)-1, d*(y+0)-1, 1);
glVertex3f(d*(x+1)-1, d*(y+0)-1, 1); glVertex3f(d*(x+1)-1, d*(y+0)-1, 1);
@@ -1076,7 +1076,7 @@ static void makeShadow(const mjModel* m, mjrContext* con) {
// check FBO status // check FBO status
GLenum err = glCheckFramebufferStatus(GL_FRAMEBUFFER); GLenum err = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (err!=GL_FRAMEBUFFER_COMPLETE) { if (err != GL_FRAMEBUFFER_COMPLETE) {
mju_error("Shadow framebuffer is not complete, error 0x%x", err); mju_error("Shadow framebuffer is not complete, error 0x%x", err);
} }
@@ -1102,7 +1102,7 @@ static void makeOff(mjrContext* con) {
// clamp samples request // clamp samples request
int sMax = 0; int sMax = 0;
glGetIntegerv(GL_MAX_SAMPLES, &sMax); glGetIntegerv(GL_MAX_SAMPLES, &sMax);
if (con->offSamples>sMax) { if (con->offSamples > sMax) {
con->offSamples = sMax; con->offSamples = sMax;
} }
@@ -1137,7 +1137,7 @@ static void makeOff(mjrContext* con) {
// check FBO status // check FBO status
GLenum err = glCheckFramebufferStatus(GL_FRAMEBUFFER); GLenum err = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (err!=GL_FRAMEBUFFER_COMPLETE) { if (err != GL_FRAMEBUFFER_COMPLETE) {
mju_error("Offscreen framebuffer is not complete, error 0x%x", err); mju_error("Offscreen framebuffer is not complete, error 0x%x", err);
} }
@@ -1175,7 +1175,7 @@ static void makeOff(mjrContext* con) {
// check FBO status // check FBO status
GLenum err = glCheckFramebufferStatus(GL_FRAMEBUFFER); GLenum err = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (err!=GL_FRAMEBUFFER_COMPLETE) { if (err != GL_FRAMEBUFFER_COMPLETE) {
mju_error("Offscreen framebuffer_r is not complete, error 0x%x", err); mju_error("Offscreen framebuffer_r is not complete, error 0x%x", err);
} }
} }
@@ -1241,14 +1241,14 @@ static void makeFont(mjrContext* con, int fontscale) {
con->baseFontNormal = glGenLists(con->rangeFont); con->baseFontNormal = glGenLists(con->rangeFont);
con->baseFontShadow = glGenLists(con->rangeFont); con->baseFontShadow = glGenLists(con->rangeFont);
con->baseFontBig = glGenLists(con->rangeFont); con->baseFontBig = glGenLists(con->rangeFont);
if (con->baseFontNormal==0 || con->baseFontShadow==0 || con->baseFontBig==0) { if (con->baseFontNormal == 0 || con->baseFontShadow == 0 || con->baseFontBig == 0) {
mju_error("Could not allocate font lists"); mju_error("Could not allocate font lists");
} }
// loop over printable characters (32-126) // loop over printable characters (32-126)
for (unsigned char i=32; i<=126; i++) { for (unsigned char i=32; i <= 126; i++) {
// assert character code; SHOULD NOT OCCUR // assert character code; SHOULD NOT OCCUR
if (font_normal[adr]!=i || font_back[adr]!=i || font_big[adr_big]!=i) { if (font_normal[adr] != i || font_back[adr] != i || font_big[adr_big] != i) {
mju_error("Invalid font data index"); mju_error("Invalid font data index");
} }
@@ -1286,7 +1286,7 @@ static void makeFont(mjrContext* con, int fontscale) {
} }
// assert 123 termination token; SHOULD NOT OCCUR // assert 123 termination token; SHOULD NOT OCCUR
if (font_normal[adr]!=123 || font_back[adr]!=123 || font_big[adr_big]!=123) { if (font_normal[adr] != 123 || font_back[adr] != 123 || font_big[adr_big] != 123) {
mju_error("Invalid font data termination"); mju_error("Invalid font data termination");
} }
} }
@@ -1296,7 +1296,7 @@ static void makeFont(mjrContext* con, int fontscale) {
// make textures // make textures
static void makeTexture(const mjModel* m, mjrContext* con) { static void makeTexture(const mjModel* m, mjrContext* con) {
// checks size // checks size
if (m->ntex>mjMAXTEXTURE) { if (m->ntex > mjMAXTEXTURE) {
mju_error("Maximum number of textures is %d", mjMAXTEXTURE); mju_error("Maximum number of textures is %d", mjMAXTEXTURE);
} }
@@ -1308,7 +1308,7 @@ static void makeTexture(const mjModel* m, mjrContext* con) {
// allocate and upload // allocate and upload
glGenTextures(con->ntexture, con->texture); glGenTextures(con->ntexture, con->texture);
for (int i=0; i<m->ntex; i++) { for (int i=0; i < m->ntex; i++) {
con->textureType[i] = m->tex_type[i]; con->textureType[i] = m->tex_type[i];
mjr_uploadTexture(m, con, i); mjr_uploadTexture(m, con, i);
} }
@@ -1322,7 +1322,7 @@ void mjr_uploadTexture(const mjModel* m, const mjrContext* con, int texid) {
float plane[4]; float plane[4];
// 2D texture // 2D texture
if (m->tex_type[texid]==mjTEXTURE_2D) { if (m->tex_type[texid] == mjTEXTURE_2D) {
// OpenGL settings // OpenGL settings
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
@@ -1373,8 +1373,8 @@ void mjr_uploadTexture(const mjModel* m, const mjrContext* con, int texid) {
glTexGenfv(GL_R, GL_OBJECT_PLANE, plane); glTexGenfv(GL_R, GL_OBJECT_PLANE, plane);
// assign data: repeated // assign data: repeated
if (m->tex_width[texid]==m->tex_height[texid]) { if (m->tex_width[texid] == m->tex_height[texid]) {
for (int i=0; i<6; i++) { for (int i=0; i < 6; i++) {
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X+i, 0, GL_RGB, w, w, 0, glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X+i, 0, GL_RGB, w, w, 0,
GL_RGB, GL_UNSIGNED_BYTE, m->tex_rgb + m->tex_adr[texid]); GL_RGB, GL_UNSIGNED_BYTE, m->tex_rgb + m->tex_adr[texid]);
} }
@@ -1382,7 +1382,7 @@ void mjr_uploadTexture(const mjModel* m, const mjrContext* con, int texid) {
// assign data: separate faces // assign data: separate faces
else { else {
for (int i=0; i<6; i++) { for (int i=0; i < 6; i++) {
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X+i, 0, GL_RGB, w, w, 0, glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X+i, 0, GL_RGB, w, w, 0,
GL_RGB, GL_UNSIGNED_BYTE, m->tex_rgb + m->tex_adr[texid] + i*3*w*w); GL_RGB, GL_UNSIGNED_BYTE, m->tex_rgb + m->tex_adr[texid] + i*3*w*w);
} }
@@ -1418,9 +1418,9 @@ static void makeSkin(const mjModel* m, mjrContext* con) {
glGenBuffers(nskin, con->skinfaceVBO); glGenBuffers(nskin, con->skinfaceVBO);
// process skins // process skins
for (int i=0; i<nskin; i++) { for (int i=0; i < nskin; i++) {
// texture coordinates // texture coordinates
if (m->skin_texcoordadr[i]>=0) { if (m->skin_texcoordadr[i] >= 0) {
glBindBuffer(GL_ARRAY_BUFFER, con->skintexcoordVBO[i]); glBindBuffer(GL_ARRAY_BUFFER, con->skintexcoordVBO[i]);
glBufferData(GL_ARRAY_BUFFER, glBufferData(GL_ARRAY_BUFFER,
2*m->skin_vertnum[i]*sizeof(float), 2*m->skin_vertnum[i]*sizeof(float),
@@ -1469,9 +1469,9 @@ void mjr_makeContext_offSize(const mjModel* m, mjrContext* con, int fontscale,
int default_offwidth, int default_offheight) { int default_offwidth, int default_offheight) {
// fix fontscale // fix fontscale
fontscale = 50 * mju_round(((mjtNum)fontscale)/50.0); fontscale = 50 * mju_round(((mjtNum)fontscale)/50.0);
if (fontscale<100) { if (fontscale < 100) {
fontscale = 100; fontscale = 100;
} else if (fontscale>300) { } else if (fontscale > 300) {
fontscale = 300; fontscale = 300;
} }
@@ -1494,9 +1494,9 @@ void mjr_makeContext_offSize(const mjModel* m, mjrContext* con, int fontscale,
// determine window availability (could be EGL-headless) // determine window availability (could be EGL-headless)
glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0);
unsigned int status = glCheckFramebufferStatus(GL_FRAMEBUFFER); unsigned int status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (status==GL_FRAMEBUFFER_COMPLETE) { if (status == GL_FRAMEBUFFER_COMPLETE) {
con->windowAvailable = 1; con->windowAvailable = 1;
} else if (status==GL_FRAMEBUFFER_UNDEFINED) { } else if (status == GL_FRAMEBUFFER_UNDEFINED) {
con->windowAvailable = 0; con->windowAvailable = 0;
} else { } else {
mju_error("Default framebuffer is not complete, error 0x%x", status); mju_error("Default framebuffer is not complete, error 0x%x", status);
@@ -1640,7 +1640,7 @@ void mjr_changeFont(int fontscale, mjrContext* con) {
// Add Aux buffer to context; free previous Aux buffer. // Add Aux buffer to context; free previous Aux buffer.
void mjr_addAux(int index, int width, int height, int samples, mjrContext* con) { void mjr_addAux(int index, int width, int height, int samples, mjrContext* con) {
// check index // check index
if (index<0 || index>=mjNAUX) { if (index < 0 || index >= mjNAUX) {
mju_error("Invalid aux buffer index"); mju_error("Invalid aux buffer index");
} }
@@ -1663,21 +1663,21 @@ void mjr_addAux(int index, int width, int height, int samples, mjrContext* con)
con->auxFBO_r[index] = 0; con->auxFBO_r[index] = 0;
// return if size is not positive // return if size is not positive
if (width<1 || height<1) { if (width < 1 || height < 1) {
return; return;
} }
// check max size // check max size
int maxSize = 0; int maxSize = 0;
glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &maxSize); glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &maxSize);
if (width>maxSize || height>maxSize) { if (width > maxSize || height > maxSize) {
mju_error("Auxiliary buffer size exceeds maximum allowed by OpenGL implementation"); mju_error("Auxiliary buffer size exceeds maximum allowed by OpenGL implementation");
} }
// clamp samples request // clamp samples request
int maxSample = 0; int maxSample = 0;
glGetIntegerv(GL_MAX_SAMPLES, &maxSample); glGetIntegerv(GL_MAX_SAMPLES, &maxSample);
if (samples>maxSample) { if (samples > maxSample) {
samples = maxSample; samples = maxSample;
} }
@@ -1706,7 +1706,7 @@ void mjr_addAux(int index, int width, int height, int samples, mjrContext* con)
// check FBO status // check FBO status
GLenum err = glCheckFramebufferStatus(GL_FRAMEBUFFER); GLenum err = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (err!=GL_FRAMEBUFFER_COMPLETE) { if (err != GL_FRAMEBUFFER_COMPLETE) {
mju_error("Auxiliary framebuffer is not complete, error 0x%x", err); mju_error("Auxiliary framebuffer is not complete, error 0x%x", err);
} }
@@ -1730,7 +1730,7 @@ void mjr_addAux(int index, int width, int height, int samples, mjrContext* con)
// check FBO status // check FBO status
err = glCheckFramebufferStatus(GL_FRAMEBUFFER); err = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (err!=GL_FRAMEBUFFER_COMPLETE) { if (err != GL_FRAMEBUFFER_COMPLETE) {
mju_error("Auxiliary framebuffer resolve is not complete, error 0x%x", err); mju_error("Auxiliary framebuffer resolve is not complete, error 0x%x", err);
} }
@@ -1759,7 +1759,7 @@ void mjr_freeContext(mjrContext* con) {
if (con->offFBO_r) glDeleteFramebuffers(1, &con->offFBO_r); if (con->offFBO_r) glDeleteFramebuffers(1, &con->offFBO_r);
if (con->shadowTex) glDeleteTextures(1, &con->shadowTex); if (con->shadowTex) glDeleteTextures(1, &con->shadowTex);
if (con->shadowFBO) glDeleteFramebuffers(1, &con->shadowFBO); if (con->shadowFBO) glDeleteFramebuffers(1, &con->shadowFBO);
for (int i=0; i<mjNAUX; i++) { for (int i=0; i < mjNAUX; i++) {
if (con->auxColor[i]) glDeleteRenderbuffers(1, con->auxColor + i); if (con->auxColor[i]) glDeleteRenderbuffers(1, con->auxColor + i);
if (con->auxColor_r[i]) glDeleteRenderbuffers(1, con->auxColor_r + i); if (con->auxColor_r[i]) glDeleteRenderbuffers(1, con->auxColor_r + i);
if (con->auxFBO[i]) glDeleteFramebuffers(1, con->auxFBO + i); if (con->auxFBO[i]) glDeleteFramebuffers(1, con->auxFBO + i);
+74 -71
View File
@@ -60,7 +60,7 @@ void mjr_setBuffer(int framebuffer, mjrContext* con) {
// both available: use selected framebuffer // both available: use selected framebuffer
else { else {
// bind selected buffer // bind selected buffer
if (framebuffer==mjFB_WINDOW) { if (framebuffer == mjFB_WINDOW) {
glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0);
glReadBuffer(con->windowDoublebuffer ? GL_BACK : GL_FRONT); glReadBuffer(con->windowDoublebuffer ? GL_BACK : GL_FRONT);
glDrawBuffer(con->windowDoublebuffer ? GL_BACK : GL_FRONT); glDrawBuffer(con->windowDoublebuffer ? GL_BACK : GL_FRONT);
@@ -79,7 +79,7 @@ void mjr_setBuffer(int framebuffer, mjrContext* con) {
// make con->currentBuffer current again // make con->currentBuffer current again
void mjr_restoreBuffer(const mjrContext* con) { void mjr_restoreBuffer(const mjrContext* con) {
if (con->currentBuffer==mjFB_WINDOW) { if (con->currentBuffer == mjFB_WINDOW) {
glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0);
glReadBuffer(con->windowDoublebuffer ? GL_BACK : GL_FRONT); glReadBuffer(con->windowDoublebuffer ? GL_BACK : GL_FRONT);
glDrawBuffer(con->windowDoublebuffer ? GL_BACK : GL_FRONT); glDrawBuffer(con->windowDoublebuffer ? GL_BACK : GL_FRONT);
@@ -106,7 +106,7 @@ void mjr_readPixels(unsigned char* rgb, float* depth,
} }
// read from window // read from window
if (con->currentBuffer==mjFB_WINDOW) { if (con->currentBuffer == mjFB_WINDOW) {
// read rgb and depth // read rgb and depth
if (rgb) { if (rgb) {
glReadPixels(viewport.left, viewport.bottom, viewport.width, viewport.height, glReadPixels(viewport.left, viewport.bottom, viewport.width, viewport.height,
@@ -193,7 +193,7 @@ void mjr_blitBuffer(mjrRect src, mjrRect dst,
// construct mask and filter for blit // construct mask and filter for blit
GLbitfield mask = (flg_color ? GL_COLOR_BUFFER_BIT : 0) | GLbitfield mask = (flg_color ? GL_COLOR_BUFFER_BIT : 0) |
(flg_depth ? GL_DEPTH_BUFFER_BIT : 0); (flg_depth ? GL_DEPTH_BUFFER_BIT : 0);
GLenum filter = (!flg_depth && (src.width!=dst.width || src.height!=dst.height)) ? GLenum filter = (!flg_depth && (src.width != dst.width || src.height != dst.height)) ?
GL_LINEAR : GL_NEAREST; GL_LINEAR : GL_NEAREST;
// make sure both buffers are available and we have something to do // make sure both buffers are available and we have something to do
@@ -207,7 +207,7 @@ void mjr_blitBuffer(mjrRect src, mjrRect dst,
} }
// from window to offsreen // from window to offsreen
if (con->currentBuffer==mjFB_WINDOW) { if (con->currentBuffer == mjFB_WINDOW) {
// offscreen is multisample: go through resolve // offscreen is multisample: go through resolve
if (con->offSamples) { if (con->offSamples) {
// prepare to blit from window to resolve // prepare to blit from window to resolve
@@ -291,7 +291,7 @@ void mjr_blitBuffer(mjrRect src, mjrRect dst,
// Set Aux buffer for custom OpenGL rendering (call restoreBuffer when done). // Set Aux buffer for custom OpenGL rendering (call restoreBuffer when done).
void mjr_setAux(int index, const mjrContext* con) { void mjr_setAux(int index, const mjrContext* con) {
// check index // check index
if (index<0 || index>=mjNAUX) { if (index < 0 || index >= mjNAUX) {
mju_error("Invalid aux buffer index"); mju_error("Invalid aux buffer index");
} }
@@ -310,7 +310,7 @@ void mjr_setAux(int index, const mjrContext* con) {
// Blit from Aux buffer to con->currentBuffer. // Blit from Aux buffer to con->currentBuffer.
void mjr_blitAux(int index, mjrRect src, int left, int bottom, const mjrContext* con) { void mjr_blitAux(int index, mjrRect src, int left, int bottom, const mjrContext* con) {
// check index // check index
if (index<0 || index>=mjNAUX) { if (index < 0 || index >= mjNAUX) {
mju_error("Invalid aux buffer index"); mju_error("Invalid aux buffer index");
} }
@@ -338,7 +338,7 @@ void mjr_blitAux(int index, mjrRect src, int left, int bottom, const mjrContext*
glReadBuffer(GL_COLOR_ATTACHMENT0); glReadBuffer(GL_COLOR_ATTACHMENT0);
// set destination // set destination
if (con->currentBuffer==mjFB_WINDOW) { if (con->currentBuffer == mjFB_WINDOW) {
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glDrawBuffer(con->windowDoublebuffer ? GL_BACK : GL_FRONT); glDrawBuffer(con->windowDoublebuffer ? GL_BACK : GL_FRONT);
} else { } else {
@@ -391,7 +391,7 @@ void mjr_textActual(int font, const char* txt, const mjrContext* con,
} }
// shadow text // shadow text
if (font==mjFONT_SHADOW) { if (font == mjFONT_SHADOW) {
// blend shadow with black // blend shadow with black
glListBase(con->baseFontShadow); glListBase(con->baseFontShadow);
glColor4f(0, 0, 0, 0.5); glColor4f(0, 0, 0, 0.5);
@@ -407,7 +407,7 @@ void mjr_textActual(int font, const char* txt, const mjrContext* con,
// regular text (normal or big) // regular text (normal or big)
else { else {
glListBase(font==mjFONT_BIG ? con->baseFontBig : con->baseFontNormal); glListBase(font == mjFONT_BIG ? con->baseFontBig : con->baseFontNormal);
glColor4f(r, g, b, 1); glColor4f(r, g, b, 1);
glRasterPos3f(x, y, z); glRasterPos3f(x, y, z);
glCallLists((GLsizei)strlen(txt), GL_UNSIGNED_BYTE, txt); glCallLists((GLsizei)strlen(txt), GL_UNSIGNED_BYTE, txt);
@@ -433,16 +433,16 @@ static int draw_overlay(int font, mjrRect viewport, int skip, int gridpos,
float red, float green, float blue, float red, float green, float blue,
const char* overlay, const mjrContext* con) { const char* overlay, const mjrContext* con) {
int pos, ncthis, nc, nr, W, H, flg_big = (font==mjFONT_BIG); int pos, ncthis, nc, nr, W, H, flg_big = (font == mjFONT_BIG);
int PAD = 5, sz = mjMIN(mjMAXOVERLAY, (int)strlen(overlay)); int PAD = 5, sz = mjMIN(mjMAXOVERLAY, (int)strlen(overlay));
char text[mjMAXOVERLAY]; char text[mjMAXOVERLAY];
// count rows and columns of text rectangle in pixels // count rows and columns of text rectangle in pixels
nr = flg_big ? con->charHeightBig : con->charHeight; nr = flg_big ? con->charHeightBig : con->charHeight;
ncthis = nc = 0; ncthis = nc = 0;
for (int i=0; i<sz; i++) { for (int i=0; i < sz; i++) {
// process this char // process this char
if (overlay[i]!='\n') { if (overlay[i] != '\n') {
ncthis += flg_big ? con->charWidthBig[(unsigned char)overlay[i]] ncthis += flg_big ? con->charWidthBig[(unsigned char)overlay[i]]
: con->charWidth[(unsigned char)overlay[i]]; : con->charWidth[(unsigned char)overlay[i]];
nc = mjMAX(nc, ncthis); nc = mjMAX(nc, ncthis);
@@ -503,10 +503,10 @@ static int draw_overlay(int font, mjrRect viewport, int skip, int gridpos,
// draw text line by line // draw text line by line
nr = flg_big ? con->charHeightBig : con->charHeight; nr = flg_big ? con->charHeightBig : con->charHeight;
pos = 0; pos = 0;
for (int i=0; i<sz; i++) { for (int i=0; i < sz; i++) {
// terminate line and draw // terminate line and draw
if (overlay[i]=='\n' || i==sz-1) { if (overlay[i] == '\n' || i == sz-1) {
if (overlay[i]=='\n') { if (overlay[i] == '\n') {
text[pos] = 0; text[pos] = 0;
} else { } else {
text[pos] = overlay[i]; text[pos] = overlay[i];
@@ -536,7 +536,7 @@ void mjr_overlay(int font, int gridpos, mjrRect viewport,
int skip = 0; int skip = 0;
// empty viewport: nothing to do // empty viewport: nothing to do
if (viewport.width<=0 || viewport.height<=0) { if (viewport.width <= 0 || viewport.height <= 0) {
return; return;
} }
@@ -546,7 +546,7 @@ void mjr_overlay(int font, int gridpos, mjrRect viewport,
// two-column // two-column
if (overlay2 && overlay2[0]) { if (overlay2 && overlay2[0]) {
// left side // left side
if (gridpos==mjGRID_TOPLEFT || gridpos==mjGRID_BOTTOMLEFT) { if (gridpos == mjGRID_TOPLEFT || gridpos == mjGRID_BOTTOMLEFT) {
skip = draw_overlay(font, viewport, 0, gridpos, .7, .7, .7, overlay, con); skip = draw_overlay(font, viewport, 0, gridpos, .7, .7, .7, overlay, con);
draw_overlay(font, viewport, skip, gridpos, 1, 1, 1, overlay2, con); draw_overlay(font, viewport, skip, gridpos, 1, 1, 1, overlay2, con);
} }
@@ -575,7 +575,7 @@ mjrRect mjr_maxViewport(const mjrContext* con) {
// window: get from scissor box // window: get from scissor box
int dims[4]; int dims[4];
if (con->currentBuffer==mjFB_WINDOW) { if (con->currentBuffer == mjFB_WINDOW) {
glGetIntegerv(GL_SCISSOR_BOX, dims); glGetIntegerv(GL_SCISSOR_BOX, dims);
res.width = dims[2]; res.width = dims[2];
res.height = dims[3]; res.height = dims[3];
@@ -589,7 +589,7 @@ mjrRect mjr_maxViewport(const mjrContext* con) {
// draw rectangle // draw rectangle
void mjr_rectangle(mjrRect viewport, float r, float g, float b, float a) { void mjr_rectangle(mjrRect viewport, float r, float g, float b, float a) {
// empty viewport: nothing to do // empty viewport: nothing to do
if (viewport.width<=0 || viewport.height<=0) { if (viewport.width <= 0 || viewport.height <= 0) {
return; return;
} }
@@ -616,7 +616,7 @@ void mjr_label(mjrRect viewport, int font, const char* txt,
float r, float g, float b, float a, float rt, float gt, float bt, float r, float g, float b, float a, float rt, float gt, float bt,
const mjrContext* con) { const mjrContext* con) {
// empty viewport: nothing to do // empty viewport: nothing to do
if (viewport.width<=0 || viewport.height<=0) { if (viewport.width <= 0 || viewport.height <= 0) {
return; return;
} }
@@ -658,7 +658,7 @@ void mjr_label(mjrRect viewport, int font, const char* txt,
if (txt && con->rangeFont) { if (txt && con->rangeFont) {
// compute width // compute width
int i = 0, width = 0; int i = 0, width = 0;
if (font==mjFONT_BIG) { if (font == mjFONT_BIG) {
while (txt[i]) { while (txt[i]) {
width += con->charWidthBig[(unsigned char)txt[i++]]; width += con->charWidthBig[(unsigned char)txt[i++]];
} }
@@ -670,10 +670,10 @@ void mjr_label(mjrRect viewport, int font, const char* txt,
// compute center // compute center
int cx = (W - width)/2; int cx = (W - width)/2;
int cy = (H - (font==mjFONT_BIG ? con->charHeightBig : con->charHeight))/2; int cy = (H - (font == mjFONT_BIG ? con->charHeightBig : con->charHeight))/2;
// draw // draw
glListBase(font==mjFONT_BIG ? con->baseFontBig : con->baseFontNormal); glListBase(font == mjFONT_BIG ? con->baseFontBig : con->baseFontNormal);
glColor3f(rt, gt, bt); glColor3f(rt, gt, bt);
glRasterPos2i(mjMAX(0, cx), cy); glRasterPos2i(mjMAX(0, cx), cy);
glCallLists((GLsizei)strlen(txt), GL_UNSIGNED_BYTE, txt); glCallLists((GLsizei)strlen(txt), GL_UNSIGNED_BYTE, txt);
@@ -691,15 +691,15 @@ static void maketext(const char* format, char* txt, float num, int txt_sz) {
// locate trailing zeros // locate trailing zeros
i = strlen(txt); i = strlen(txt);
while (i>0 && txt[i-1]=='0') { while (i > 0 && txt[i-1] == '0') {
i--; i--;
} }
if (i<=1) { if (i <= 1) {
return; return;
} }
// strip if preceding char is '.' // strip if preceding char is '.'
if (txt[i-1]=='.') { if (txt[i-1] == '.') {
txt[i-1] = 0; txt[i-1] = 0;
} }
@@ -707,12 +707,12 @@ static void maketext(const char* format, char* txt, float num, int txt_sz) {
else { else {
// find regular preceding digits // find regular preceding digits
j = i-1; j = i-1;
while (j>=0 && txt[j]>='0' && txt[j]<='9') { while (j >= 0 && txt[j] >= '0' && txt[j] <= '9') {
j--; j--;
} }
// '.' found: strip // '.' found: strip
if (j>=0 && txt[j]=='.') { if (j >= 0 && txt[j] == '.') {
txt[i] = 0; txt[i] = 0;
} }
} }
@@ -743,7 +743,7 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
char datatxt[STRING_BUFSIZE]; char datatxt[STRING_BUFSIZE];
// empty viewport: nothing to do // empty viewport: nothing to do
if (viewport.width<=0 || viewport.height<=0) { if (viewport.width <= 0 || viewport.height <= 0) {
return; return;
} }
@@ -763,12 +763,12 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
glDisable(GL_BLEND); glDisable(GL_BLEND);
// determine range along (x,y) // determine range along (x,y)
for (int axis=0; axis<2; axis++) { for (int axis=0; axis < 2; axis++) {
// init ranges, set flag // init ranges, set flag
range[axis][0] = fig->range[axis][0]; range[axis][0] = fig->range[axis][0];
range[axis][1] = fig->range[axis][1]; range[axis][1] = fig->range[axis][1];
int flg; int flg;
if (fig->range[axis][0]<fig->range[axis][1]) { if (fig->range[axis][0] < fig->range[axis][1]) {
flg = 1; flg = 1;
} else { } else {
flg = 0; flg = 0;
@@ -776,8 +776,8 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
// determine range: scan line data, find min and max // determine range: scan line data, find min and max
if (!flg || fig->flg_extend) { if (!flg || fig->flg_extend) {
for (int n=0; n<mjMAXLINE; n++) { for (int n=0; n < mjMAXLINE; n++) {
for (int i=0; i<fig->linepnt[n]; i++) { for (int i=0; i < fig->linepnt[n]; i++) {
// get data // get data
float ldata = fig->linedata[n][2*i+axis]; float ldata = fig->linedata[n][2*i+axis];
@@ -796,12 +796,12 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
// otherwise regular update // otherwise regular update
else { else {
// update minimum // update minimum
if (range[axis][0]>ldata) { if (range[axis][0] > ldata) {
range[axis][0] = ldata; range[axis][0] = ldata;
} }
// update maximum // update maximum
if (range[axis][1]<ldata) { if (range[axis][1] < ldata) {
range[axis][1] = ldata; range[axis][1] = ldata;
} }
} }
@@ -810,7 +810,7 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
} }
// make sure range is not too small // make sure range is not too small
if (range[axis][1]-range[axis][0]<minrange) { if (range[axis][1]-range[axis][0] < minrange) {
float needed = minrange - (range[axis][1]-range[axis][0]); float needed = minrange - (range[axis][1]-range[axis][0]);
range[axis][0] -= 0.5f*needed; range[axis][0] -= 0.5f*needed;
range[axis][1] += 0.5f*needed; range[axis][1] += 0.5f*needed;
@@ -833,7 +833,7 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
// set projection in pixels // set projection in pixels
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
if (viewport.width<=1 || viewport.height<=1) { if (viewport.width <= 1 || viewport.height <= 1) {
return; return;
} }
glOrtho(0, viewport.width-1, 0, viewport.height-1, -1, 1); glOrtho(0, viewport.width-1, 0, viewport.height-1, -1, 1);
@@ -843,29 +843,32 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
if (fig->title[0]) { if (fig->title[0]) {
// find address of selected subplot title // find address of selected subplot title
int subadr = 0, subcnt = 0; int subadr = 0, subcnt = 0;
while (subcnt<fig->subplot && subadr<1000 && fig->title[subadr]) { while (subcnt < fig->subplot && subadr < 1000 && fig->title[subadr]) {
// skip non-space // skip non-space
while (subadr<1000 && fig->title[subadr] && fig->title[subadr]!=' ') { while (subadr < 1000 && fig->title[subadr] && fig->title[subadr] != ' ') {
subadr++; subadr++;
} }
// skip space, count // skip space, count
int cntspace = 0; int cntspace = 0;
while (subadr<1000 && fig->title[subadr]==' ') { while (subadr < 1000 && fig->title[subadr] == ' ') {
subadr++; subadr++;
cntspace++; cntspace++;
} }
// count subplot if 2+ spaces // count subplot if 2+ spaces
if (cntspace>1) { if (cntspace > 1) {
subcnt++; subcnt++;
} }
} }
// find length of selected subplot title (skip non-space or single space) // find length of selected subplot title (skip non-space or single space)
int sublen = 0; int sublen = 0;
while ((subadr+sublen<1000 && fig->title[subadr+sublen] && fig->title[subadr+sublen]!=' ') || while ((subadr+sublen < 1000 &&
(subadr+sublen+1<1000 && fig->title[subadr+sublen+1] && fig->title[subadr+sublen+1]!=' ')) { fig->title[subadr+sublen] &&
fig->title[subadr+sublen] != ' ') ||
(subadr+sublen+1 < 1000 && fig->title[subadr+sublen+1] &&
fig->title[subadr+sublen+1] != ' ')) {
sublen++; sublen++;
} }
@@ -876,7 +879,7 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
// get title size // get title size
int sx_title = 0; int sx_title = 0;
for (int i=subadr; i<subadr+sublen; i++) { for (int i=subadr; i < subadr+sublen; i++) {
sx_title += con->charWidth[(unsigned char)fig->title[i]]; sx_title += con->charWidth[(unsigned char)fig->title[i]];
} }
@@ -885,15 +888,15 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
// compute left edge and address of extended title // compute left edge and address of extended title
int left1 = left, subadr1 = subadr; int left1 = left, subadr1 = subadr;
while (subadr1>0 && left1>=con->charWidth[(unsigned char)fig->title[subadr1-1]]) { while (subadr1 > 0 && left1 >= con->charWidth[(unsigned char)fig->title[subadr1-1]]) {
left1 -= con->charWidth[(unsigned char)fig->title[subadr1-1]]; left1 -= con->charWidth[(unsigned char)fig->title[subadr1-1]];
subadr1--; subadr1--;
} }
// compute right edge and length of extended title // compute right edge and length of extended title
int sublen1 = 0, right1 = left1; int sublen1 = 0, right1 = left1;
while (sublen1+subadr1<1000 && fig->title[subadr1+sublen1] && while (sublen1+subadr1 < 1000 && fig->title[subadr1+sublen1] &&
right1+con->charWidth[(unsigned char)fig->title[subadr1+sublen1]]<viewport.width) { right1+con->charWidth[(unsigned char)fig->title[subadr1+sublen1]] < viewport.width) {
right1 += con->charWidth[(unsigned char)fig->title[subadr1+sublen1]]; right1 += con->charWidth[(unsigned char)fig->title[subadr1+sublen1]];
sublen1++; sublen1++;
} }
@@ -932,7 +935,7 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
// reduce viewport // reduce viewport
viewport.bottom += (sy_label ? sy_label + PAD/2 : 0); viewport.bottom += (sy_label ? sy_label + PAD/2 : 0);
viewport.height -= (sy_label ? sy_label + PAD/2 : 0) + (sy_title ? sy_title + PAD : 0); viewport.height -= (sy_label ? sy_label + PAD/2 : 0) + (sy_title ? sy_title + PAD : 0);
if (viewport.width<=0 || viewport.height<=0) { if (viewport.width <= 0 || viewport.height <= 0) {
return; return;
} }
glViewport(viewport.left, viewport.bottom, viewport.width, viewport.height); glViewport(viewport.left, viewport.bottom, viewport.width, viewport.height);
@@ -944,7 +947,7 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
} }
// draw optional tick labels, reduce viewport // draw optional tick labels, reduce viewport
if (fig->gridsize[0]>1 && fig->gridsize[1]>1) { if (fig->gridsize[0] > 1 && fig->gridsize[1] > 1) {
char txt[STRING_BUFSIZE]; char txt[STRING_BUFSIZE];
// determine xtick height // determine xtick height
@@ -965,7 +968,7 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
int n = mjMIN(20, fig->gridsize[1]); int n = mjMIN(20, fig->gridsize[1]);
// generate all strings, find max width // generate all strings, find max width
for (int i=0; i<n; i++) { for (int i=0; i < n; i++) {
const int txt_sz = mjSIZEOFARRAY(txt); const int txt_sz = mjSIZEOFARRAY(txt);
maketext(fig->yformat, txt, range[1][0] + (range[1][1]-range[1][0])*i/(float)(n-1), maketext(fig->yformat, txt, range[1][0] + (range[1][1]-range[1][0])*i/(float)(n-1),
txt_sz); txt_sz);
@@ -981,7 +984,7 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
int n = mjMIN(20, fig->gridsize[0]); int n = mjMIN(20, fig->gridsize[0]);
// process ticks // process ticks
for (int i=0; i<n; i++) { for (int i=0; i < n; i++) {
// make text, get width // make text, get width
{ {
const int txt_sz = mjSIZEOFARRAY(txt); const int txt_sz = mjSIZEOFARRAY(txt);
@@ -993,7 +996,7 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
// draw // draw
mjr_textActual(mjFONT_NORMAL, txt, con, mjr_textActual(mjFONT_NORMAL, txt, con,
PAD+ytick_width+ PAD+ytick_width+
(i==0 ? 0 : (i==n-1 ? -w : -w/2))+ (i == 0 ? 0 : (i == n-1 ? -w : -w/2))+
(viewport.width-2*PAD-ytick_width)*i/(float)(n-1), (viewport.width-2*PAD-ytick_width)*i/(float)(n-1),
PAD, 0, PAD, 0,
fig->textrgb[0], fig->textrgb[0], fig->textrgb[0]); fig->textrgb[0], fig->textrgb[0], fig->textrgb[0]);
@@ -1006,7 +1009,7 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
int n = mjMIN(20, fig->gridsize[1]); int n = mjMIN(20, fig->gridsize[1]);
// process ticks // process ticks
for (int i=0; i<n; i++) { for (int i=0; i < n; i++) {
// make text, get width // make text, get width
{ {
const int txt_sz = mjSIZEOFARRAY(txt); const int txt_sz = mjSIZEOFARRAY(txt);
@@ -1036,7 +1039,7 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
viewport.width -= 2*PAD; viewport.width -= 2*PAD;
viewport.bottom += PAD; viewport.bottom += PAD;
viewport.height -= 2*PAD; viewport.height -= 2*PAD;
if (viewport.width<=0 || viewport.height<=0) { if (viewport.width <= 0 || viewport.height <= 0) {
return; return;
} }
glViewport(viewport.left, viewport.bottom, viewport.width, viewport.height); glViewport(viewport.left, viewport.bottom, viewport.width, viewport.height);
@@ -1067,7 +1070,7 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_VERTEX_ARRAY);
// draw grid // draw grid
if (fig->gridsize[0]>1 && fig->gridsize[1]>1) { if (fig->gridsize[0] > 1 && fig->gridsize[1] > 1) {
// common GL state // common GL state
glVertexPointer(2, GL_FLOAT, 0, griddata); glVertexPointer(2, GL_FLOAT, 0, griddata);
glColor3fv(fig->gridrgb); glColor3fv(fig->gridrgb);
@@ -1075,7 +1078,7 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
// prepare vertical lines // prepare vertical lines
int n = mjMIN(20, fig->gridsize[0]); int n = mjMIN(20, fig->gridsize[0]);
for (int i=0; i<n; i++) { for (int i=0; i < n; i++) {
griddata[4*i] = i/(float)(n-1); griddata[4*i] = i/(float)(n-1);
griddata[4*i+1] = 0; griddata[4*i+1] = 0;
griddata[4*i+2] = griddata[4*i]; griddata[4*i+2] = griddata[4*i];
@@ -1087,7 +1090,7 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
// prepare horizontal lines // prepare horizontal lines
n = mjMIN(20, fig->gridsize[1]); n = mjMIN(20, fig->gridsize[1]);
for (int i=0; i<n; i++) { for (int i=0; i < n; i++) {
griddata[4*i] = 0; griddata[4*i] = 0;
griddata[4*i+1] = i/(float)(n-1); griddata[4*i+1] = i/(float)(n-1);
griddata[4*i+2] = 1; griddata[4*i+2] = 1;
@@ -1107,7 +1110,7 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
range[1][0] - dify*offset, range[1][1] + dify*offset, -1, 1); range[1][0] - dify*offset, range[1][1] + dify*offset, -1, 1);
// draw lines: back to front // draw lines: back to front
for (int n=mjMAXLINE-1; n>=0; n--) for (int n=mjMAXLINE-1; n >= 0; n--)
if (fig->linepnt[n]) { if (fig->linepnt[n]) {
// GL state // GL state
glVertexPointer(2, GL_FLOAT, 0, fig->linedata[n]); glVertexPointer(2, GL_FLOAT, 0, fig->linedata[n]);
@@ -1134,14 +1137,14 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
// set matrix projection in pixels // set matrix projection in pixels
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
if (viewport.width<=1 || viewport.height<=1) { if (viewport.width <= 1 || viewport.height <= 1) {
return; return;
} }
glOrtho(0, viewport.width-1, 0, viewport.height-1, -1, 1); glOrtho(0, viewport.width-1, 0, viewport.height-1, -1, 1);
// find legend size // find legend size
int lw = 0, lh = 0, cnt = 0; int lw = 0, lh = 0, cnt = 0;
for (int n=fig->legendoffset; n<mjMAXLINE; n++) { for (int n=fig->legendoffset; n < mjMAXLINE; n++) {
if (fig->linename[n][0]) { if (fig->linename[n][0]) {
// max width, accumulate height // max width, accumulate height
lw = mjMAX(lw, textwidth(con, fig->linename[n])); lw = mjMAX(lw, textwidth(con, fig->linename[n]));
@@ -1151,7 +1154,7 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
cnt++; cnt++;
// too big: correct and break // too big: correct and break
if (lh+2*PAD >=viewport.height) { if (lh+2*PAD >= viewport.height) {
cnt--; cnt--;
lh -= con->charHeight; lh -= con->charHeight;
break; break;
@@ -1163,10 +1166,10 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
int hcnt = -1; int hcnt = -1;
int hx = fig->highlight[0] - viewport.left; int hx = fig->highlight[0] - viewport.left;
int hy = fig->highlight[1] - viewport.bottom; int hy = fig->highlight[1] - viewport.bottom;
if (hx>=viewport.width-PAD-lw && if (hx >= viewport.width-PAD-lw &&
hx<=viewport.width-PAD && hx <= viewport.width-PAD &&
hy>=viewport.height-PAD-lh && hy >= viewport.height-PAD-lh &&
hy<=viewport.height-PAD) { hy <= viewport.height-PAD) {
hcnt = (viewport.height-PAD-hy) / con->charHeight; hcnt = (viewport.height-PAD-hy) / con->charHeight;
} }
@@ -1185,7 +1188,7 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
// find named lines and draw text // find named lines and draw text
cnt = 0; cnt = 0;
for (int n=fig->legendoffset; n<mjMAXLINE; n++) { for (int n=fig->legendoffset; n < mjMAXLINE; n++) {
if (fig->linename[n][0]) { if (fig->linename[n][0]) {
// get width // get width
int width = textwidth(con, fig->linename[n]); int width = textwidth(con, fig->linename[n]);
@@ -1196,7 +1199,7 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
fig->linergb[n][0], fig->linergb[n][1], fig->linergb[n][2]); fig->linergb[n][0], fig->linergb[n][1], fig->linergb[n][2]);
// save hlight // save hlight
if (hcnt==cnt) { if (hcnt == cnt) {
hlight = n; hlight = n;
} }
@@ -1212,7 +1215,7 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
} }
// draw highlight // draw highlight
if (hlight>=0 && hlight<mjMAXLINE) { if (hlight >= 0 && hlight < mjMAXLINE) {
// line-rendering projection // line-rendering projection
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
@@ -1230,8 +1233,8 @@ void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con) {
// find nearest x-value // find nearest x-value
int ibest = -1; int ibest = -1;
float best = 0; float best = 0;
for (int i=0; i<fig->linepnt[hlight]; i++) { for (int i=0; i < fig->linepnt[hlight]; i++) {
if (ibest<0 || best>fabs(fig->selection-fig->linedata[hlight][2*i])) { if (ibest < 0 || best > fabs(fig->selection-fig->linedata[hlight][2*i])) {
ibest = i; ibest = i;
best = fabs(fig->selection-fig->linedata[hlight][2*i]); best = fabs(fig->selection-fig->linedata[hlight][2*i]);
} }
+79 -78
View File
@@ -44,9 +44,9 @@ static int isBehind(const float* headpos, const float* pos, const float* mat) {
// check if geom is reflective // check if geom is reflective
static int isReflective(const mjvGeom* geom) { static int isReflective(const mjvGeom* geom) {
return ((geom->type==mjGEOM_PLANE || geom->type==mjGEOM_BOX) && return ((geom->type == mjGEOM_PLANE || geom->type == mjGEOM_BOX) &&
!geom->transparent && !geom->transparent &&
(geom->reflectance>0)); (geom->reflectance > 0));
} }
@@ -64,7 +64,7 @@ static void settexture(int type, int state, const mjrContext* con, const mjvGeom
float plane[4], scl[2]; float plane[4], scl[2];
// shadow // shadow
if (type==mjtexSHADOW) { if (type == mjtexSHADOW) {
// enable // enable
if (state) { if (state) {
glActiveTexture(GL_TEXTURE1); glActiveTexture(GL_TEXTURE1);
@@ -88,7 +88,7 @@ static void settexture(int type, int state, const mjrContext* con, const mjvGeom
} }
// explicit texture coordinates // explicit texture coordinates
else if (type==mjtexREGULAR && geom->texcoord) { else if (type == mjtexREGULAR && geom->texcoord) {
// enable // enable
if (state) { if (state) {
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
@@ -104,7 +104,7 @@ static void settexture(int type, int state, const mjrContext* con, const mjvGeom
} }
// 2D // 2D
else if (type==mjtexREGULAR && con->textureType[geom->texid]==mjTEXTURE_2D) { else if (type == mjtexREGULAR && con->textureType[geom->texid] == mjTEXTURE_2D) {
// enable // enable
if (state) { if (state) {
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
@@ -116,23 +116,23 @@ static void settexture(int type, int state, const mjrContext* con, const mjvGeom
// determine scaling, adjust for pre-scaled geoms // determine scaling, adjust for pre-scaled geoms
scl[0] = geom->texrepeat[0]; scl[0] = geom->texrepeat[0];
scl[1] = geom->texrepeat[1]; scl[1] = geom->texrepeat[1];
if (geom->dataid>=0) { if (geom->dataid >= 0) {
if (geom->size[0]>0) { if (geom->size[0] > 0) {
scl[0] = scl[0] / mju_max(mjMINVAL, geom->size[0]); scl[0] = scl[0] / mju_max(mjMINVAL, geom->size[0]);
} }
if (geom->size[1]>0) { if (geom->size[1] > 0) {
scl[1] = scl[1] / mju_max(mjMINVAL, geom->size[1]); scl[1] = scl[1] / mju_max(mjMINVAL, geom->size[1]);
} }
} }
// uniform: repeat relative to spatial units rather than object // uniform: repeat relative to spatial units rather than object
if (geom->texuniform) { if (geom->texuniform) {
if (geom->size[0]>0) { if (geom->size[0] > 0) {
scl[0] = scl[0] * geom->size[0]; scl[0] = scl[0] * geom->size[0];
} }
if (geom->size[1]>0) { if (geom->size[1] > 0) {
scl[1] = scl[1] * geom->size[1]; scl[1] = scl[1] * geom->size[1];
} }
} }
@@ -165,7 +165,7 @@ static void settexture(int type, int state, const mjrContext* con, const mjvGeom
glBindTexture(GL_TEXTURE_CUBE_MAP, con->texture[geom->texid]); glBindTexture(GL_TEXTURE_CUBE_MAP, con->texture[geom->texid]);
// set mapping : cube // set mapping : cube
if (type==mjtexREGULAR) { if (type == mjtexREGULAR) {
mjr_setf4(plane, geom->texuniform ? geom->size[0] : 1, 0, 0, 0); mjr_setf4(plane, geom->texuniform ? geom->size[0] : 1, 0, 0, 0);
glTexGenfv(GL_S, GL_OBJECT_PLANE, plane); glTexGenfv(GL_S, GL_OBJECT_PLANE, plane);
mjr_setf4(plane, 0, geom->texuniform ? geom->size[1] : 1, 0, 0); mjr_setf4(plane, 0, geom->texuniform ? geom->size[1] : 1, 0, 0);
@@ -217,7 +217,7 @@ static void renderGeom(const mjvGeom* geom, int mode, const float* headpos,
int behind, whichface, lighting; int behind, whichface, lighting;
// lines to do not cast shadows // lines to do not cast shadows
if (mode==mjrRND_SHADOWCAST && geom->type==mjGEOM_LINE) { if (mode == mjrRND_SHADOWCAST && geom->type == mjGEOM_LINE) {
return; return;
} }
@@ -233,18 +233,18 @@ static void renderGeom(const mjvGeom* geom, int mode, const float* headpos,
behind = isBehind(headpos, geom->pos, geom->mat); behind = isBehind(headpos, geom->pos, geom->mat);
// enable texture in normal and shadowmap mode // enable texture in normal and shadowmap mode
if (geom->texid>=0 && con->ntexture>0 && if (geom->texid >= 0 && con->ntexture > 0 &&
(mode==mjrRND_NORMAL || mode==mjrRND_SHADOWMAP)) { (mode == mjrRND_NORMAL || mode == mjrRND_SHADOWMAP)) {
settexture(mjtexREGULAR, 1, con, geom); settexture(mjtexREGULAR, 1, con, geom);
} }
// make plane more transparent from the back // make plane more transparent from the back
if (geom->type==mjGEOM_PLANE && behind && mode==mjrRND_NORMAL) { if (geom->type == mjGEOM_PLANE && behind && mode == mjrRND_NORMAL) {
rgba[3] *= 0.3; rgba[3] *= 0.3;
} }
// set material emission: none in shadow mode // set material emission: none in shadow mode
if (mode==mjrRND_NORMAL) { if (mode == mjrRND_NORMAL) {
mjr_setf4(temp, mjr_setf4(temp,
geom->emission*rgba[0], geom->emission*rgba[0],
geom->emission*rgba[1], geom->emission*rgba[1],
@@ -261,9 +261,9 @@ static void renderGeom(const mjvGeom* geom, int mode, const float* headpos,
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, temp); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, temp);
// set color for segmentation mode // set color for segmentation mode
if (mode>=mjrRND_SEGMENT) { if (mode >= mjrRND_SEGMENT) {
// segid color // segid color
if (mode==mjrRND_IDCOLOR) { if (mode == mjrRND_IDCOLOR) {
unsigned char seg[4] = { unsigned char seg[4] = {
(geom->segid+1) & 0xFF, (geom->segid+1) & 0xFF,
((geom->segid+1)>>8) & 0xFF, ((geom->segid+1)>>8) & 0xFF,
@@ -287,7 +287,7 @@ static void renderGeom(const mjvGeom* geom, int mode, const float* headpos,
// apply coordinate transformation, except for skin which is global // apply coordinate transformation, except for skin which is global
glPushMatrix(); glPushMatrix();
if (geom->type!=mjGEOM_SKIN) { if (geom->type != mjGEOM_SKIN) {
glTranslatef(geom->pos[0], geom->pos[1], geom->pos[2]); glTranslatef(geom->pos[0], geom->pos[1], geom->pos[2]);
glMultMatrixf(mat); glMultMatrixf(mat);
} }
@@ -297,13 +297,13 @@ static void renderGeom(const mjvGeom* geom, int mode, const float* headpos,
case mjGEOM_PLANE: // plane case mjGEOM_PLANE: // plane
if (behind) { if (behind) {
glGetIntegerv(GL_CULL_FACE_MODE, &whichface); glGetIntegerv(GL_CULL_FACE_MODE, &whichface);
if (whichface==GL_BACK) { if (whichface == GL_BACK) {
glCullFace(GL_FRONT); glCullFace(GL_FRONT);
} }
} }
// use plane-specific displaylist if available // use plane-specific displaylist if available
if (geom->dataid>=0) { if (geom->dataid >= 0) {
glCallList(con->basePlane + geom->dataid+1); glCallList(con->basePlane + geom->dataid+1);
} }
@@ -313,13 +313,13 @@ static void renderGeom(const mjvGeom* geom, int mode, const float* headpos,
glCallList(con->basePlane); glCallList(con->basePlane);
} }
if (behind && whichface==GL_BACK) { if (behind && whichface == GL_BACK) {
glCullFace(GL_BACK); glCullFace(GL_BACK);
} }
break; break;
case mjGEOM_HFIELD: // height field case mjGEOM_HFIELD: // height field
if (geom->dataid>=0) { if (geom->dataid >= 0) {
glCallList(con->baseHField + geom->dataid); glCallList(con->baseHField + geom->dataid);
} }
break; break;
@@ -356,7 +356,7 @@ static void renderGeom(const mjvGeom* geom, int mode, const float* headpos,
break; break;
case mjGEOM_MESH: // mesh case mjGEOM_MESH: // mesh
if (geom->dataid>=0) { if (geom->dataid >= 0) {
glCallList(con->baseMesh + geom->dataid); glCallList(con->baseMesh + geom->dataid);
} }
break; break;
@@ -443,8 +443,8 @@ static void renderGeom(const mjvGeom* geom, int mode, const float* headpos,
glPopMatrix(); glPopMatrix();
// disable texture if enabled // disable texture if enabled
if (geom->texid>=0 && con->ntexture>0 && if (geom->texid >= 0 && con->ntexture > 0 &&
(mode==mjrRND_NORMAL || mode==mjrRND_SHADOWMAP)) { (mode == mjrRND_NORMAL || mode == mjrRND_SHADOWMAP)) {
settexture(mjtexREGULAR, 0, con, geom); settexture(mjtexREGULAR, 0, con, geom);
} }
} }
@@ -456,7 +456,7 @@ void renderGeomReflection(int id, float reflectance, float headpos[3],
float old_rgb[3]; float old_rgb[3];
// save rgb, modulate rgb by this->reflectance // save rgb, modulate rgb by this->reflectance
for (int k=0; k<3; k++) { for (int k=0; k < 3; k++) {
old_rgb[k] = scn->geoms[id].rgba[k]; old_rgb[k] = scn->geoms[id].rgba[k];
scn->geoms[id].rgba[k] *= reflectance; scn->geoms[id].rgba[k] *= reflectance;
} }
@@ -465,7 +465,7 @@ void renderGeomReflection(int id, float reflectance, float headpos[3],
renderGeom(scn->geoms+id, mjrRND_NORMAL, headpos, scn, con); renderGeom(scn->geoms+id, mjrRND_NORMAL, headpos, scn, con);
// restore rgb // restore rgb
for (int k=0; k<3; k++) { for (int k=0; k < 3; k++) {
scn->geoms[id].rgba[k] = old_rgb[k]; scn->geoms[id].rgba[k] = old_rgb[k];
} }
} }
@@ -532,14 +532,14 @@ static void initLights(mjvScene* scn, const float* headpos, const float* gazedir
// headlight: set pos and dir // headlight: set pos and dir
if (scn->lights[0].headlight) { if (scn->lights[0].headlight) {
for (int i=0; i<3; i++) { for (int i=0; i < 3; i++) {
scn->lights[0].pos[i] = headpos[i]; scn->lights[0].pos[i] = headpos[i];
scn->lights[0].dir[i] = gazedir[i]; scn->lights[0].dir[i] = gazedir[i];
} }
} }
// set light properties // set light properties
for (int i=0; i<scn->nlight; i++) { for (int i=0; i < scn->nlight; i++) {
// colors // colors
glLightfv(GL_LIGHT0+i, GL_AMBIENT, scn->lights[i].ambient); glLightfv(GL_LIGHT0+i, GL_AMBIENT, scn->lights[i].ambient);
glLightfv(GL_LIGHT0+i, GL_DIFFUSE, scn->lights[i].diffuse); glLightfv(GL_LIGHT0+i, GL_DIFFUSE, scn->lights[i].diffuse);
@@ -565,7 +565,7 @@ static void initLights(mjvScene* scn, const float* headpos, const float* gazedir
} }
// disable all lights (enable selectively in render) // disable all lights (enable selectively in render)
for (int i=0; i<scn->nlight; i++) { for (int i=0; i < scn->nlight; i++) {
glDisable(GL_LIGHT0+i); glDisable(GL_LIGHT0+i);
} }
} }
@@ -578,7 +578,7 @@ static void setView(int view, mjrRect viewport, const mjvScene* scn, const mjrCo
mjvGLCamera cam; mjvGLCamera cam;
// copy specified camera for stereo, average for mono (view = -1) // copy specified camera for stereo, average for mono (view = -1)
if (view>=0) { if (view >= 0) {
cam = scn->camera[view]; cam = scn->camera[view];
} else { } else {
cam = mjv_averageCamera(scn->camera, scn->camera+1); cam = mjv_averageCamera(scn->camera, scn->camera+1);
@@ -674,7 +674,7 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
mjvLight *thislight; mjvLight *thislight;
// empty viewport: nothing to do // empty viewport: nothing to do
if (viewport.width<=0 || viewport.height<=0) { if (viewport.width <= 0 || viewport.height <= 0) {
return; return;
} }
@@ -682,7 +682,7 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
cam = mjv_averageCamera(scn->camera, scn->camera+1); cam = mjv_averageCamera(scn->camera, scn->camera+1);
// check znear // check znear
if (cam.frustum_near<mjMINVAL) { if (cam.frustum_near < mjMINVAL) {
// geoms: error // geoms: error
if (scn->ngeom) { if (scn->ngeom) {
mju_error("mjvScene frustum_near too small in mjr_render"); mju_error("mjvScene frustum_near too small in mjr_render");
@@ -695,7 +695,7 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
} }
// upload dynamic skin data to GPU // upload dynamic skin data to GPU
for (int i=0; i<scn->nskin; i++) { for (int i=0; i < scn->nskin; i++) {
// upload positions to VBO // upload positions to VBO
glBindBuffer(GL_ARRAY_BUFFER, con->skinvertVBO[i]); glBindBuffer(GL_ARRAY_BUFFER, con->skinvertVBO[i]);
glBufferData(GL_ARRAY_BUFFER, glBufferData(GL_ARRAY_BUFFER,
@@ -712,7 +712,7 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
} }
// determine drawbuffer; may be changed by stereo later // determine drawbuffer; may be changed by stereo later
if (con->currentBuffer==mjFB_WINDOW) { if (con->currentBuffer == mjFB_WINDOW) {
drawbuffer = (con->windowDoublebuffer ? GL_BACK : GL_FRONT); drawbuffer = (con->windowDoublebuffer ? GL_BACK : GL_FRONT);
} else { } else {
drawbuffer = GL_COLOR_ATTACHMENT0; drawbuffer = GL_COLOR_ATTACHMENT0;
@@ -728,12 +728,12 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
// make list of transparent geoms // make list of transparent geoms
nt = 0; nt = 0;
for (int i=0; i<ngeom; i++) { for (int i=0; i < ngeom; i++) {
// get geom pointer // get geom pointer
thisgeom = scn->geoms + i; thisgeom = scn->geoms + i;
if (thisgeom->rgba[3]<0.995 || (thisgeom->type==mjGEOM_PLANE && if (thisgeom->rgba[3] < 0.995 || (thisgeom->type == mjGEOM_PLANE &&
isBehind(headpos, thisgeom->pos, thisgeom->mat))) { isBehind(headpos, thisgeom->pos, thisgeom->mat))) {
// include index in list // include index in list
scn->geomorder[nt++] = i; scn->geomorder[nt++] = i;
thisgeom->transparent = 1; thisgeom->transparent = 1;
@@ -747,7 +747,7 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
thisgeom->camdist -= mjv_rbound(thisgeom); thisgeom->camdist -= mjv_rbound(thisgeom);
// plane always far away // plane always far away
if (thisgeom->type==mjGEOM_PLANE) { if (thisgeom->type == mjGEOM_PLANE) {
thisgeom->camdist = 1E+10; thisgeom->camdist = 1E+10;
} }
} else { } else {
@@ -760,7 +760,7 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
// allow only one reflective geom // allow only one reflective geom
int j = 0; int j = 0;
for (int i=0; i<ngeom; i++) { for (int i=0; i < ngeom; i++) {
if (j) { if (j) {
scn->geoms[i].reflectance = 0; scn->geoms[i].reflectance = 0;
} else if (isReflective(scn->geoms + i)) { } else if (isReflective(scn->geoms + i)) {
@@ -782,19 +782,20 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
// determine stereo; quadbuffered reverts to sidebyside if hardware not available // determine stereo; quadbuffered reverts to sidebyside if hardware not available
stereo = scn->stereo; stereo = scn->stereo;
if (stereo==mjSTEREO_QUADBUFFERED && (con->currentBuffer!=mjFB_WINDOW || !con->windowStereo)) { if (stereo == mjSTEREO_QUADBUFFERED &&
(con->currentBuffer != mjFB_WINDOW || !con->windowStereo)) {
stereo = mjSTEREO_SIDEBYSIDE; stereo = mjSTEREO_SIDEBYSIDE;
} }
// SIDEBYSIDE: reduce viewport // SIDEBYSIDE: reduce viewport
if (stereo==mjSTEREO_SIDEBYSIDE) { if (stereo == mjSTEREO_SIDEBYSIDE) {
viewport.width /= 2; viewport.width /= 2;
} }
// render with stereo // render with stereo
for (int view=(stereo?0:-1); view<(stereo?2:0); view++) { for (int view=(stereo?0:-1); view < (stereo?2:0); view++) {
// change drawbuffer for QUADBUFFERED stereo // change drawbuffer for QUADBUFFERED stereo
if (stereo==mjSTEREO_QUADBUFFERED) { if (stereo == mjSTEREO_QUADBUFFERED) {
if (con->windowDoublebuffer) { if (con->windowDoublebuffer) {
drawbuffer = (view ? GL_BACK_RIGHT : GL_BACK_LEFT); drawbuffer = (view ? GL_BACK_RIGHT : GL_BACK_LEFT);
} else { } else {
@@ -809,7 +810,7 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
} }
// change viewport for SIDEBYSIDE stereo // change viewport for SIDEBYSIDE stereo
else if (stereo==mjSTEREO_SIDEBYSIDE) { else if (stereo == mjSTEREO_SIDEBYSIDE) {
// move viewport to the right for view 1 // move viewport to the right for view 1
if (view) { if (view) {
viewport.left += viewport.width; viewport.left += viewport.width;
@@ -834,8 +835,8 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
glDisable(GL_MULTISAMPLE); glDisable(GL_MULTISAMPLE);
// render all geoms // render all geoms
for (int i=0; i<ngeom; i++) { for (int i=0; i < ngeom; i++) {
if (scn->geoms[i].segid>=0) { if (scn->geoms[i].segid >= 0) {
renderGeom(scn->geoms+i, renderGeom(scn->geoms+i,
scn->flags[mjRND_IDCOLOR] ? mjrRND_IDCOLOR : mjrRND_SEGMENT, scn->flags[mjRND_IDCOLOR] ? mjrRND_IDCOLOR : mjrRND_SEGMENT,
headpos, scn, con); headpos, scn, con);
@@ -850,13 +851,13 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
// plane and box reflection rendering // plane and box reflection rendering
if (scn->flags[mjRND_REFLECTION]) { if (scn->flags[mjRND_REFLECTION]) {
for (int i=0; i<ngeom; i++) { for (int i=0; i < ngeom; i++) {
// get geom pointer // get geom pointer
thisgeom = scn->geoms + i; thisgeom = scn->geoms + i;
if (isReflective(thisgeom)) { if (isReflective(thisgeom)) {
// if box, replace with temporary plane matching Z+ box side // if box, replace with temporary plane matching Z+ box side
if (thisgeom->type==mjGEOM_BOX) { if (thisgeom->type == mjGEOM_BOX) {
// copy and convert to plane // copy and convert to plane
tempgeom = *thisgeom; tempgeom = *thisgeom;
tempgeom.type = mjGEOM_PLANE; tempgeom.type = mjGEOM_PLANE;
@@ -911,14 +912,14 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
mjr_reflect(thisgeom->pos, thisgeom->mat); mjr_reflect(thisgeom->pos, thisgeom->mat);
// set light position and direction, enable // set light position and direction, enable
for (int j=0; j<nlight; j++) { for (int j=0; j < nlight; j++) {
adjustLight(scn->lights+j, j); adjustLight(scn->lights+j, j);
glEnable(GL_LIGHT0+j); glEnable(GL_LIGHT0+j);
} }
// render reflected non-transparent geoms, except for thisgeom // render reflected non-transparent geoms, except for thisgeom
for (int j=0; j<ngeom; j++) { for (int j=0; j < ngeom; j++) {
if (!scn->geoms[j].transparent && i!=j) { if (!scn->geoms[j].transparent && i != j) {
renderGeomReflection(j, thisgeom->reflectance, headpos, scn, con); renderGeomReflection(j, thisgeom->reflectance, headpos, scn, con);
} }
} }
@@ -931,14 +932,14 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
} else { } else {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
} }
for (int j=0; j<nt; j++) { for (int j=0; j < nt; j++) {
if (i!=scn->geomorder[j]) { if (i != scn->geomorder[j]) {
renderGeomReflection(scn->geomorder[j], thisgeom->reflectance, headpos, scn, con); renderGeomReflection(scn->geomorder[j], thisgeom->reflectance, headpos, scn, con);
} }
} }
if (!scn->flags[mjRND_ADDITIVE]) { if (!scn->flags[mjRND_ADDITIVE]) {
for (int j=nt-1; j>=0; j--) { for (int j=nt-1; j >= 0; j--) {
if (i!=scn->geomorder[j]) { if (i != scn->geomorder[j]) {
renderGeomReflection(scn->geomorder[j], thisgeom->reflectance, headpos, scn, con); renderGeomReflection(scn->geomorder[j], thisgeom->reflectance, headpos, scn, con);
} }
} }
@@ -947,7 +948,7 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
glDisable(GL_BLEND); glDisable(GL_BLEND);
// disable lights // disable lights
for (int j=0; j<nlight; j++) { for (int j=0; j < nlight; j++) {
glDisable(GL_LIGHT0+j); glDisable(GL_LIGHT0+j);
} }
@@ -963,7 +964,7 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
//---------------------------------- regular rendering //---------------------------------- regular rendering
// set light position and direction, enable non-shadow lights // set light position and direction, enable non-shadow lights
for (int i=0; i<nlight; i++) { for (int i=0; i < nlight; i++) {
// set light // set light
thislight = scn->lights + i; thislight = scn->lights + i;
adjustLight(thislight, i); adjustLight(thislight, i);
@@ -978,21 +979,21 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
// (only one allowed, more would result in weird transparency) // (only one allowed, more would result in weird transparency)
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE); glBlendFunc(GL_ONE, GL_ONE);
for (int i=0; i<ngeom; i++) for (int i=0; i < ngeom; i++)
if (isReflective(scn->geoms+i)) { if (isReflective(scn->geoms+i)) {
renderGeom(scn->geoms+i, mjrRND_NORMAL, headpos, scn, con); renderGeom(scn->geoms+i, mjrRND_NORMAL, headpos, scn, con);
} }
glDisable(GL_BLEND); glDisable(GL_BLEND);
// render remaining opaque geoms // render remaining opaque geoms
for (int i=0; i<ngeom; i++) { for (int i=0; i < ngeom; i++) {
if (!scn->geoms[i].transparent && !isReflective(scn->geoms+i)) { if (!scn->geoms[i].transparent && !isReflective(scn->geoms+i)) {
renderGeom(scn->geoms+i, mjrRND_NORMAL, headpos, scn, con); renderGeom(scn->geoms+i, mjrRND_NORMAL, headpos, scn, con);
} }
} }
// disable lights // disable lights
for (int i=0; i<nlight; i++) { for (int i=0; i < nlight; i++) {
glDisable(GL_LIGHT0+i); glDisable(GL_LIGHT0+i);
} }
@@ -1004,7 +1005,7 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
// shadow map rendering // shadow map rendering
if (scn->flags[mjRND_SHADOW] && con->shadowFBO) { if (scn->flags[mjRND_SHADOW] && con->shadowFBO) {
for (int i=0; i<nlight; i++) { for (int i=0; i < nlight; i++) {
// get pointer // get pointer
thislight = scn->lights + i; thislight = scn->lights + i;
@@ -1042,13 +1043,13 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
glColorMask(0, 0, 0, 0); glColorMask(0, 0, 0, 0);
// render all geoms to depth texture // render all geoms to depth texture
for (int j=0; j<ngeom; j++) { for (int j=0; j < ngeom; j++) {
renderGeom(scn->geoms+j, mjrRND_SHADOWCAST, headpos, scn, con); renderGeom(scn->geoms+j, mjrRND_SHADOWCAST, headpos, scn, con);
} }
// restore OpenGL settings // restore OpenGL settings
glBindFramebuffer(GL_FRAMEBUFFER, glBindFramebuffer(GL_FRAMEBUFFER,
con->currentBuffer==mjFB_WINDOW ? 0 : con->offFBO); con->currentBuffer == mjFB_WINDOW ? 0 : con->offFBO);
glDrawBuffer(drawbuffer); glDrawBuffer(drawbuffer);
glViewport(viewport.left, viewport.bottom, viewport.width, viewport.height); glViewport(viewport.left, viewport.bottom, viewport.width, viewport.height);
glCullFace(GL_BACK); glCullFace(GL_BACK);
@@ -1082,7 +1083,7 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
glEnable(GL_LIGHT0+i); glEnable(GL_LIGHT0+i);
// only opaque geoms accept shadows // only opaque geoms accept shadows
for (int j=0; j<ngeom; j++) { for (int j=0; j < ngeom; j++) {
if (!scn->geoms[j].transparent) { if (!scn->geoms[j].transparent) {
renderGeom(scn->geoms+j, mjrRND_SHADOWMAP, headpos, scn, con); renderGeom(scn->geoms+j, mjrRND_SHADOWMAP, headpos, scn, con);
} }
@@ -1108,8 +1109,8 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
// find skybox texture // find skybox texture
for (int i=0; i<con->ntexture; i++) { for (int i=0; i < con->ntexture; i++) {
if (con->textureType[i]==mjTEXTURE_SKYBOX) { if (con->textureType[i] == mjTEXTURE_SKYBOX) {
// save first skybox texture id in tempgeom // save first skybox texture id in tempgeom
memset(&tempgeom, 0, sizeof(mjvGeom)); memset(&tempgeom, 0, sizeof(mjvGeom));
tempgeom.texid = i; tempgeom.texid = i;
@@ -1136,10 +1137,10 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
// haze // haze
if (scn->flags[mjRND_HAZE]) { if (scn->flags[mjRND_HAZE]) {
for (int j=0; j<ngeom; j++) { for (int j=0; j < ngeom; j++) {
if (scn->geoms[j].type==mjGEOM_PLANE && if (scn->geoms[j].type == mjGEOM_PLANE &&
scn->geoms[j].size[0]==0 && scn->geoms[j].size[0] == 0 &&
scn->geoms[j].size[1]==0) { scn->geoms[j].size[1] == 0) {
// compute headpos elevation above plane // compute headpos elevation above plane
float* mat3 = scn->geoms[j].mat; float* mat3 = scn->geoms[j].mat;
float elevation = ((headpos[0]-scn->geoms[j].pos[0])*mat3[2] + float elevation = ((headpos[0]-scn->geoms[j].pos[0])*mat3[2] +
@@ -1148,7 +1149,7 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
skyboxdst; skyboxdst;
// below plane: no rendering // below plane: no rendering
if (elevation<0) { if (elevation < 0) {
break; break;
} }
@@ -1195,7 +1196,7 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
//------------------------------------ transparent regular rendering //------------------------------------ transparent regular rendering
// enable lights // enable lights
for (int i=0; i<nlight; i++) { for (int i=0; i < nlight; i++) {
glEnable(GL_LIGHT0+i); glEnable(GL_LIGHT0+i);
} }
@@ -1209,13 +1210,13 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
} }
// render transparent geoms: front to back // render transparent geoms: front to back
for (int i=0; i<nt; i++) { for (int i=0; i < nt; i++) {
renderGeom(scn->geoms+scn->geomorder[i], mjrRND_NORMAL, headpos, scn, con); renderGeom(scn->geoms+scn->geomorder[i], mjrRND_NORMAL, headpos, scn, con);
} }
// render transparent geoms: back to front, if not additive // render transparent geoms: back to front, if not additive
if (!scn->flags[mjRND_ADDITIVE]) { if (!scn->flags[mjRND_ADDITIVE]) {
for (int i=nt-1; i>=0; i--) { for (int i=nt-1; i >= 0; i--) {
renderGeom(scn->geoms+scn->geomorder[i], mjrRND_NORMAL, headpos, scn, con); renderGeom(scn->geoms+scn->geomorder[i], mjrRND_NORMAL, headpos, scn, con);
} }
} }
@@ -1225,7 +1226,7 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
glDisable(GL_BLEND); glDisable(GL_BLEND);
// disable lights // disable lights
for (int i=0; i<nlight; i++) { for (int i=0; i < nlight; i++) {
glDisable(GL_LIGHT0+i); glDisable(GL_LIGHT0+i);
} }
@@ -1234,7 +1235,7 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
// render text labels if present // render text labels if present
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING); glDisable(GL_LIGHTING);
for (int i=0; i<ngeom; i++) { for (int i=0; i < ngeom; i++) {
thisgeom = scn->geoms + i; thisgeom = scn->geoms + i;
if (thisgeom->label[0]) { if (thisgeom->label[0]) {
+14 -14
View File
@@ -54,10 +54,10 @@ void mjr_setf3(float* vec, float f0, float f1, float f2) {
// multiply 4-by-4 matrices, column-major // multiply 4-by-4 matrices, column-major
void mjr_mulMat44(float* res, const float* A, const float* B) { void mjr_mulMat44(float* res, const float* A, const float* B) {
for (int r=0; r<4; r++) { for (int r=0; r < 4; r++) {
for (int c=0; c<4; c++) { for (int c=0; c < 4; c++) {
res[r+4*c] = 0; res[r+4*c] = 0;
for (int i=0; i<4; i++) { for (int i=0; i < 4; i++) {
res[r+4*c] += A[r+4*i]*B[i+4*c]; res[r+4*c] += A[r+4*i]*B[i+4*c];
} }
} }
@@ -89,7 +89,7 @@ void mjr_crossVec(float* a, const float* b, const float* c) {
void mjr_normalizeVec(float* v) { void mjr_normalizeVec(float* v) {
float scl, len = sqrtf(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]); float scl, len = sqrtf(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
if (len<1E-10f) { if (len < 1E-10f) {
v[0] = 0; v[0] = 0;
v[1] = 0; v[1] = 0;
v[2] = 1; v[2] = 1;
@@ -111,7 +111,7 @@ void mjr_orthoVec(float* res, const float* v) {
mjr_crossVec(res, v, other); mjr_crossVec(res, v, other);
// success // success
if (res[0]*res[0]+res[1]*res[1]+res[2]*res[2]>0.01) { if (res[0]*res[0]+res[1]*res[1]+res[2]*res[2] > 0.01) {
mjr_normalizeVec(res); mjr_normalizeVec(res);
return; return;
} }
@@ -134,9 +134,9 @@ float mjr_dotVec(const float* a, const float* b) {
// multiply 4x4 matrix by vector; column-major (OpenGL format) // multiply 4x4 matrix by vector; column-major (OpenGL format)
void mjr_multiply4(float* res, const float* mat, const float* vec) { void mjr_multiply4(float* res, const float* mat, const float* vec) {
for (int i=0; i<4; i++) { for (int i=0; i < 4; i++) {
res[i] = 0; res[i] = 0;
for (int j=0; j<4; j++) { for (int j=0; j < 4; j++) {
res[i] += mat[i+4*j]*vec[j]; res[i] += mat[i+4*j]*vec[j];
} }
} }
@@ -207,8 +207,8 @@ void mjr_reflect(const float* pos, const float* mat) {
v[2] = mat[8]; v[2] = mat[8];
// compute outer product v*vT // compute outer product v*vT
for (int i=0; i<3; i++) { for (int i=0; i < 3; i++) {
for (int j=0; j<3; j++) { for (int j=0; j < 3; j++) {
vvt[3*i+j] = v[i]*v[j]; vvt[3*i+j] = v[i]*v[j];
} }
} }
@@ -273,11 +273,11 @@ void mjr_transform(const float* translate, const float* rotate, float scale) {
// Find first rectangle containing mouse, -1: not found. // Find first rectangle containing mouse, -1: not found.
int mjr_findRect(int x, int y, int nrect, const mjrRect* rect) { int mjr_findRect(int x, int y, int nrect, const mjrRect* rect) {
// scan // scan
for (int i=0; i<nrect; i++) { for (int i=0; i < nrect; i++) {
if (x>=rect[i].left && if (x >= rect[i].left &&
x<rect[i].left+rect[i].width && x < rect[i].left+rect[i].width &&
y>=rect[i].bottom && y >= rect[i].bottom &&
y<rect[i].bottom+rect[i].height) { y < rect[i].bottom+rect[i].height) {
return i; return i;
} }
} }
+252 -247
View File
File diff suppressed because it is too large Load Diff