Camera::Camera(int width, int height) : m_windowWidth(width) , m_windowHeight(height) , m_eyePosition(Point4(0, 0, 0, 1)) , m_worldPos(Point4(0, 0, 0, 1)) , m_scale(Vec3(1, 1, 1)) , m_nVector(Vec4(0, 0, -1, 0)) , m_upVector(Vec4(0, 1, 0, 0)) , m_mouseX(0) , m_mouseY(0) , m_distanceFactor(0.0) {}
int MarketDefaultTest::Tester::testCfgDefaults() { mStatus.message(kInfoMessage, _T("Starting testCfgDefaults\r\n")); int errors = 0; // This one we can do multiple times, because we are using the API MarketDefaults* dflts = GetMarketDefaults(_T("testHighLevel")); if (dflts == NULL) { mStatus.message(kErrorMessage, _T("Unexpected Error: Market defaults is NULL\r\n")); return 1; } CfgDefaultTestClassDesc cd; CfgDefaultTestParamBlock pd(cd); #define CHECKVALUE(f, i, v, n) highLevelCheck(pd.paramdefs[i].def.f, v, _T(n)) errors += CHECKVALUE(i, 0, intValue, "int"); errors += CHECKVALUE(f, 1, floatValue, "float"); errors += CHECKVALUE(p[0], 2, Point3(array3), "Point3"); errors += CHECKVALUE(p4[0], 3, Point4(array4), "Point4"); #undef CHECKVALUE mStatus.message(kInfoMessage, _T("Finished testCfgDefaults - %d error(s)\r\n\r\n"), errors); return errors; }
Point4 Matrix4::operator*(const Point4& rhs) const { Point4 tmp = Point4(0,0,0,0); for( unsigned i = 0; i < 4; i++) for( unsigned j = 0; j < 4; j++) tmp.v[i] += rhs.v[j] * m[i][j]; return tmp; }
void menu::render(size_t i, bool replace) { auto size = current_size(); if(i < 0 || i >= size) { return; } auto &item = current_at(i); IDType id; if(replace) { itemDtors.at(i) = engine->add(id); } else { itemDtors.emplace_back(engine->add(id)); } Decimal scale = glm::min(actual_height() / Decimal(size), actual_scale()); Decimal spacing = uiTextHeight * scale; Point2 origin = Point2(60, 50 + spacing * (size - i - 1)); engine->add<component::text>(id, font, item.value); engine->add<component::screenposition>(id, origin); engine->add<component::scale>(id, Point3(scale)); if(int(i) == current) { engine->add<component::color>(id, Point4(1, 1, selectionAlpha, 1)); } if(item.control) { IDType controlID; auto offset = Point2(uiTextWidth / uiBase * scale, 0); offset.y -= 12 * scale; controlDtors[(int)i] = item.control->render(engine, controlID, origin + offset, 8 * scale); } }
//------------------------------------------------------------------------------- //void Sphere::ViewportDisplay() const //{ // static GLUquadric *q = NULL; // if ( q == NULL ) { // q = gluNewQuadric(); // gluQuadricTexture(q,true); // } // gluSphere(q,1,50,50); //} //void Plane::ViewportDisplay() const //{ // const int resolution = 32; // float xyInc = 2.0f / resolution; // float uvInc = 1.0f / resolution; // glPushMatrix(); // glNormal3f(0,0,1); // glBegin(GL_QUADS); // float y1=-1, y2=xyInc-1, v1=0, v2=uvInc; // for ( int y=0; y<resolution; y++ ) { // float x1=-1, x2=xyInc-1, u1=0, u2=uvInc; // for ( int x=0; x<resolution; x++ ) { // glTexCoord2f(u1, v1); // glVertex3f ( x1, y1, 0 ); // glTexCoord2f(u2, v1); // glVertex3f ( x2, y1, 0 ); // glTexCoord2f(u2, v2); // glVertex3f ( x2, y2, 0 ); // glTexCoord2f(u1, v2); // glVertex3f ( x1, y2, 0 ); // x1=x2; x2+=xyInc; u1=u2; u2+=uvInc; // } // y1=y2; y2+=xyInc; v1=v2; v2+=uvInc; // } // glEnd(); // glPopMatrix(); //} //void TriObj::ViewportDisplay() const //{ // glBegin(GL_TRIANGLES); // for ( unsigned int i=0; i<NF(); i++ ) { // for ( int j=0; j<3; j++ ) { // if ( HasTextureVertices() ) glTexCoord3fv( &VT( FT(i).v[j] ).x ); // if ( HasNormals() ) glNormal3fv( &VN( FN(i).v[j] ).x ); // glVertex3fv( &V( F(i).v[j] ).x ); // } // } // glEnd(); //} void PointLight::SetViewportLight(int lightID) const { SetViewportParam(lightID,0.0f,intensity,Point4(position,1.0f)); glLightf( GL_LIGHT0 + lightID, GL_CONSTANT_ATTENUATION, 0 ); glLightf( GL_LIGHT0 + lightID, GL_LINEAR_ATTENUATION, 0 ); glLightf( GL_LIGHT0 + lightID, GL_QUADRATIC_ATTENUATION, 1 ); }
Point4 Matrix4::operator*(const Point4& rhs) const { return(Point4(std::inner_product(rhs.v, rhs.v+4, v+0, 0), std::inner_product(rhs.v, rhs.v+4, v+4, 0), std::inner_product(rhs.v, rhs.v+4, v+8, 0), std::inner_product(rhs.v, rhs.v+4, v+12, 0) ) ); }
/** * Get the current position of the skeleton * @param skeletonIndex the skeleton to read from * @return the current position as defined in the Kinect SDK (w is ignored) */ Kinect::Point4 Kinect::GetPosition(int skeletonIndex) { if (skeletonIndex <= 0 || skeletonIndex > kNumSkeletons) { wpi_setWPIErrorWithContext(ParameterOutOfRange, "Skeleton index must be 1"); return Point4(); } UpdateData(); return m_position[skeletonIndex-1]; }
int MarketDefaultTest::Tester::verifyHighLevelValues(MarketDefaults* dflts) { int errors = 0; #define CHECKVALUE(t, n, d, v) highLevelCheck(dflts->Get##t(highLevelSClass, highLevelClass,\ _T(n), d), v, _T(n)) errors += CHECKVALUE(Int, "int", 0, intValue); errors += CHECKVALUE(Float, "float", 0.0f, floatValue); errors += CHECKVALUE(Point3, "point3", Point3(0,0,0), Point3(array3)); errors += CHECKVALUE(Point4, "point4", Point4(0,0,0,0), Point4(array4)); errors += CHECKVALUE(String, "string", _T(""), TSTR(theString)); errors += CHECKVALUE(ClassID, "classid", Class_ID(0,0), Class_ID(clarray[0], clarray[1])); errors += verifyMtl(dflts->CreateMtl(highLevelSClass, highLevelClass, _T("classid"), Class_ID(0, 0)), Class_ID(clarray[0], clarray[1]), _T("classid")); #undef CHECKVALUE return errors; }
Point4 TransformMatrix::operator*( const Point4 &v ) { const float *pnt = v.Data(); float result[4]; for( int i = 0; i < 4; ++i ) { float rowCol = 0.0; for( int k = 0; k < 4; ++k ) { rowCol += mData[i][k] * pnt[k]; } result[i] = rowCol; } return Point4( result[0], result[1], result[2], result[3] ); }
CfgDefaultTestParamBlock(ClassDesc2& cd) : ParamBlockDesc2(1, _T("CfgDefaultTestParamBlock"), 0, &cd, 0, kIntParam, _T("int"), TYPE_INT, 0, 0, p_configurable_default, 0, _T("testHighLevel"), NULL, p_end, kFloatParam, _T("float"), TYPE_FLOAT, 0, 0, p_configurable_default, 0.0f, _T("testHighLevel"), NULL, p_end, kPoint3Param, _T("point3"), TYPE_POINT3, 0, 0, p_configurable_default, Point3(0, 0, 0), _T("testHighLevel"), NULL, p_end, kPoint4Param, _T("point4"), TYPE_FRGBA, 0, 0, p_configurable_default, Point4(0, 0, 0, 0), _T("testHighLevel"), NULL, p_end, p_end) {}
void scigraphics::painter::clearBordersArea() { if ( ! ableToDraw() ) return; const int Shift = 10; wpoint Point1( -Shift, -Shift ); wpoint Point2( Indents.left(), Drawer->height() + Shift ); Drawer->eraseRectangle( wrectangle(Point1,Point2) ); wpoint Point3( Drawer->width() + Shift, Drawer->height() - Indents.down() ); Drawer->eraseRectangle( wrectangle(Point2,Point3) ); wpoint Point4( Drawer->width() - Indents.right(), -Shift ); Drawer->eraseRectangle( wrectangle(Point3,Point4) ); wpoint Point5( -Shift, Indents.up() ); Drawer->eraseRectangle( wrectangle(Point4,Point5) ); }
namespace Bibim { const Point4 Point4::Zero = Point4(0, 0, 0, 0); }
// Unary negation operator, negates every component and returns a copy Point4 Point4::operator-(void) const { return Point4(-x, -y, -z,-w); }
void Camera::recoverModelTransform() { m_worldPos = Point4(0, 0, 0, 1); m_scale = Vec3(1, 1, 1); }
// Basic vector math operations with points, you can add a Vector4 to a Point4, or subtract // a Vector4 from a Point4 Point4 Point4::operator+ (const Vector4& rhs) const { return Point4(x + rhs.x, y + rhs.y, z + rhs.z, w + rhs.w); }
int Plate::BuildMaps(TimeValue t, RenderMapsContext &rmc) { SubRendParams srp; rmc.GetSubRendParams(srp); PlateMap *pmap = FindMap(rmc.NodeRenderID()); if (pmap&&!DoThisFrame(t,srp.fieldRender,pmap->mapTime)) return 1; ViewParams vp; Box2 sbox; rmc.GetCurrentViewParams(vp); rmc.FindMtlScreenBox(sbox, &vp.affineTM, rmc.SubMtlIndex()); int xmin,xmax,ymin,ymax; BOOL fieldRender = FALSE; if (srp.fieldRender) { sbox.top *= 2; sbox.bottom *= 2; fieldRender = TRUE; } // add a margin around object for refraction int ew = srp.devWidth/20; int eh = srp.devHeight/20; xmax = sbox.right+ew; xmin = sbox.left-ew; ymax = sbox.bottom+eh; ymin = sbox.top-eh; if (srp.rendType==RENDTYPE_REGION) { ymin = MAX(ymin,srp.ymin-eh); ymax = MIN(ymax,srp.ymax+eh); xmin = MAX(xmin,srp.xmin-ew); xmax = MIN(xmax,srp.xmax+ew); } srp.xmin = MAX(xmin,-ew); srp.xmax = MIN(xmax,srp.devWidth+ew); srp.ymin = MAX(ymin,-eh); srp.ymax = MIN(ymax,srp.devHeight+eh); int xorg = xmin; int yorg = ymin; int devw = srp.devWidth; int devh = srp.devHeight; // The renderer is set up to allocate A-buffer for the range // 0..devWidth-1, 0..devHeight-1. If the region of the plate // bitmap goes out of this region, it must be extended. int d1 = 0, d2 = 0; if (srp.xmin<0) d1 = -srp.xmin; if (srp.xmax>=srp.devWidth) d2 = srp.xmax-srp.devWidth+1; int d = MAX(d1,d2); if (d) { srp.devWidth += 2*d; srp.xmax += d; srp.xmin += d; // must also correct fov (or zoom) so the renderer computes the // same xscale and yscale if (vp.projType==PROJ_PERSPECTIVE) { vp.fov = 2.0f*(float)atan((float(srp.devWidth)/float(devw))*tan(0.5*vp.fov)); } else { vp.zoom *= (float(srp.devWidth)/float(devw)); } srp.blowupCenter.x += d; // DS: 11/6/00 } d1 = d2 = 0; if (srp.ymin<0) d1 = -srp.ymin; if (srp.ymax>=srp.devHeight) d2 = srp.ymax-srp.devHeight+1; d = MAX(d1,d2); if (d) { // if (fieldRender) // d = ((d+1)>>1)<<1; // make d even, so line doubling (below) works right. srp.devHeight += 2*d; srp.ymax += d; srp.ymin += d; srp.blowupCenter.y += d; // DS: 11/6/00 } srp.xorg = srp.xmin; srp.yorg = srp.ymin; srp.doEnvMap = useEnvMap; //srp.doingMirror = TRUE; // DS: 11/6/00: no longer necessary int w = srp.xmax-srp.xmin; int h = srp.ymax-srp.ymin; if (w<=0||h<=0) return 1; #ifdef DBG w = ((w+3)/4)*4; // For some reason this needs to be a multiple of 4 for bm->Display #endif if (pmap==NULL) { pmap = new PlateMap; pmap->nodeID = rmc.NodeRenderID(); pmap->next = maps; maps = pmap; } pmap->AllocMap(w, h); pmap->org.x = xorg-devw/2; pmap->org.y = yorg-devh/2; pmap->devW = devw; // TBD: This should be accessable from the SC pmap->mapTime = t; // Set up clipping planes to clip out stuff between camera and plate. Box3 b = rmc.ObjectSpaceBoundingBox(); Matrix3 tmObToWorld = rmc.ObjectToWorldTM(); Matrix3 obToCam = tmObToWorld*vp.affineTM; int nplanes=0; Point4 pl[6],pc; Point4 clip[6]; pl[0] = Point4( 1.0f, 0.0f, 0.0f, -b.pmax.x); pl[1] = Point4(-1.0f, 0.0f, 0.0f, b.pmin.x); pl[2] = Point4( 0.0f, 1.0f, 0.0f, -b.pmax.y); pl[3] = Point4( 0.0f,-1.0f, 0.0f, b.pmin.y); pl[4] = Point4( 0.0f, 0.0f, 1.0f, -b.pmax.z); pl[5] = Point4( 0.0f, 0.0f,-1.0f, b.pmin.z); if (vp.projType==PROJ_PARALLEL) { for (int i=0; i<6; i++) { pc = TransformPlane(obToCam,pl[i]); // see if camera = (0,0,0) is in front of plane if (pc.z>0.0f) clip[nplanes++] = -pc; } } else { for (int i=0; i<6; i++) { pc = TransformPlane(obToCam,pl[i]); // see if camera = (0,0,0) is in front of plane if (pc.w>0.0f) clip[nplanes++] = -pc; } } srp.fieldRender = FALSE; // assert(nplanes<4); if (!rmc.Render(pmap->bm, vp, srp, clip, nplanes)) return 0; /* if (srp.fieldRender) { // Double the lines, otherwise the blur wont work right, // because the blank lines in between get averaged in and darken it. int evenLines = srp.evenLines; if(srp.ymin&1) evenLines = !evenLines; PixelBuf l64(w); if (evenLines) { for (int i=0; i<h; i+=2) { BMM_Color_64 *p64=l64.Ptr(); if (i+1<h) { pmap->bm->GetPixels(0,i, w, p64); pmap->bm->PutPixels(0,i+1,w, p64); } } } else { for (int i=0; i<h; i+=2) { BMM_Color_64 *p64=l64.Ptr(); if (i+1<h) { pmap->bm->GetPixels(0,i+1,w, p64); pmap->bm->PutPixels(0,i ,w, p64); } } } } */ #ifdef DBG if (devw>200){ pmap->bm->UnDisplay(); TSTR buf; RenderGlobalContext *gc = rmc.GetGlobalContext(); RenderInstance* inst = gc->GetRenderInstance(rmc.NodeRenderID()); INode *node = inst->GetINode(); buf.printf(_T("Thinwall: %s"), node->GetName()); pmap->bm->Display(buf, BMM_UR); MessageBox(NULL, _T("hi"), _T(" Plate Test"), MB_OK|MB_ICONEXCLAMATION); } #endif if (applyBlur) { // I tried pyramids here, but SATs looked much better. // maybe we should give users a choice? pmap->bm->SetFilter(BMM_FILTER_SUM); // pmap->bm->SetFilter(BMM_FILTER_PYRAMID); BitmapFilter *filt = pmap->bm->Filter(); if (filt) filt->MakeDirty(); // so filter gets recomputed for each frame } else pmap->bm->SetFilter(BMM_FILTER_NONE); return 1; }
Point4 Point4::operator- (const Vector4& rhs) const { return Point4(x - rhs.x, y - rhs.y, z - rhs.z, w - rhs.w); }
Point4 p3to4 (const Point3 &p3) { return Point4 (p3.x(), p3.y(), p3.z(), 1); }