CSulScreenAlignedQuad::CSulScreenAlignedQuad( float fViewW, float fViewH, const CSulString& fileTexture ) { setName( "CSulScreenAlignedQuad" ); osg::ref_ptr<osg::Image> image = osgDB::readImageFile( osgDB::findDataFile(fileTexture.c_str()) ); float x = 0.0f; float y = 0.0f; float w = image->s(); float h = image->t(); m_rGeomQuad = new CSulGeomQuad( osg::Vec3( x + w/2.0f, fViewH - (y+h/2.0f) , 0 ), w, h, CSulGeomQuad::PLANE_XY ); m_rGeomQuad->setTexture( image ); m_geodeQuad = new CSulGeode; m_geodeQuad->addDrawable( m_rGeomQuad ); osg::Matrixd mOrtho = osg::Matrix::ortho2D( 0, fViewW, 0, fViewH ); setMatrix( mOrtho ); initConstructor(); }
// Render a research item given a BASE_STATS structure. // void displayResearchButton(BASE_STATS *Stat, Vector3i *Rotation, Vector3i *Position, BOOL RotXYZ, SDWORD scale) { iIMDShape *ResearchIMD = ((RESEARCH *)Stat)->pIMD; iIMDShape *MountIMD = ((RESEARCH *)Stat)->pIMD2; if(ResearchIMD) { setMatrix(Position, Rotation, RotXYZ); pie_MatScale(scale / 100.f); if(MountIMD) { pie_Draw3DShape(MountIMD, 0, getPlayerColour(selectedPlayer), WZCOL_WHITE, WZCOL_BLACK, pie_BUTTON, 0); } pie_Draw3DShape(ResearchIMD, 0, getPlayerColour(selectedPlayer), WZCOL_WHITE, WZCOL_BLACK, pie_BUTTON, 0); unsetMatrix(); } else { debug(LOG_ERROR, "ResearchIMD == NULL"); } }
//============================================================================== void EllipsoidShapeNode::extractData(bool firstTime) { if( mShape->checkDataVariance(dart::dynamics::Shape::DYNAMIC_TRANSFORM) || mShape->checkDataVariance(dart::dynamics::Shape::DYNAMIC_PRIMITIVE) || firstTime ) { Eigen::Matrix4d S(Eigen::Matrix4d::Zero()); const Eigen::Vector3d& s = mEllipsoidShape->getSize()/smallestComponent(mEllipsoidShape->getSize()); S(0,0) = s[0]; S(1,1) = s[1]; S(2,2) = s[2]; S(3,3) = 1.0; setMatrix(eigToOsgMatrix(S)); } if(nullptr == mGeode) { mGeode = new EllipsoidShapeGeode(mEllipsoidShape.get(), mParentShapeFrameNode, this); addChild(mGeode); return; } mGeode->refresh(); }
void SchematicSceneViewer::zoomQt(bool zoomin, bool resetZoom) { #if QT_VERSION >= 0x050000 double scale2 = matrix().determinant(); #else double scale2 = matrix().det(); #endif if (resetZoom || ((scale2 < 100000 || !zoomin) && (scale2 > 0.001 * 0.05 || zoomin))) { double oldZoomScale = sqrt(scale2); double zoomScale = resetZoom ? 1 : ImageUtils::getQuantizedZoomFactor( oldZoomScale, zoomin); QMatrix scale = QMatrix().scale(zoomScale / oldZoomScale, zoomScale / oldZoomScale); // See QGraphicsView::mapToScene()'s doc for details QRect rect(0, 0, width(), height()); QRectF sceneCenterRect( mapToScene(QRect(rect.center(), QSize(2, 2))).boundingRect()); setMatrix(scale, true); centerOn(sceneCenterRect.center()); } }
SwkMatrix3x3 (const GenericPointT& p1, const GenericPointT& p2, const GenericPointT& p3, const GenericPointT& pt) { /* // sort the points first // GenericPointT pos[3]; pos[0] = p1; if (p2 < pos[0]) { pos[1] = pos[0]; pos[0] = p2; } else { pos[1] = p2; } if (p3 < pos[0]) { pos[2] = pos[1]; pos[1] = pos[0]; pos[0] = p3; } else if (p3 < pos[1]) { pos[2] = pos[1]; pos[1] = p3; } else { pos[2] = p3; } setMatrix(pos[0], pos[1], pos[2], pt); */ setMatrix(p1, p2, p3, pt); }
void CQIllustratorShape:: skew(double dx, double dy) { checkoutShape(CQIllustratorData::ChangeType::GEOMETRY); CMatrix2D m; m.setSkew(dx, dy); CMatrix2D m1, m2; CPoint2D rc = getRotateCenter(); m1.setTranslation(-rc.x, -rc.y); m2.setTranslation( rc.x, rc.y); CMatrix2D mm = m2*m*m1; setMatrix(mm*m_); checkinShape(CQIllustratorData::ChangeType::GEOMETRY); }
void loop() { time_t rawtime; // raw time struct tm *ptime; // time struct holder // nyble vector for matrix columns // [hour/10, hour/1, minute/10, minute/1] uint8_t bTime[4] = {0b0000}; // row/column inc. uint8_t x = 0; uint8_t y = 0; // get the time from system time(&rawtime); // load into the tm struct ptime = localtime(&rawtime); // convert the time to nybles for the matrix pixelTime(ptime, bTime); // quarter hour indicator if ( (ptime->tm_min % 15 == 0) && ptime->tm_sec == 0) { quarterHour(ptime->tm_hour, ptime->tm_min, QUARTER_WAIT); } if (pulse_second) { for (x = 0; x < PIXEL_ROW; x += width) { for (y = 0; y < PIXEL_COLUMN; y += height) { setPixelColorT(pixelMap[x][y],Color(0,0,0)); } } show(); usleep(100*100); } // set the matrix to the binary time setMatrix(bTime, sizeof(bTime)/sizeof(bTime[1]), Color(255,255,255), Color(255,0,0)); }
virtual void resizeEvent(QResizeEvent *event) { QGraphicsView::resizeEvent(event); setSceneRect(Config.Rect); if(Config.FitInView) fitInView(sceneRect(), Qt::KeepAspectRatio); if(matrix().m11() > 1) setMatrix(QMatrix()); MainWindow *main_window = qobject_cast<MainWindow *>(parentWidget()); if(scene()->inherits("RoomScene")){ RoomScene *room_scene = qobject_cast<RoomScene *>(scene()); QRectF newSceneRect(0, 0, event->size().width(), event->size().height()); room_scene->setSceneRect(newSceneRect); room_scene->adjustItems(); setSceneRect(room_scene->sceneRect()); if(Config.FitInView) fitInView(room_scene->sceneRect(), Qt::KeepAspectRatio); main_window->setBackgroundBrush(false); return; } if(main_window) main_window->setBackgroundBrush(true); }
Khepera::Khepera(World* world, SharedDataWrapper<Shared> shared, ConfigurationManager& params) : RobotOnPlane(params) , PhyKhepera(world, shared) { setName(m_initialName); setMatrix(m_initialTm); doKinematicSimulation(ConfigurationHelper::getBool(configurationManager(), confPath() + "kinematicRobot")); const bool enableWheels = ConfigurationHelper::getBool(configurationManager(), confPath() + "enableWheels"); const bool enableProximityIR = ConfigurationHelper::getBool(configurationManager(), confPath() + "enableProximityIR"); const bool drawProximityIR = ConfigurationHelper::getBool(configurationManager(), confPath() + "drawProximityIR"); const bool drawIRRays = ConfigurationHelper::getBool(configurationManager(), confPath() + "drawIRRays"); const bool drawIRRaysRange = ConfigurationHelper::getBool(configurationManager(), confPath() + "drawIRRaysRange"); wheelsController()->setEnabled(enableWheels); proximityIRSensorController()->setEnabled(enableProximityIR); setProximityIRSensorsGraphicalProperties(drawProximityIR, drawIRRays, drawIRRaysRange); setDrawFrontMarker(true); // Setting the color of the robot setColor(configuredRobotColor()); }
AffineTransform::AffineTransform(const CGAffineTransform& t) { setMatrix(t.a, t.b, t.c, t.d, t.tx, t.ty); }
void GFXDevice::updateStates(bool forceSetAll /*=false*/) { PROFILE_SCOPE(GFXDevice_updateStates); if(forceSetAll) { bool rememberToEndScene = false; if(!canCurrentlyRender()) { if (!beginScene()) { AssertFatal(false, "GFXDevice::updateStates: Unable to beginScene!"); } rememberToEndScene = true; } setMatrix( GFXMatrixProjection, mProjectionMatrix ); setMatrix( GFXMatrixWorld, mWorldMatrix[mWorldStackSize] ); setMatrix( GFXMatrixView, mViewMatrix ); setVertexDecl( mCurrVertexDecl ); for ( U32 i=0; i < VERTEX_STREAM_COUNT; i++ ) { setVertexStream( i, mCurrentVertexBuffer[i] ); setVertexStreamFrequency( i, mVertexBufferFrequency[i] ); } if( mCurrentPrimitiveBuffer.isValid() ) // This could be NULL when the device is initalizing mCurrentPrimitiveBuffer->prepare(); /// Stateblocks if ( mNewStateBlock ) setStateBlockInternal(mNewStateBlock, true); mCurrentStateBlock = mNewStateBlock; for(U32 i = 0; i < getNumSamplers(); i++) { switch (mTexType[i]) { case GFXTDT_Normal : { mCurrentTexture[i] = mNewTexture[i]; setTextureInternal(i, mCurrentTexture[i]); } break; case GFXTDT_Cube : { mCurrentCubemap[i] = mNewCubemap[i]; if (mCurrentCubemap[i]) mCurrentCubemap[i]->setToTexUnit(i); else setTextureInternal(i, NULL); } break; default: AssertFatal(false, "Unknown texture type!"); break; } } // Set our material setLightMaterialInternal(mCurrentLightMaterial); // Set our lights for(U32 i = 0; i < LIGHT_STAGE_COUNT; i++) { setLightInternal(i, mCurrentLight[i], mCurrentLightEnable[i]); } _updateRenderTargets(); if(rememberToEndScene) endScene(); return; } if (!mStateDirty) return; // Normal update logic begins here. mStateDirty = false; // Update Projection Matrix if( mProjectionMatrixDirty ) { setMatrix( GFXMatrixProjection, mProjectionMatrix ); mProjectionMatrixDirty = false; } // Update World Matrix if( mWorldMatrixDirty ) { setMatrix( GFXMatrixWorld, mWorldMatrix[mWorldStackSize] ); mWorldMatrixDirty = false; } // Update View Matrix if( mViewMatrixDirty ) { setMatrix( GFXMatrixView, mViewMatrix ); mViewMatrixDirty = false; } if( mTextureMatrixCheckDirty ) { for( S32 i = 0; i < getNumSamplers(); i++ ) { if( mTextureMatrixDirty[i] ) { mTextureMatrixDirty[i] = false; setMatrix( (GFXMatrixType)(GFXMatrixTexture + i), mTextureMatrix[i] ); } } mTextureMatrixCheckDirty = false; } // Update the vertex declaration. if ( mVertexDeclDirty ) { setVertexDecl( mCurrVertexDecl ); mVertexDeclDirty = false; } // Update the vertex buffers. for ( U32 i=0; i < VERTEX_STREAM_COUNT; i++ ) { if ( mVertexBufferDirty[i] ) { setVertexStream( i, mCurrentVertexBuffer[i] ); mVertexBufferDirty[i] = false; } if ( mVertexBufferFrequencyDirty[i] ) { setVertexStreamFrequency( i, mVertexBufferFrequency[i] ); mVertexBufferFrequencyDirty[i] = false; } } // Update primitive buffer // // NOTE: It is very important to set the primitive buffer AFTER the vertex buffer // because in order to draw indexed primitives in DX8, the call to SetIndicies // needs to include the base vertex offset, and the DX8 GFXDevice relies on // having mCurrentVB properly assigned before the call to setIndices -patw if( mPrimitiveBufferDirty ) { if( mCurrentPrimitiveBuffer.isValid() ) // This could be NULL when the device is initalizing mCurrentPrimitiveBuffer->prepare(); mPrimitiveBufferDirty = false; } // NOTE: With state blocks, it's now important to update state before setting textures // some devices (e.g. OpenGL) set states on the texture and we need that information before // the texture is activated. if (mStateBlockDirty) { setStateBlockInternal(mNewStateBlock, false); mCurrentStateBlock = mNewStateBlock; mStateBlockDirty = false; } if( mTexturesDirty ) { mTexturesDirty = false; for(U32 i = 0; i < getNumSamplers(); i++) { if(!mTextureDirty[i]) continue; mTextureDirty[i] = false; switch (mTexType[i]) { case GFXTDT_Normal : { mCurrentTexture[i] = mNewTexture[i]; setTextureInternal(i, mCurrentTexture[i]); } break; case GFXTDT_Cube : { mCurrentCubemap[i] = mNewCubemap[i]; if (mCurrentCubemap[i]) mCurrentCubemap[i]->setToTexUnit(i); else setTextureInternal(i, NULL); } break; default: AssertFatal(false, "Unknown texture type!"); break; } } } // Set light material if(mLightMaterialDirty) { setLightMaterialInternal(mCurrentLightMaterial); mLightMaterialDirty = false; } // Set our lights if(mLightsDirty) { mLightsDirty = false; for(U32 i = 0; i < LIGHT_STAGE_COUNT; i++) { if(!mLightDirty[i]) continue; mLightDirty[i] = false; setLightInternal(i, mCurrentLight[i], mCurrentLightEnable[i]); } } _updateRenderTargets(); #ifdef TORQUE_DEBUG_RENDER doParanoidStateCheck(); #endif }
AffineTransform::AffineTransform(double a, double b, double c, double d, double e, double f) { setMatrix(a, b, c, d, e, f); }
void GraphicsView::wheelEvent(QWheelEvent *event) { int zoomType = event->delta(); QMatrix m = matrixImage; switch (zoom) { case -3: if (zoomType > 0) { m.scale(0.5, 0.5); zoom = -2; setMatrix(m); } break; case -2: if (zoomType < 0) { m.scale(0.25, 0.25); zoom = -3; } else { m.scale(0.75, 0.75); zoom = -1; } setMatrix(m); break; case -1: if (zoomType < 0) { m.scale(0.5, 0.5); zoom = -2; } else { m.scale(1, 1); zoom = 0; } setMatrix(m); break; case 0: if (zoomType < 0) { m.scale(0.75, 0.75); zoom = -1; } else { m.scale(1.25, 1.25); zoom = 1; } setMatrix(m); break; case 1: if (zoomType < 0) { m.scale(1, 1); zoom = 0; } else { m.scale(1.5, 1.5); zoom = 2; } setMatrix(m); break; case 2: if (zoomType < 0) { m.scale(1.25, 1.25); zoom = 1; } else { m.scale(1.75, 1.75); zoom = 3; } setMatrix(m); break; case 3: if (zoomType < 0) { m.scale(1.5, 1.5); zoom = 2; } else { m.scale(2, 2); zoom = 4; } setMatrix(m); break; case 4: if (zoomType < 0) { m.scale(1.75, 1.75); zoom = 3; } else { m.scale(2.25, 2.25); zoom = 5; } setMatrix(m); break; case 5: if (zoomType < 0) { m.scale(2, 2); zoom = 4; setMatrix(m); } break; } }
int main(int argc, char** argv) { osg::ArgumentParser arguments( &argc, argv ); std::string dbPath; arguments.read("--db_path", dbPath); std::srand ( unsigned ( std::time(0) ) ); auto board = Board(boardDefinition, boardSizeX, boardSizeY, dbPath); auto ghostFactory = GhostFactory(); auto main_obj = make_ref<osg::Group>(); main_obj->addChild(board.draw().get()); auto ghostModel = osgDB::readNodeFile(dbPath + "/cow.osg"); auto ghostCount = 16; while(ghostCount--) { main_obj->addChild(ghostFactory.drawGhost(board, ghostModel).get()); } // init rotate auto init_rotate = make_ref<osg::MatrixTransform>(); init_rotate->setMatrix( osg::Matrix::rotate(osg::PI * 2, osg::Vec3(1.0f, 0.0f, 0.0f)) ); // chain rotates init_rotate->addChild(main_obj); // Root group auto root = make_ref<osg::Group>(); root->addChild(init_rotate); // Setup fog if(FogEnabled) { osg::ref_ptr<osg::Fog> fog = new osg::Fog; fog->setMode( osg::Fog::EXP2 ); fog->setStart( 0.0f ); fog->setEnd(board.getFieldSizeX() * 20); fog->setDensity(0.0135); fog->setColor( osg::Vec4(0., 0., 0., 1.0) ); root->getOrCreateStateSet()->setAttributeAndModes(fog.get()); } // Start viewer osgViewer::Viewer viewer; // Set up flashlight auto lightSource = make_ref<osg::LightSource>(); lightSource->setReferenceFrame(osg::LightSource::ABSOLUTE_RF); auto light = lightSource->getLight(); const osg::Vec3 lightPosition{1.5, -1, -1}; // right, down, front light->setPosition(osg::Vec4{lightPosition, 1}); light->setDirection(osg::Vec3{0, 0, -1} * 30 - lightPosition); light->setSpotExponent(60); light->setSpotCutoff(90); light->setDiffuse(osg::Vec4(1, 1, 1, 1)); light->setAmbient(osg::Vec4(0.6, 0.6, 0.6, 1)); light->setSpecular(osg::Vec4(1, 1, 1, 1)); light->setLinearAttenuation(0.001); light->setConstantAttenuation(0.5); root->addChild(lightSource); double height = std::min(board.getFieldSizeX(), board.getFieldSizeY()) / 1.5; auto fpsManipulator = make_ref<FPSManipulator>(board, viewer, *light); fpsManipulator->setHomePosition( osg::Vec3d(board.getFieldCenterX(1), board.getFieldCenterY(10), height), osg::Vec3d(0.0f, 0.0f, height), osg::Vec3d(0.0f, 0.0f, 1.0f) ); auto keySwitch = make_ref<osgGA::KeySwitchMatrixManipulator>(); keySwitch->addNumberedMatrixManipulator(make_ref<osgGA::OrbitManipulator>()); keySwitch->addNumberedMatrixManipulator(fpsManipulator); viewer.setCameraManipulator(keySwitch); viewer.home(); viewer.setSceneData( root ); osgViewer::Viewer::Windows windows; viewer.getWindows(windows); viewer.getCamera()->setClearColor(osg::Vec4{0, 0, 0, 0}); viewer.getCamera()->getView()->setLightingMode(osg::View::HEADLIGHT); auto defaultLight = viewer.getCamera()->getView()->getLight(); defaultLight->setDiffuse(osg::Vec4(0, 0, 0, 1)); defaultLight->setAmbient(osg::Vec4(0, 0, 0, 1)); defaultLight->setSpecular(osg::Vec4(0, 0, 0, 1)); // Shaders auto program = make_ref<osg::Program>(); auto fragmentObject = make_ref<osg::Shader>(osg::Shader::FRAGMENT); loadShaderSource(fragmentObject, dbPath + "/shader.frag"); auto vertexObject = make_ref<osg::Shader>(osg::Shader::VERTEX); loadShaderSource(vertexObject, dbPath + "/shader.vert"); program->addShader(vertexObject); program->addShader(fragmentObject); root->getOrCreateStateSet()->setAttributeAndModes(program, osg::StateAttribute::ON); root->getOrCreateStateSet()->addUniform(new osg::Uniform("samplerName", TEXTURE_UNIT)); root->getOrCreateStateSet()->addUniform(new osg::Uniform("Shininess", BoardObjectsShininess)); root->getOrCreateStateSet()->addUniform(new osg::Uniform("FogEnabled", FogEnabled)); // Optimize osgUtil::Optimizer optimzer; optimzer.optimize(root); viewer.setUpViewOnSingleScreen(0); return viewer.run(); }
////////////////////////////////////////////////////////////////////////// // setMatirx // (desc) call by outside // set transformation matrix ////////////////////////////////////////////////////////////////////////// bool ZShadow::setMatrix(ZCharacterObject& char_, float size_ ) { return setMatrix( *char_.m_pVMesh ,size_); }
void loadMatrix(e2dMatrix* mat) { static float matrix[16]; setMatrix(matrix, mat); glLoadMatrixf(matrix); }
void multMatrix(e2dMatrix* mat) { static float matrix[16]; setMatrix(matrix, mat); glMultMatrixf(matrix); }
void PSMoveForm::parseMoveData(MoveData d) { setButtons(d.buttons); ui->tempLcdNumber->display(d.temperature); if (d.battery <= 5) { for (int i = 0; i < 5; i++) { mBatteryCheckBoxes[i].setChecked(i < d.battery); } mBatteryLayout->setCurrentIndex(0); } else { mBatteryLayout->setCurrentIndex(1); } //emit setRumble(d.buttons.trigger); /*const QVector3D acc = d.accelerometer.normalized() * 128 + QVector3D(128, 128, 128); const QColor rgb(acc.x(), acc.y(), acc.z()); static int w = 0; if (w++ == 10) { w = 0; emit setRgb(rgb); }*/ //QVector3D normalisedAcc = d.accelerometer / 32768; //QVector3D normalisedMag = d.mag / 32768; //normalisedAcc.normalize(); //normalisedMag = QVector3D::crossProduct(normalisedMag.normalized(), normalisedAcc).normalized(); //QVector3D north = QVector3D::crossProduct(normalisedMag, normalisedAcc).normalized(); bool movePressedB = d.buttons.buttonsPressed.contains(MoveButtons::Move); if (!mPrevMovePressed && movePressedB) { //mOne = normalisedAcc; //mTwo = normalisedMag; //mThree = north; qDebug() << "acc:" << d.accelerometer; qDebug() << "mag:" << d.mag; emit movePressed(); } mPrevMovePressed = movePressedB; /*float one = std::acos(QVector3D::dotProduct(normalisedAcc, mOne)); float two = std::acos(QVector3D::dotProduct(normalisedMag, mTwo)); float three = std::acos(QVector3D::dotProduct(north, mThree));*/ //qDebug() << QString::number(one, 'g', 4) << QString::number(two, 'g', 4) << QString::number(three, 'g', 4); /*ui->accXProgressBar->setValue(one * 180 / M_PI); ui->accYProgressBar->setValue(two * 180 / M_PI); ui->accZProgressBar->setValue(three * 180 / M_PI);*/ if (ui->accGroupBox->isChecked()) { ui->accXProgressBar->setValue(d.accelerometer.x()); ui->accYProgressBar->setValue(d.accelerometer.y()); ui->accZProgressBar->setValue(d.accelerometer.z()); } if (ui->gyroGroupBox->isChecked()) { ui->gyroXProgressBar->setValue(d.gyro.x()); ui->gyroYProgressBar->setValue(d.gyro.y()); ui->gyroZProgressBar->setValue(d.gyro.z()); } if (ui->magGroupBox->isChecked()) { ui->magXProgressBar->setValue(d.mag.x()); ui->magYProgressBar->setValue(d.mag.y()); ui->magZProgressBar->setValue(d.mag.z()); } bool triPressed = d.buttons.buttonsPressed.contains(MoveButtons::Triangle); if (triPressed && !mPrevTriPressed) { emit setTopRightCorner(); } mPrevTriPressed = triPressed; bool squPressed = d.buttons.buttonsPressed.contains(MoveButtons::Square); if (squPressed && !mPrevSquPressed) { emit setBottomLeftCorner(); } mPrevSquPressed = squPressed; #if 0 QVector3D acc = d.accelerometer; QVector3D mag = d.mag; acc.normalize(); mag.normalize(); QMatrix4x4 m; m.setRow(2, acc); QVector3D east = QVector3D::crossProduct(acc, -mag); m.setRow(0, east); QVector3D north = QVector3D::crossProduct(acc, -mag); m.setRow(1, north); //qDebug() << mag; // QVector3D gyro = d.gyro / 32768; // acc.setX(mAccFilters[0]->step(acc.x())); // acc.setY(mAccFilters[1]->step(acc.y())); // acc.setZ(mAccFilters[2]->step(acc.z())); // mag.setX(mMagFilters[0]->step(mag.x())); // mag.setY(mMagFilters[1]->step(mag.y())); // mag.setZ(mMagFilters[2]->step(mag.z())); QVector3D newY = acc; QVector3D newZ = mag; newZ.setZ(-newZ.z()); QVector3D newX = QVector3D::crossProduct(newZ, newY).normalized(); QMatrix4x4 newMat; newMat.setRow(0, newX); newMat.setRow(1, newY); newMat.setRow(2, newZ); newMat.setRow(3, QVector4D(0, 0, 0, 1)); float qq1 = q0; float qq2 = q1; float qq3 = q2; float qq4 = q3; QQuaternion quat(qq1, qq2, qq3, qq4); QVector3D vec(1, 1, 1); emit setMatrix(newMat); //emit setVector(quat.rotatedVector(vec)); #endif }
void QtWebPageSGNode::setScale(float scale) { QMatrix4x4 matrix; matrix.scale(scale); setMatrix(matrix); }
void EnlightedNode::updateMatrix(QFixture* fixture) { setMatrix(fixture->body()->matrix() * fixture->matrix()); }
AffineTransform::AffineTransform() { setMatrix(1, 0, 0, 1, 0, 0); }
void BigArray<T>::setMatrix(unsigned long startingRow, unsigned long startingCol, const gMat2D<T>&value) { setMatrix(startingRow, startingCol, value.getData(), value.rows(), value.cols()); }
void AffineTransform::makeIdentity() { setMatrix(1, 0, 0, 1, 0, 0); }
void BigArray<T>::readCSV(const std::string& fileName) { int myid; int numprocs; MPI_Comm_size(MPI_COMM_WORLD, &numprocs); MPI_Comm_rank(MPI_COMM_WORLD, &myid); unsigned long rows = 0; unsigned long cols = 0; typedef boost::tokenizer<boost::char_separator<char> > tokenizer; boost::char_separator<char> sep(" ;|,"); std::string line; if(myid == 0) { std::ifstream in(fileName.c_str()); if(!in.is_open()) throw gurls::gException("Cannot open file " + fileName); while(std::getline(in, line)) { if(!line.empty()) ++rows; if(rows == 1) { tokenizer tokens(line, sep); for (tokenizer::iterator t_it = tokens.begin(); t_it != tokens.end(); ++t_it) ++cols; } } in.close(); } MPI_Bcast(&rows, 1, MPI_UNSIGNED_LONG, 0, MPI_COMM_WORLD); MPI_Bcast(&cols, 1, MPI_UNSIGNED_LONG, 0, MPI_COMM_WORLD); close(); init(dataFileName, rows, cols); if(rows == 0 || cols == 0) return; unsigned long block_rows = rows/numprocs; const unsigned long first_row = myid*block_rows; if(myid == numprocs -1) block_rows += rows%numprocs; const unsigned long last_row = first_row+block_rows-1; std::ifstream in(fileName.c_str()); if(!in.is_open()) throw gurls::gException("Cannot open file " + fileName); T* block_transposed = new T[cols*block_rows]; T* rv_it = block_transposed; tokenizer::iterator t_it; unsigned long row = 0; while (std::getline(in, line)) { if(!line.empty()) { if(row >= first_row && row <= last_row) { tokenizer tokens(line, sep); for (t_it = tokens.begin(); t_it != tokens.end(); ++t_it, ++rv_it) *rv_it = boost::lexical_cast<T>(*t_it); } ++row; } } in.close(); T* block = new T[block_rows*cols]; gurls::transpose(block_transposed, cols, block_rows, block); setMatrix(first_row, 0, block, block_rows, cols); delete[] block_transposed; delete[] block; MPI_Barrier(MPI_COMM_WORLD); }
GLuint OpenSubdivPtexShader::bindProgram(const MHWRender::MDrawContext & mDrawContext, OpenSubdiv::OsdGLDrawContext *osdDrawContext, const OpenSubdiv::OsdPatchArray & patch) { CHECK_GL_ERROR("bindProgram begin\n"); // Build shader Effect effect; effect.color = _enableColor; effect.occlusion = _enableOcclusion; effect.displacement = _enableDisplacement; effect.normal = _enableNormal; EffectDesc effectDesc( patch.desc, effect ); EffectDrawRegistry::ConfigType * config = effectRegistry.GetDrawConfig(effectDesc); // Install shader GLuint program = config->program; glUseProgram(program); // Update and bind transform state struct Transform { float ModelViewMatrix[16]; float ProjectionMatrix[16]; float ModelViewProjectionMatrix[16]; } transformData; setMatrix(mDrawContext.getMatrix(MHWRender::MDrawContext::kWorldViewMtx), transformData.ModelViewMatrix); setMatrix(mDrawContext.getMatrix(MHWRender::MDrawContext::kProjectionMtx), transformData.ProjectionMatrix); setMatrix(mDrawContext.getMatrix(MHWRender::MDrawContext::kWorldViewProjMtx), transformData.ModelViewProjectionMatrix); if (!g_transformUB) { glGenBuffers(1, &g_transformUB); glBindBuffer(GL_UNIFORM_BUFFER, g_transformUB); glBufferData(GL_UNIFORM_BUFFER, sizeof(transformData), NULL, GL_STATIC_DRAW); }; glBindBuffer(GL_UNIFORM_BUFFER, g_transformUB); glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(transformData), &transformData); glBindBuffer(GL_UNIFORM_BUFFER, 0); glBindBufferBase(GL_UNIFORM_BUFFER, g_transformBinding, g_transformUB); // Update and bind tessellation state struct Tessellation { float TessLevel; int GregoryQuadOffsetBase; int PrimitiveIdBase; } tessellationData; tessellationData.TessLevel = static_cast<float>(1 << _tessFactor); tessellationData.GregoryQuadOffsetBase = patch.GetQuadOffsetBase; tessellationData.PrimitiveIdBase = patch.GetPatchIndex();; if (!g_tessellationUB) { glGenBuffers(1, &g_tessellationUB); glBindBuffer(GL_UNIFORM_BUFFER, g_tessellationUB); glBufferData(GL_UNIFORM_BUFFER, sizeof(tessellationData), NULL, GL_STATIC_DRAW); }; glBindBuffer(GL_UNIFORM_BUFFER, g_tessellationUB); glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(tessellationData), &tessellationData); glBindBuffer(GL_UNIFORM_BUFFER, 0); glBindBufferBase(GL_UNIFORM_BUFFER, g_tessellationBinding, g_tessellationUB); #ifdef USE_NON_IMAGE_BASED_LIGHTING // Update and bind lighting state int numLights = mDrawContext.numberOfActiveLights(); struct Lighting { struct Light { float position[4]; float diffuse[4]; float ambient[4]; float specular[4]; } lightSource[2]; } lightingData; memset(&lightingData, 0, sizeof(lightingData)); for (int i = 0; i < numLights && i < 1; ++i) { MFloatPointArray positions; MFloatVector direction; float intensity; MColor color; bool hasDirection, hasPosition; mDrawContext.getLightInformation(i, positions, direction, intensity, color, hasDirection, hasPosition); Lighting::Light &light = lightingData.lightSource[i]; if (hasDirection) { light.position[0] = -direction[0]; light.position[1] = -direction[1]; light.position[2] = -direction[2]; for (int j = 0; j < 4; ++j) { light.diffuse[j] = color[j] * intensity; light.ambient[j] = color[j] * intensity; light.specular[j] = color[j] * intensity; } } } if (!g_lightingUB) { glGenBuffers(1, &g_lightingUB); glBindBuffer(GL_UNIFORM_BUFFER, g_lightingUB); glBufferData(GL_UNIFORM_BUFFER, sizeof(lightingData), NULL, GL_STATIC_DRAW); }; glBindBuffer(GL_UNIFORM_BUFFER, g_lightingUB); glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(lightingData), &lightingData); glBindBuffer(GL_UNIFORM_BUFFER, 0); glBindBufferBase(GL_UNIFORM_BUFFER, g_lightingBinding, g_lightingUB); #endif GLint eye = glGetUniformLocation(program, "eyePositionInWorld"); MPoint e = MPoint(0, 0, 0) * mDrawContext.getMatrix(MHWRender::MDrawContext::kWorldViewInverseMtx); glProgramUniform3f(program, eye, static_cast<float>(e.x), static_cast<float>(e.y), static_cast<float>(e.z)); // update other uniforms float color[4] = { 0, 0, 0, 1 }; _diffuse.get(color); glProgramUniform4fv(program, glGetUniformLocation(program, "diffuseColor"), 1, color); _ambient.get(color); glProgramUniform4fv(program, glGetUniformLocation(program, "ambientColor"), 1, color); _specular.get(color); glProgramUniform4fv(program, glGetUniformLocation(program, "specularColor"), 1, color); glProgramUniform1f(program, glGetUniformLocation(program, "fresnelBias"), _fresnelBias); glProgramUniform1f(program, glGetUniformLocation(program, "fresnelScale"), _fresnelScale); glProgramUniform1f(program, glGetUniformLocation(program, "fresnelPower"), _fresnelPower); // Ptex bindings // color ptex if (effectRegistry.getPtexColorValid()) { GLint texData = glGetUniformLocation(program, "textureImage_Data"); glProgramUniform1i(program, texData, CLR_TEXTURE_UNIT + 0); GLint texPacking = glGetUniformLocation(program, "textureImage_Packing"); glProgramUniform1i(program, texPacking, CLR_TEXTURE_UNIT + 1); GLint texPages = glGetUniformLocation(program, "textureImage_Pages"); glProgramUniform1i(program, texPages, CLR_TEXTURE_UNIT + 2); } // displacement ptex if (effectRegistry.getPtexDisplacementValid()) { GLint texData = glGetUniformLocation(program, "textureDisplace_Data"); glProgramUniform1i(program, texData, DISP_TEXTURE_UNIT + 0); GLint texPacking = glGetUniformLocation(program, "textureDisplace_Packing"); glProgramUniform1i(program, texPacking, DISP_TEXTURE_UNIT + 1); GLint texPages = glGetUniformLocation(program, "textureDisplace_Pages"); glProgramUniform1i(program, texPages, DISP_TEXTURE_UNIT + 2); } // occlusion ptex if (effectRegistry.getPtexOcclusionValid()) { GLint texData = glGetUniformLocation(program, "textureOcclusion_Data"); glProgramUniform1i(program, texData, OCC_TEXTURE_UNIT + 0); GLint texPacking = glGetUniformLocation(program, "textureOcclusion_Packing"); glProgramUniform1i(program, texPacking, OCC_TEXTURE_UNIT + 1); GLint texPages = glGetUniformLocation(program, "textureOcclusion_Pages"); glProgramUniform1i(program, texPages, OCC_TEXTURE_UNIT + 2); } // diffuse environment map if (effectRegistry.getDiffuseEnvironmentId() != 0) { GLint difmap = glGetUniformLocation(program, "diffuseEnvironmentMap"); glProgramUniform1i(program, difmap, DIFF_TEXTURE_UNIT); } // specular environment map if (effectRegistry.getSpecularEnvironmentId() != 0) { GLint envmap = glGetUniformLocation(program, "specularEnvironmentMap"); glProgramUniform1i(program, envmap, ENV_TEXTURE_UNIT); } glActiveTexture(GL_TEXTURE0); CHECK_GL_ERROR("bindProgram leave\n"); return program; }
void FixedFunctionPainter::setMatrices (const QMatrix4x4 &mv, const QMatrix4x4 &proj) { setMatrix(GL_PROJECTION, proj); setMatrix(GL_MODELVIEW, mv); }
void MatrixTransform::setValue(const float * m44, const float * offset4) { setMatrix(m44); setOffset(offset4); }
namespace SkRecords { // FIXME: SkBitmaps are stateful, so we need to copy them to play back in multiple threads. static SkBitmap shallow_copy(const SkBitmap& bitmap) { return bitmap; } // NoOps draw nothing. template <> void Draw::draw(const NoOp&) {} #define DRAW(T, call) template <> void Draw::draw(const T& r) { fCanvas->call; } DRAW(Restore, restore()); DRAW(Save, save()); DRAW(SaveLayer, saveLayer(r.bounds, r.paint, r.flags)); DRAW(PopCull, popCull()); DRAW(PushCull, pushCull(r.rect)); DRAW(Clear, clear(r.color)); DRAW(Concat, concat(r.matrix)); DRAW(SetMatrix, setMatrix(SkMatrix::Concat(fInitialCTM, r.matrix))); DRAW(ClipPath, clipPath(r.path, r.op, r.doAA)); DRAW(ClipRRect, clipRRect(r.rrect, r.op, r.doAA)); DRAW(ClipRect, clipRect(r.rect, r.op, r.doAA)); DRAW(ClipRegion, clipRegion(r.region, r.op)); DRAW(DrawBitmap, drawBitmap(shallow_copy(r.bitmap), r.left, r.top, r.paint)); DRAW(DrawBitmapMatrix, drawBitmapMatrix(shallow_copy(r.bitmap), r.matrix, r.paint)); DRAW(DrawBitmapNine, drawBitmapNine(shallow_copy(r.bitmap), r.center, r.dst, r.paint)); DRAW(DrawBitmapRectToRect, drawBitmapRectToRect(shallow_copy(r.bitmap), r.src, r.dst, r.paint, r.flags)); DRAW(DrawDRRect, drawDRRect(r.outer, r.inner, r.paint)); DRAW(DrawOval, drawOval(r.oval, r.paint)); DRAW(DrawPaint, drawPaint(r.paint)); DRAW(DrawPath, drawPath(r.path, r.paint)); DRAW(DrawPatch, drawPatch(r.cubics, r.colors, r.texCoords, r.xmode.get(), r.paint)); DRAW(DrawPicture, drawPicture(r.picture, r.matrix, r.paint)); DRAW(DrawPoints, drawPoints(r.mode, r.count, r.pts, r.paint)); DRAW(DrawPosText, drawPosText(r.text, r.byteLength, r.pos, r.paint)); DRAW(DrawPosTextH, drawPosTextH(r.text, r.byteLength, r.xpos, r.y, r.paint)); DRAW(DrawRRect, drawRRect(r.rrect, r.paint)); DRAW(DrawRect, drawRect(r.rect, r.paint)); DRAW(DrawSprite, drawSprite(shallow_copy(r.bitmap), r.left, r.top, r.paint)); DRAW(DrawText, drawText(r.text, r.byteLength, r.x, r.y, r.paint)); DRAW(DrawTextOnPath, drawTextOnPath(r.text, r.byteLength, r.path, r.matrix, r.paint)); DRAW(DrawVertices, drawVertices(r.vmode, r.vertexCount, r.vertices, r.texs, r.colors, r.xmode.get(), r.indices, r.indexCount, r.paint)); #undef DRAW // This is an SkRecord visitor that fills an SkBBoxHierarchy. // // The interesting part here is how to calculate bounds for ops which don't // have intrinsic bounds. What is the bounds of a Save or a Translate? // // We answer this by thinking about a particular definition of bounds: if I // don't execute this op, pixels in this rectangle might draw incorrectly. So // the bounds of a Save, a Translate, a Restore, etc. are the union of the // bounds of Draw* ops that they might have an effect on. For any given // Save/Restore block, the bounds of the Save, the Restore, and any other // non-drawing ("control") ops inside are exactly the union of the bounds of // the drawing ops inside that block. // // To implement this, we keep a stack of active Save blocks. As we consume ops // inside the Save/Restore block, drawing ops are unioned with the bounds of // the block, and control ops are stashed away for later. When we finish the // block with a Restore, our bounds are complete, and we go back and fill them // in for all the control ops we stashed away. class FillBounds : SkNoncopyable { public: FillBounds(const SkRecord& record, SkBBoxHierarchy* bbh) : fBounds(record.count()) { // Calculate bounds for all ops. This won't go quite in order, so we'll need // to store the bounds separately then feed them in to the BBH later in order. fCTM.setIdentity(); for (fCurrentOp = 0; fCurrentOp < record.count(); fCurrentOp++) { record.visit<void>(fCurrentOp, *this); } // If we have any lingering unpaired Saves, simulate restores to make // sure all ops in those Save blocks have their bounds calculated. while (!fSaveStack.isEmpty()) { this->popSaveBlock(); } // Any control ops not part of any Save/Restore block draw everywhere. while (!fControlIndices.isEmpty()) { this->popControl(SkIRect::MakeLargest()); } // Finally feed all stored bounds into the BBH. They'll be returned in this order. SkASSERT(NULL != bbh); for (uintptr_t i = 0; i < record.count(); i++) { if (!fBounds[i].isEmpty()) { bbh->insert((void*)i, fBounds[i], true/*ok to defer*/); } } bbh->flushDeferredInserts(); } template <typename T> void operator()(const T& r) { this->updateCTM(r); this->trackBounds(r); } private: struct SaveBounds { int controlOps; // Number of control ops in this Save block, including the Save. SkIRect bounds; // Bounds of everything in the block. }; template <typename T> void updateCTM(const T&) { /* most ops don't change the CTM */ } void updateCTM(const Restore& r) { fCTM = r.matrix; } void updateCTM(const SetMatrix& r) { fCTM = r.matrix; } void updateCTM(const Concat& r) { fCTM.preConcat(r.matrix); } // The bounds of these ops must be calculated when we hit the Restore // from the bounds of the ops in the same Save block. void trackBounds(const Save&) { this->pushSaveBlock(); } // TODO: bounds of SaveLayer may be more complicated? void trackBounds(const SaveLayer&) { this->pushSaveBlock(); } void trackBounds(const Restore&) { fBounds[fCurrentOp] = this->popSaveBlock(); } void trackBounds(const Concat&) { this->pushControl(); } void trackBounds(const SetMatrix&) { this->pushControl(); } void trackBounds(const ClipRect&) { this->pushControl(); } void trackBounds(const ClipRRect&) { this->pushControl(); } void trackBounds(const ClipPath&) { this->pushControl(); } void trackBounds(const ClipRegion&) { this->pushControl(); } // For all other ops, we can calculate and store the bounds directly now. template <typename T> void trackBounds(const T& op) { fBounds[fCurrentOp] = this->bounds(op); this->updateSaveBounds(fBounds[fCurrentOp]); } // TODO: remove this trivially-safe default when done bounding all ops template <typename T> SkIRect bounds(const T&) { return SkIRect::MakeLargest(); } void pushSaveBlock() { // Starting a new Save block. Push a new entry to represent that. SaveBounds sb = { 0, SkIRect::MakeEmpty() }; fSaveStack.push(sb); this->pushControl(); } SkIRect popSaveBlock() { // We're done the Save block. Apply the block's bounds to all control ops inside it. SaveBounds sb; fSaveStack.pop(&sb); while (sb.controlOps --> 0) { this->popControl(sb.bounds); } // This whole Save block may be part another Save block. this->updateSaveBounds(sb.bounds); // If called from a real Restore (not a phony one for balance), it'll need the bounds. return sb.bounds; } void pushControl() { fControlIndices.push(fCurrentOp); if (!fSaveStack.isEmpty()) { fSaveStack.top().controlOps++; } } void popControl(const SkIRect& bounds) { fBounds[fControlIndices.top()] = bounds; fControlIndices.pop(); } void updateSaveBounds(const SkIRect& bounds) { // If we're in a Save block, expand its bounds to cover these bounds too. if (!fSaveStack.isEmpty()) { fSaveStack.top().bounds.join(bounds); } } SkIRect bounds(const NoOp&) { return SkIRect::MakeEmpty(); } // NoOps don't draw anywhere. SkAutoTMalloc<SkIRect> fBounds; // One for each op in the record. SkMatrix fCTM; unsigned fCurrentOp; SkTDArray<SaveBounds> fSaveStack; SkTDArray<unsigned> fControlIndices; }; } // namespace SkRecords
REPORTER_ASSERT_MESSAGE(reporter, canvas-> CALL , \ testStep->assertMessage()); \ } \ TEST_STEP(NAME, NAME##TestStep ) /////////////////////////////////////////////////////////////////////////////// // Basic test steps for most virtual methods in SkCanvas that draw or affect // the state of the canvas. SIMPLE_TEST_STEP(Translate, translate(SkIntToScalar(1), SkIntToScalar(2))); SIMPLE_TEST_STEP(Scale, scale(SkIntToScalar(1), SkIntToScalar(2))); SIMPLE_TEST_STEP(Rotate, rotate(SkIntToScalar(1))); SIMPLE_TEST_STEP(Skew, skew(SkIntToScalar(1), SkIntToScalar(2))); SIMPLE_TEST_STEP(Concat, concat(d.fMatrix)); SIMPLE_TEST_STEP(SetMatrix, setMatrix(d.fMatrix)); SIMPLE_TEST_STEP(ClipRect, clipRect(d.fRect)); SIMPLE_TEST_STEP(ClipPath, clipPath(d.fPath)); SIMPLE_TEST_STEP(ClipRegion, clipRegion(d.fRegion, SkRegion::kReplace_Op)); SIMPLE_TEST_STEP(Clear, clear(d.fColor)); /////////////////////////////////////////////////////////////////////////////// // Complex test steps static void SaveMatrixClipStep(SkCanvas* canvas, const TestData& d, skiatest::Reporter* reporter, CanvasTestStep* testStep) { int saveCount = canvas->getSaveCount(); canvas->save(); canvas->translate(SkIntToScalar(1), SkIntToScalar(2)); canvas->clipRegion(d.fRegion); canvas->restore();
std::shared_ptr<raytracer::Primitive> Surface::applyTransform(std::shared_ptr<raytracer::Primitive> primitive) const { auto result = std::make_shared<raytracer::Instance>(primitive); result->setMatrix(localTransform()); return result; }