void SinWaveObject::MakeCircle(TimeValue t, Mesh &mesh, int startVert, int& face, float radius, float a1,float a2,float w,float s, float d, int numCircleSegs) { float x, y, z, u, u2; for ( int i = startVert; i < startVert+numCircleSegs; i++ ) { u = float(i-startVert) / float(numCircleSegs); x = radius * (float)cos( u * TWOPI ); y = radius * (float)sin( u * TWOPI ); u2 = (u > 0.5f) ? (u-0.5f) : u; u2 = (u2 > 0.25f) ? (0.5f-u2) : u2; u2 = u2 * 4.0f; u2 = u2*u2; z = WaveFunc(radius, t, a1*(1.0f-u2) + a2*u2, w, s, d); if ( startVert == 0 ) { mesh.setVert( i+1, Point3(x, y, z) ); } else { mesh.setVert( numCircleSegs + i, Point3(x, y, z) ); if ( i < startVert+numCircleSegs-1 ) { MakeQuad(&(mesh.faces[face]), i+numCircleSegs,i+numCircleSegs+1,i+1,i,1); face += 2; } else { MakeQuad(&(mesh.faces[face]), i+numCircleSegs,startVert+numCircleSegs,startVert,i,1); face += 2; } } } }
void LinWaveObject::BuildMesh(TimeValue t) { int startVert = 1, face = 0, nverts, nfaces, numSides, numSegs, divs; float radius = float(0); float dx, dy, starty, startx; float a, a2, w, s, d, x, y, z, u; int nv=0, nf=0, ix, den; ivalid = FOREVER; pblock->GetValue(PB_AMPLITUDE,t,a,ivalid); pblock->GetValue(PB_AMPLITUDE2,t,a2,ivalid); pblock->GetValue(PB_WAVELEN,t,w,ivalid); pblock->GetValue(PB_PHASE,t,s,ivalid); pblock->GetValue(PB_DECAY,t,d,ivalid); pblock->GetValue(PB_SEGMENTS,t,numSegs,ivalid); pblock->GetValue(PB_CIRCLES,t,numSides,ivalid); pblock->GetValue(PB_DIVISIONS,t,divs,ivalid); LimitValue(d,0.0f,float(1.0E30)); dy = w/float(divs); dx = dy * 4; starty = -float(numSegs)/2.0f * dy; startx = -float(numSides)/2.0f * dx; nverts = (numSides+1) * (numSegs+1); nfaces = (numSides) * numSegs * 2; mesh.setNumVerts(nverts); mesh.setNumFaces(nfaces); for (int i=0; i<=numSides; i++) { x = startx + dx * float(i); den = (int)(dx*numSides*0.5f); u = (float)fabs(x/(den?den:0.00001f)); u = u*u; //u = smoothstep(0.0f,1.0f,u); for (int j=0; j<=numSegs; j++) { y = starty + float(j) * dy; z = WaveFunc(y, t, a*(1.0f-u)+a2*u, w, s, d); mesh.setVert(nv++,Point3(x, y, z)); } } for (i=0; i<numSides; i++) { ix = i * (numSegs+1); for (int j=0; j<numSegs; j++) { MakeQuad(&(mesh.faces[nf]), ix+numSegs+1+j, ix+numSegs+2+j, ix+1+j, ix+j, 1); nf += 2; } } assert(nv==mesh.numVerts); assert(nf==mesh.numFaces); mesh.InvalidateGeomCache(); }
void TargetObject::BuildMesh() { int nverts = 8; int nfaces = 12; Point3 va(-sz,-sz,-sz); Point3 vb( sz, sz, sz); mesh.setNumVerts(nverts); mesh.setNumFaces(nfaces); mesh.setVert(0, Point3( va.x, va.y, va.z)); mesh.setVert(1, Point3( vb.x, va.y, va.z)); mesh.setVert(2, Point3( va.x, vb.y, va.z)); mesh.setVert(3, Point3( vb.x, vb.y, va.z)); mesh.setVert(4, Point3( va.x, va.y, vb.z)); mesh.setVert(5, Point3( vb.x, va.y, vb.z)); mesh.setVert(6, Point3( va.x, vb.y, vb.z)); mesh.setVert(7, Point3( vb.x, vb.y, vb.z)); MakeQuad(&(mesh.faces[ 0]), 0,2,3,1, 1); MakeQuad(&(mesh.faces[ 2]), 2,0,4,6, 2); MakeQuad(&(mesh.faces[ 4]), 3,2,6,7, 4); MakeQuad(&(mesh.faces[ 6]), 1,3,7,5, 8); MakeQuad(&(mesh.faces[ 8]), 0,1,5,4, 16); MakeQuad(&(mesh.faces[10]), 4,5,7,6, 32); mesh.buildNormals(); mesh.EnableEdgeList(1); }
void CParticleSystemLibrary::Render() { TPROF("CParticleSystemLibrary::Render"); if (!r_particles.GetBool()) return; MakeQuad(); CParticleSystemLibrary* pPSL = Get(); if (!pPSL->m_apInstances.size()) return; tmap<size_t, CSystemInstance*>::iterator it; if (true) { CGameRenderingContext c(GameServer()->GetRenderer(), true); c.UseProgram("particle"); c.SetUniform("bDiffuse", true); c.SetUniform("iDiffuse", 0); for (it = pPSL->m_apInstances.begin(); it != pPSL->m_apInstances.end(); it++) { CSystemInstance* pInstance = (*it).second; pInstance->Render(&c, false); } } if (true) { CGameRenderingContext c(GameServer()->GetRenderer(), true); c.UseProgram("particle"); c.SetUniform("bDiffuse", true); c.SetUniform("iDiffuse", 0); c.SetDepthMask(false); for (it = pPSL->m_apInstances.begin(); it != pPSL->m_apInstances.end(); it++) { CSystemInstance* pInstance = (*it).second; pInstance->Render(&c, true); } } CRenderingContext::DebugFinish(); }
void ProxSensorObject::BuildMesh(TimeValue t) { int nverts = 8; int nfaces = 12; Point3 va; Point3 vb; float length, width, height; pblock->GetValue(PB_PS_LENGTH, t, length, FOREVER); pblock->GetValue(PB_PS_WIDTH, t, width, FOREVER); pblock->GetValue(PB_PS_HEIGHT, t, height, FOREVER); float x = width/2.0f; float y = length/2.0f; float z = height; va = Point3(-x, -y, 0.0f); vb = Point3( x, y, z); mesh.setNumVerts(nverts); mesh.setNumFaces(nfaces); mesh.setVert(0, Point3( va.x, va.y, va.z)); mesh.setVert(1, Point3( vb.x, va.y, va.z)); mesh.setVert(2, Point3( va.x, vb.y, va.z)); mesh.setVert(3, Point3( vb.x, vb.y, va.z)); mesh.setVert(4, Point3( va.x, va.y, vb.z)); mesh.setVert(5, Point3( vb.x, va.y, vb.z)); mesh.setVert(6, Point3( va.x, vb.y, vb.z)); mesh.setVert(7, Point3( vb.x, vb.y, vb.z)); MakeQuad(&(mesh.faces[ 0]), 0,2,3,1, 1); MakeQuad(&(mesh.faces[ 2]), 2,0,4,6, 2); MakeQuad(&(mesh.faces[ 4]), 3,2,6,7, 4); MakeQuad(&(mesh.faces[ 6]), 1,3,7,5, 8); MakeQuad(&(mesh.faces[ 8]), 0,1,5,4, 16); MakeQuad(&(mesh.faces[10]), 4,5,7,6, 32); mesh.InvalidateGeomCache(); mesh.EnableEdgeList(1); }
// Will return the edge factor of the right a to left b float EdgeFactor( BMP& a, BMP& b, vec2i dir ) { // Clamp the x and y on dir to [-1,1] dir.x = dir.x>1||dir.y<-1?dir.x>1?1:-1:dir.x; dir.y = dir.y>1||dir.y<-1?dir.y>1?1:-1:dir.y; if( values.find(MakeQuad(&a,&b,dir.x,dir.y)) != values.end() ) { savedComps++; return values[MakeQuad(&a,&b,dir.x,dir.y)]; } edgeComps++; // We can only compare images of equal size if( a.TellHeight() != b.TellHeight() || a.TellWidth() != b.TellWidth() ) { std::cout << "ROW_SIZE_ERROR" << std::endl; return -1; } int result = 0; int width = a.TellWidth(); int height = a.TellHeight(); for( int i = 0; i < a.TellHeight(); i++ ) { RGBApixel* aPx = NULL; RGBApixel* bPx = NULL; // Comparing a.right with b.left if( dir.x == 1 ) { aPx = a( width-1,i ); bPx = b( 0,i ); } // Comparing a.top with b.bottom else if( dir.y == -1 ) { aPx = a( i,0 ); bPx = b( i,height-1 ); } // Comparing a.right with b.left else if( dir.x == -1 ) { aPx = a( 0,i ); bPx = b( width-1,i ); } // Comparing a.bottom with b.top else { aPx = a( i,height-1 ); bPx = b( i,0 ); } result += abs( bPx->Red-aPx->Red ); result += abs( bPx->Green-aPx->Green ); result += abs( bPx->Blue-aPx->Blue ); } // Store the results in a quad mapping to never compute this quad again values[MakeQuad(&a,&b,dir.x,dir.y)] = result/static_cast<float>(768.0f * a.TellHeight()); return values[MakeQuad(&a,&b,dir.x,dir.y)]; }
void Cal3DObject::BuildMesh(TimeValue t) { pblock->GetValue(PB_CAL_SIZE, t, scale, FOREVER); float r = scale, r2 = r / 3.0f; if (coreHelper) { int animI, actionI; pblock->GetValue(PB_CAL_ANIM, t, animI, FOREVER); pblock->GetValue(PB_CAL_ACTION, t, actionI, FOREVER); coreHelper->setState(animI, 0.0); coreHelper->buildMesh(mesh, scale, t); // mesh.InvalidateStrips(); //mesh.BuildStripsAndEdges(); } else { mesh.setNumVerts(28); mesh.setNumFaces(52); int v = 0; mesh.setVert(v++, Point3(-r2, r2, r2)); //0 -- back of center cube of the plus mesh.setVert(v++, Point3(-r2, r2, -r2)); mesh.setVert(v++, Point3(r2, r2, -r2)); mesh.setVert(v++, Point3(r2, r2, r2)); mesh.setVert(v++, Point3(-r2, -r2, r2)); //4 -- front of center cube of the plus mesh.setVert(v++, Point3(-r2, -r2, -r2)); mesh.setVert(v++, Point3(r2, -r2, -r2)); mesh.setVert(v++, Point3(r2, -r2, r2)); mesh.setVert(v++, Point3(-r2, -r, r2)); //8 -- front of the plus mesh.setVert(v++, Point3(-r2, -r, -r2)); mesh.setVert(v++, Point3(r2, -r, -r2)); mesh.setVert(v++, Point3(r2, -r, r2)); mesh.setVert(v++, Point3(-r, r2, r2)); //12 -- left end mesh.setVert(v++, Point3(-r, r2, -r2)); mesh.setVert(v++, Point3(-r, -r2, -r2)); mesh.setVert(v++, Point3(-r, -r2, r2)); mesh.setVert(v++, Point3(r, r2, r2)); //16 -- right end mesh.setVert(v++, Point3(r, r2, -r2)); mesh.setVert(v++, Point3(r, -r2, -r2)); mesh.setVert(v++, Point3(r, -r2, r2)); mesh.setVert(v++, Point3(-r2, r2, r)); //20 -- top end mesh.setVert(v++, Point3(r2, r2, r)); mesh.setVert(v++, Point3(r2, -r2, r)); mesh.setVert(v++, Point3(-r2, -r2, r)); mesh.setVert(v++, Point3(-r, r, -r)); //24 -- bottom end mesh.setVert(v++, Point3(r, r, -r)); mesh.setVert(v++, Point3(r, -r, -r)); mesh.setVert(v++, Point3(-r, -r, -r)); /* Now the Faces */ int f = 0; // TOP MakeQuad(&f, 23, 22, 21, 20, 1, 1, 1, 1); // Top MakeQuad(&f, 7, 22, 23, 4, 1, 0, 0, 1); // Front MakeQuad(&f, 3, 21, 22, 7, 1, 0, 0, 1); // Right MakeQuad(&f, 0, 20, 21, 3, 1, 0, 0, 0); // Back MakeQuad(&f, 4, 23, 20, 0, 1, 0, 0, 1); // Left // FRONT MakeQuad(&f, 8, 9, 10, 11, 1, 1, 1, 1); // End MakeQuad(&f, 4, 8, 11, 7, 1, 0, 0, 0); // Top MakeQuad(&f, 7, 11, 10, 6, 1, 0, 0, 1); // Right MakeQuad(&f, 6, 10, 9, 5, 1, 0, 1, 1); // Bottom MakeQuad(&f, 5, 9, 8, 4, 1, 0, 0, 1); // Left // LEFT MakeQuad(&f, 12, 13, 14, 15, 1, 1, 1, 1); // End MakeQuad(&f, 0, 12, 15, 4, 1, 0, 0, 0); // Top MakeQuad(&f, 4, 15, 14, 5, 1, 0, 0, 0); // Right MakeQuad(&f, 5, 14, 13, 1, 1, 0, 0, 1); // Bottom MakeQuad(&f, 1, 13, 12, 0, 1, 0, 0, 0); // Left // BACK MakeQuad(&f, 3, 2, 1, 0, 0, 1, 0, 0); // Left // RIGHT MakeQuad(&f, 19, 18, 17, 16, 1, 1, 1, 1); // End MakeQuad(&f, 7, 19, 16, 3, 1, 0, 0, 0); // Top MakeQuad(&f, 3, 16, 17, 2, 1, 0, 0, 0); // Right MakeQuad(&f, 2, 17, 18, 6, 1, 0, 0, 1); // Bottom MakeQuad(&f, 6, 18, 19, 7, 1, 0, 0, 0); // Left // BASE MakeQuad(&f, 24, 25, 26, 27, 1, 1, 1, 1); // Bottom MakeQuad(&f, 5, 27, 26, 6, 1, 0, 0, 0); // Front MakeQuad(&f, 6, 26, 25, 2, 1, 0, 0, 0); // Right MakeQuad(&f, 2, 25, 24, 1, 1, 0, 0, 0); // Back MakeQuad(&f, 1, 24, 27, 5, 1, 0, 0, 0); // Left } mesh.InvalidateGeomCache(); mesh.EnableEdgeList(1); mesh.buildBoundingBox(); }