Esempio n. 1
0
VOID render(){
	g_pDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
		D3DCOLOR_XRGB(192, 192, 192), 1.0f, 0);

	if(SUCCEEDED(g_pDevice->BeginScene())){

		setWorldMatrix();
		//First, Render the not transparent part
		for(DWORD i=0; i<g_dwNumMaterials; ++i){
			if(g_pMeshMaterials[i].Diffuse.a == 1.0f){
				g_pDevice->SetMaterial(&g_pMeshMaterials[i]);
				g_pDevice->SetTexture(0, g_pMeshTextures[i]);

				g_pMesh->DrawSubset(i);
			}
		}

		//Second , Render the transparent part
		for(DWORD i=0; i<g_dwNumMaterials; ++i){
			if(g_pMeshMaterials[i].Diffuse.a != 1.0f){
				g_pDevice->SetMaterial(&g_pMeshMaterials[i]);
				g_pDevice->SetTexture(0, g_pMeshTextures[i]);

				g_pMesh->DrawSubset(i);
			}
		}
		g_pDevice->EndScene();
	}
	g_pDevice->Present(NULL, NULL, NULL, NULL);
}
Esempio n. 2
0
/**
 * Draws image.
 */
void RS_PainterQt::drawImg(QImage& img, const RS_Vector& pos,
                           double angle, const RS_Vector& factor,
                           int sx, int sy, int sw, int sh) {
    save();

    // Render smooth only at close zooms
    if (factor.x < 1 || factor.y < 1) {
       RS_PainterQt::setRenderHint(SmoothPixmapTransform , TRUE);
    }
    else {
      RS_PainterQt::setRenderHint(SmoothPixmapTransform);
    }

    QMatrix wm;
    wm.translate(pos.x, pos.y);
    wm.scale(factor.x, factor.y);
    wm.rotate(RS_Math::rad2deg(-angle));
    setWorldMatrix(wm);


    if (fabs(angle)<1.0e-4) {
        drawImage(0+sx,-img.height()+sy, img, sx, sy, sw, sh);
    }
    else {
        drawImage(0,-img.height(), img);
    }

    restore();
}
Esempio n. 3
0
HRESULT init3D(HWND hWnd){
	if(NULL == (g_pD3D = Direct3DCreate9(D3D_SDK_VERSION)))
		return E_FAIL;

	D3DPRESENT_PARAMETERS d3dpp; 
	ZeroMemory( &d3dpp, sizeof(d3dpp) );
	d3dpp.Windowed = TRUE;
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
	d3dpp.EnableAutoDepthStencil = TRUE;
	d3dpp.AutoDepthStencilFormat = D3DFMT_D16;

	if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
		D3DCREATE_SOFTWARE_VERTEXPROCESSING,
		&d3dpp, &g_pDevice ) ) )
		return E_FAIL;
	//open the z test
	g_pDevice->SetRenderState(D3DRS_ZENABLE, true);
	//set the test method
	g_pDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESS);	//default is LESSQUAL
	g_pDevice->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);//default

	g_pDevice->SetRenderState(D3DRS_AMBIENT, 0xffffffff);

	setWorldMatrix();
	setViewProjMatrix();
	
	D3DXMatrixIdentity(&g_matTank);
	D3DXMatrixRotationY(&g_matTank, D3DX_PI / 2);
	D3DXMatrixIdentity(&g_matShutter);

	return S_OK;
}
Esempio n. 4
0
//}}}1
//{{{1 private functions
void Scene::buildScene(Json::Value node) {
    Json::Value cam = node["camera"];
    buildCamera(cam);

    Json::Value lights = node["lights"];
    for(int i=0; i<lights.size(); i++) {
        buildLight(lights[i]);
    }

    Json::Value models = node["models"];
    for(int i=0; i<models.size(); i++) {
        buildNode(models[i]);
    }

    if(node.isMember("instances")) {
        Json::Value instances = node["instances"];
        for(int i=0; i<instances.size(); i++) {
            buildInstance(instances[i]);
        }
    }

    Json::Value anims = node["animations"];
    for(int i=0; i<anims.size(); i++) {
        buildAnimation(anims[i]);
    }

    mat4 wm = LookAt(eye, at, up);
    setWorldMatrix(LookAt(eye, at, up));
    printf("set init world matrix\n");
}
Esempio n. 5
0
void CubeProxyGeometry::process() {
    vec3 startDataTexCoord = vec3(0.0f);
    vec3 extent = vec3(1.0f); //!< will be added to the origin in the parallelepiped() yielding the end position

    if (inport_.getData()->getMetaData<BoolMetaData>("marginsEnabled", false)) {
        // volume has margins enabled
        // adjust start and end texture coordinate accordingly
        auto marginsBottomLeft = inport_.getData()->getMetaData<FloatVec3MetaData>("marginsBottomLeft", vec3(0.0f));
        auto marginsTopRight = inport_.getData()->getMetaData<FloatVec3MetaData>("marginsTopRight", vec3(0.0f));

        startDataTexCoord += marginsBottomLeft;
        // extent needs to be adjusted for both margins
        extent -= marginsBottomLeft + marginsTopRight;
    }

    glm::vec3 pos(0.0f);
    glm::vec3 p1(1.0f, 0.0f, 0.0f);
    glm::vec3 p2(0.0f, 1.0f, 0.0f);
    glm::vec3 p3(0.0f, 0.0f, 1.0f);
    glm::vec3 tex(startDataTexCoord);
    glm::vec3 t1(extent.x, 0.0f, 0.0f);
    glm::vec3 t2(0.0f, extent.y, 0.0f);
    glm::vec3 t3(0.0f, 0.0f, extent.z);
    glm::vec4 col(startDataTexCoord, 1.0f);
    glm::vec4 c1(t1, 0.0f);
    glm::vec4 c2(t2, 0.0f);
    glm::vec4 c3(t3, 0.0f);
    auto dims = inport_.getData()->getDimensions();

    if (clippingEnabled_.get()) {
        pos = pos + p1*static_cast<float>(clipX_.get().x)/static_cast<float>(dims.x)
                  + p2*static_cast<float>(clipY_.get().x)/static_cast<float>(dims.y)
                  + p3*static_cast<float>(clipZ_.get().x)/static_cast<float>(dims.z);
        p1 = p1*(static_cast<float>(clipX_.get().y)-static_cast<float>(clipX_.get().x))/static_cast<float>(dims.x);
        p2 = p2*(static_cast<float>(clipY_.get().y)-static_cast<float>(clipY_.get().x))/static_cast<float>(dims.y);
        p3 = p3*(static_cast<float>(clipZ_.get().y)-static_cast<float>(clipZ_.get().x))/static_cast<float>(dims.z);
        tex = tex + t1*static_cast<float>(clipX_.get().x)/static_cast<float>(dims.x)
                  + t2*static_cast<float>(clipY_.get().x)/static_cast<float>(dims.y)
                  + t3*static_cast<float>(clipZ_.get().x)/static_cast<float>(dims.z);
        t1 = t1*(static_cast<float>(clipX_.get().y)-static_cast<float>(clipX_.get().x))/static_cast<float>(dims.x);
        t2 = t2*(static_cast<float>(clipY_.get().y)-static_cast<float>(clipY_.get().x))/static_cast<float>(dims.y);
        t3 = t3*(static_cast<float>(clipZ_.get().y)-static_cast<float>(clipZ_.get().x))/static_cast<float>(dims.z);
        col = col + c1*static_cast<float>(clipX_.get().x)/static_cast<float>(dims.x)
                  + c2*static_cast<float>(clipY_.get().x)/static_cast<float>(dims.y)
                  + c3*static_cast<float>(clipZ_.get().x)/static_cast<float>(dims.z);
        c1 = c1*(static_cast<float>(clipX_.get().y)-static_cast<float>(clipX_.get().x))/static_cast<float>(dims.x);
        c2 = c2*(static_cast<float>(clipY_.get().y)-static_cast<float>(clipY_.get().x))/static_cast<float>(dims.y);
        c3 = c3*(static_cast<float>(clipZ_.get().y)-static_cast<float>(clipZ_.get().x))/static_cast<float>(dims.z);
    }

    // Create parallelepiped and set it to the outport. The outport will own the data.
    auto geom = SimpleMeshCreator::parallelepiped(pos, p1, p2, p3,
                                                  tex, t1, t2, t3,
                                                  col, c1, c2, c3);
    geom->setModelMatrix(inport_.getData()->getModelMatrix());
    geom->setWorldMatrix(inport_.getData()->getWorldMatrix());
    outport_.setData(geom);
}
Esempio n. 6
0
void StreamLines::process() {
    auto mesh = std::make_shared<BasicMesh>();
    mesh->setModelMatrix(sampler_.getData()->getModelMatrix());
    mesh->setWorldMatrix(sampler_.getData()->getWorldMatrix());

    auto m = streamLineProperties_.getSeedPointTransformationMatrix(
        sampler_.getData()->getCoordinateTransformer());


    ImageSampler tf(tf_.get().getData());

    float maxVelocity = 0;
    StreamLineTracer tracer(sampler_.getData(), streamLineProperties_);

    std::vector<BasicMesh::Vertex> vertices;

    for (const auto &seeds : seedPoints_) {
        for (auto &p : (*seeds)) {
            vec4 P = m * vec4(p, 1.0f);
            auto line = tracer.traceFrom(P.xyz());

            auto position = line.getPositions().begin();
            auto velocity = line.getMetaData("velocity").begin();

            auto size = line.getPositions().size();
            if (size == 0) continue;

            auto indexBuffer =
                mesh->addIndexBuffer(DrawType::Lines, ConnectivityType::StripAdjacency);

            indexBuffer->add(0);

            for (size_t i = 0; i < size; i++) {
                vec3 pos(*position);
                vec3 v(*velocity);

                float l = glm::length(vec3(*velocity));
                float d = glm::clamp(l / velocityScale_.get(), 0.0f, 1.0f);
                maxVelocity = std::max(maxVelocity, l);
                auto c = vec4(tf.sample(dvec2(d, 0.0)));

                indexBuffer->add(static_cast<std::uint32_t>(vertices.size()));

                vertices.push_back({pos, glm::normalize(v), pos, c});

                position++;
                velocity++;
            }
            indexBuffer->add(static_cast<std::uint32_t>(vertices.size() - 1));
        }
    }

    mesh->addVertices(vertices);

    linesStripsMesh_.setData(mesh);
    maxVelocity_.set(toString(maxVelocity));
}
Esempio n. 7
0
void CVBEditor::updateWorldMatrix() {
	double z = p_itemView->zoomLevel();
	QRect r = m_pCanvas->rect();
// 	QWMatrix m( z, 0.0, 0.0, z, -r.left(), -r.top() );
// 	QWMatrix m( z, 0.0, 0.0, z, 0.0, 0.0 );
	QWMatrix m;
	m.scale(z, z);
	m.translate(-r.left(), -r.top());
	setWorldMatrix(m);
}
Esempio n. 8
0
void Scene::mouseDragged(int dx, int dy) {
    float dPhi   = dx * pxToRad;
    float dTheta = dy * pxToRad;

    camTheta += dTheta;
    camPhi   += dPhi;

    recalculateCamera();

    mat4 mv = LookAt(eye, at, up);
    setWorldMatrix(mv);
}
Esempio n. 9
0
void GFXGLDevice::setClipRect( const RectI &inRect )
{
   AssertFatal(mCurrentRT.isValid(), "GFXGLDevice::setClipRect - must have a render target set to do any rendering operations!");

   // Clip the rect against the renderable size.
   Point2I size = mCurrentRT->getSize();
   RectI maxRect(Point2I(0,0), size);
   mClip = inRect;
   mClip.intersect(maxRect);

   // Create projection matrix.  See http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/ortho.html
   const F32 left = mClip.point.x;
   const F32 right = mClip.point.x + mClip.extent.x;
   const F32 bottom = mClip.extent.y;
   const F32 top = 0.0f;
   const F32 nearPlane = 0.0f;
   const F32 farPlane = 1.0f;
   
   const F32 tx = -(right + left)/(right - left);
   const F32 ty = -(top + bottom)/(top - bottom);
   const F32 tz = -(farPlane + nearPlane)/(farPlane - nearPlane);
   
   static Point4F pt;
   pt.set(2.0f / (right - left), 0.0f, 0.0f, 0.0f);
   mProjectionMatrix.setColumn(0, pt);
   
   pt.set(0.0f, 2.0f/(top - bottom), 0.0f, 0.0f);
   mProjectionMatrix.setColumn(1, pt);
   
   pt.set(0.0f, 0.0f, -2.0f/(farPlane - nearPlane), 0.0f);
   mProjectionMatrix.setColumn(2, pt);
   
   pt.set(tx, ty, tz, 1.0f);
   mProjectionMatrix.setColumn(3, pt);
   
   // Translate projection matrix.
   static MatrixF translate(true);
   pt.set(0.0f, -mClip.point.y, 0.0f, 1.0f);
   translate.setColumn(3, pt);
   
   mProjectionMatrix *= translate;
   
   setMatrix(GFXMatrixProjection, mProjectionMatrix);
   
   MatrixF mTempMatrix(true);
   setViewMatrix( mTempMatrix );
   setWorldMatrix( mTempMatrix );

   // Set the viewport to the clip rect
   RectI viewport(mClip.point.x, mClip.point.y, mClip.extent.x, mClip.extent.y);
   setViewport(viewport);
}
Esempio n. 10
0
/**
 * Draws the graph on the canvas using the graphviz engine.
 * A new canvas is created, so all items need to be regenerated.
 * TODO: Can we use the same canvas and only reposition existing items?
 */
void GraphWidget::draw()
{
	QWMatrix mtx;
	char szTempFile[TMP_TMPL_SIZE];
	int nFd;
	FILE* pFile;
	
	// Do nothing if drawing process has already started
	if (m_dot.isRunning())
		return;
	
	// Apply the zoom factor
	mtx.scale(m_dZoom, m_dZoom);
	setWorldMatrix(mtx);

	// Do not draw until the Dot process finishes
	setUpdatesEnabled(false);

	// Open a temporary file
	strcpy(szTempFile, TMP_TMPL);
	nFd = mkstemp(szTempFile);
	if ((pFile = fdopen(nFd, "w")) == NULL)
		return;
	
	// Remember the file name (so it can be deleted later)
	m_sDrawFilePath = szTempFile;
	
	// Write the graph contents to the temporary file
	{
		QTextStream str(pFile, IO_WriteOnly);
		write(str, "graph", "--", false);
	}
	
	// Close the file
	fclose(pFile);
	
	// Draw the graph
	if (m_dot.run(szTempFile)) {
		// Create the progress dialogue
		m_pProgressDlg = new ProgressDlg(i18n("KScope"), 
			i18n("Generating graph, please wait"), this);
		m_pProgressDlg->setMinimumDuration(1000);
		m_pProgressDlg->setValue(0);
		
		// TODO:
		// Implement cancel (what do we do when the drawing process is 
		// terminated, even though the nodes and edges were already added by
		// Cscope?)
		// m_pProgressDlg->setAllowCancel(true);
	}
}
Esempio n. 11
0
/**
 * Changes the zoom factor.
 * @param	bIn	true to zoom in, false to zoom out
 */
void GraphWidget::zoom(bool bIn)
{
	QWMatrix mtx;
	
	// Set the new zoom factor
	if (bIn)
		m_dZoom *= 2.0;
	else
		m_dZoom /= 2.0;
		
	// Apply the transformation matrix
	mtx.scale(m_dZoom, m_dZoom);
	setWorldMatrix(mtx);
}
Esempio n. 12
0
bool KGrCanvas::changeSize (int d)
{
#ifdef QT3
    if ((d < 0) && (scaleStep <= STEP)) {
	// Note: Smaller scales lose detail (e.g. the joints in brickwork).
	KGrMessage::information (this, i18n("Change Size"),
	i18n("Sorry, you cannot make the play area any smaller."));
	return FALSE;
    }

    if ((d >= 0) && (scaleStep >= 2 * STEP)) {
	// Note: Larger scales go off the edge of the monitor.
	KGrMessage::information (this, i18n("Change Size"),
	i18n("Sorry, you cannot make the play area any larger."));
	return FALSE;
    }

    QWMatrix wm = worldMatrix();
    double   wmScale = 1.0;

    // Set the scale back to 1:1 and calculate the new scale factor.
    wm.reset();
    scaleStep = (d < 0) ? (scaleStep - 1) : (scaleStep + 1);

    // If scale > 1:1, scale up to the new factor (e.g. 1.25:1, 1.5:1, etc.)
    if (scaleStep > STEP) {
	wmScale = (wmScale * scaleStep) / STEP;
	wm.scale (wmScale, wmScale);
    }
    setWorldMatrix (wm);

    // Force the title size and position to be re-calculated.
    QString t = title->text();
    makeTitle ();
    setTitle (t);

    // Fit the QCanvasView and its frame to the canvas.
    int frame = frameWidth()*2;
    setFixedSize ((FIELDWIDTH  + 4) * 4 * scaleStep + frame,
		  (FIELDHEIGHT + 4) * 4 * scaleStep + frame);
    return TRUE;

#else
    KGrMessage::information (this, i18n( "Change Size" ),
    i18n( "Sorry, you cannot change the size of the playing area. "
    "That function requires Qt Library version 3 or later." ));
    return FALSE;
#endif
}
Esempio n. 13
0
void RS_PainterQt::drawTextV(int x1, int y1,
                             int x2, int y2,
                             const QString& text) {
    save();
    QMatrix wm = worldMatrix();
    wm.rotate(-90.0);
    setWorldMatrix(wm);
    //rotate(-90.0);

    drawText(x1, y1, x2, y2,
             Qt::AlignRight|Qt::AlignVCenter,
             text);

    restore();
}
void GFXD3D9Device::setClipRect( const RectI &inRect ) 
{
	// We transform the incoming rect by the view 
   // matrix first, so that it can be used to pan
   // and scale the clip rect.
   //
   // This is currently used to take tiled screenshots.
	Point3F pos( inRect.point.x, inRect.point.y, 0.0f );
   Point3F extent( inRect.extent.x, inRect.extent.y, 0.0f );
   getViewMatrix().mulP( pos );
   getViewMatrix().mulV( extent );  
   RectI rect( pos.x, pos.y, extent.x, extent.y );

   // Clip the rect against the renderable size.
   Point2I size = mCurrentRT->getSize();

   RectI maxRect(Point2I(0,0), size);
   rect.intersect(maxRect);

   mClipRect = rect;

   F32 l = F32( mClipRect.point.x );
   F32 r = F32( mClipRect.point.x + mClipRect.extent.x );
   F32 b = F32( mClipRect.point.y + mClipRect.extent.y );
   F32 t = F32( mClipRect.point.y );

   // Set up projection matrix, 
   static Point4F pt;   
   pt.set(2.0f / (r - l), 0.0f, 0.0f, 0.0f);
   mTempMatrix.setColumn(0, pt);

   pt.set(0.0f, 2.0f/(t - b), 0.0f, 0.0f);
   mTempMatrix.setColumn(1, pt);

   pt.set(0.0f, 0.0f, 1.0f, 0.0f);
   mTempMatrix.setColumn(2, pt);

   pt.set((l+r)/(l-r), (t+b)/(b-t), 1.0f, 1.0f);
   mTempMatrix.setColumn(3, pt);

   setProjectionMatrix( mTempMatrix );

   // Set up world/view matrix
   mTempMatrix.identity();   
   setWorldMatrix( mTempMatrix );

   setViewport( mClipRect );
}
Esempio n. 15
0
void DigitView::slotZoomChange(const QString &zoom)
{
  QString stripped(zoom);

  if (stripped.right(1) == QString("%"))
    stripped.remove(stripped.length() - 1, 1);

  m_zoom = stripped.toInt();

  double scale = (double) m_zoom / 100.0;
  QMatrix ms;
  ms.scale(scale, scale);
  setWorldMatrix(ms);

  updateContents();
}
Esempio n. 16
0
void RenderTargetD3D9::setRenderState( const RenderState & rs)
{
    //矩阵状态
    setWorldMatrix( rs.m_mtxWorld);
    setViewMatrix(rs.m_mtxView);
    setProjectionMatrix( rs.m_mtxProjection);

    //背面拣选
    setCullingMode(rs.m_cullingMode);

    //光照参数
    setLightingEnabled(rs.m_bLightingEnabled);

    //深度检测
    setDepthBufferCheckEnabled(rs.m_bDepthCheckEnabled);
    setDepthBufferFunction(rs.m_DepthBufferFunction);
    setDepthBufferWriteEnabled(rs.m_bDepthWriteEnabled);
}
Esempio n. 17
0
std::shared_ptr<Volume> IvfVolumeReader::readData(std::string filePath) {
    if (!filesystem::fileExists(filePath)) {
        std::string newPath = filesystem::addBasePath(filePath);

        if (filesystem::fileExists(newPath)) {
            filePath = newPath;
        } else {
            throw DataReaderException("Error could not find input file: " + filePath, IvwContext);
        }
    }

    std::string fileDirectory = filesystem::getFileDirectory(filePath);
    auto volume = std::make_shared<Volume>();
    Deserializer d(InviwoApplication::getPtr(), filePath);
    d.deserialize("RawFile", rawFile_);
    rawFile_ = fileDirectory + "/" + rawFile_;
    std::string formatFlag("");
    d.deserialize("Format", formatFlag);
    format_ = DataFormatBase::get(formatFlag);
    mat4 basisAndOffset;
    d.deserialize("BasisAndOffset", basisAndOffset);
    volume->setModelMatrix(basisAndOffset);
    mat4 worldTransform;
    d.deserialize("WorldTransform", worldTransform);
    volume->setWorldMatrix(worldTransform);
    d.deserialize("Dimension", dimensions_);
    volume->setDimensions(dimensions_);

    d.deserialize("DataRange", volume->dataMap_.dataRange);
    d.deserialize("ValueRange", volume->dataMap_.valueRange);
    d.deserialize("Unit", volume->dataMap_.valueUnit);

    volume->getMetaDataMap()->deserialize(d);
    littleEndian_ = volume->getMetaData<BoolMetaData>("LittleEndian", littleEndian_);
    auto vd = std::make_shared<VolumeDisk>(filePath, dimensions_, format_);

    auto loader = util::make_unique<RawVolumeRAMLoader>(rawFile_, filePos_, dimensions_,
                                                        littleEndian_, format_);
    vd->setLoader(loader.release());

    volume->addRepresentation(vd);
    return volume;
}
Esempio n. 18
0
void SchemaEditor::zoom(float factor)
{
  _zoom+=factor;
  if (_zoom < 0.2f)
    _zoom = 0.2f;

  int oldcenterx = visibleWidth()/2;
  int oldcentery = visibleHeight()/2;
  int x, y;
  viewportToContents(oldcenterx, oldcentery, x, y);
  inverseWorldMatrix().map(x, y, &x, &y);
	
  QMatrix wm;
  wm.scale(_zoom, _zoom);
  setWorldMatrix(wm);

  
  //worldMatrix().map(x, y, &x, &y);
  //setContentsPos(x-oldcenterx, y-oldcentery);

}
Esempio n. 19
0
VOID render(){
	g_pDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
		D3DCOLOR_XRGB(192, 192, 192), 1.0f, 0);

	if(SUCCEEDED(g_pDevice->BeginScene())){

		setWorldMatrix();

		for(DWORD i=0; i<g_dwNumMaterials; ++i){

			g_pDevice->SetMaterial(&g_pMeshMaterials[i]);
			g_pDevice->SetTexture(0, g_pMeshTextures[i]);

			g_pMesh->DrawSubset(i);

		}

		g_pDevice->EndScene();
	}
	g_pDevice->Present(NULL, NULL, NULL, NULL);
}
Esempio n. 20
0
/**
 * Draws image.
 */
void RS_PainterQt::drawImg(RS_Img& img, const RS_Vector& pos,
                           double angle, const RS_Vector& factor,
                           int sx, int sy, int sw, int sh) {
    save();

    QMatrix wm;
    wm.translate(pos.x, pos.y);
    wm.scale(factor.x, factor.y);
    wm.rotate(RS_Math::rad2deg(-angle));
    setWorldMatrix(wm);


    if (fabs(angle)<1.0e-4) {
        drawImage(0+sx,-img.height()+sy, img, sx, sy, sw, sh);
    }
    else {
        drawImage(0,-img.height(), img);
    }

    restore();
}
Esempio n. 21
0
void GFXD3D9Device::setClipRect( const RectI &inRect ) 
{
   // Clip the rect against the renderable size.
   Point2I size = mCurrentRT->getSize();

   RectI maxRect(Point2I(0,0), size);
   RectI rect = inRect;
   rect.intersect(maxRect);

   mClipRect = rect;

   F32 l = F32( mClipRect.point.x );
   F32 r = F32( mClipRect.point.x + mClipRect.extent.x );
   F32 b = F32( mClipRect.point.y + mClipRect.extent.y );
   F32 t = F32( mClipRect.point.y );

   // Set up projection matrix, 
   static Point4F pt;   
   pt.set(2.0f / (r - l), 0.0f, 0.0f, 0.0f);
   mTempMatrix.setColumn(0, pt);

   pt.set(0.0f, 2.0f/(t - b), 0.0f, 0.0f);
   mTempMatrix.setColumn(1, pt);

   pt.set(0.0f, 0.0f, 1.0f, 0.0f);
   mTempMatrix.setColumn(2, pt);

   pt.set((l+r)/(l-r), (t+b)/(b-t), 1.0f, 1.0f);
   mTempMatrix.setColumn(3, pt);

   setProjectionMatrix( mTempMatrix );

   // Set up world/view matrix
   mTempMatrix.identity();
   setViewMatrix( mTempMatrix );
   setWorldMatrix( mTempMatrix );

   setViewport( mClipRect );
}
Esempio n. 22
0
/**
 * Draws image.
 */
void RS_PainterQt::drawImg(QImage& img, const RS_Vector& pos,
                           double angle, const RS_Vector& factor) {
    save();

    // Render smooth only at close zooms
    if (factor.x < 1 || factor.y < 1) {
       RS_PainterQt::setRenderHint(SmoothPixmapTransform , true);
    }
    else {
      RS_PainterQt::setRenderHint(SmoothPixmapTransform);
    }

    QMatrix wm;
    wm.translate(pos.x, pos.y);
    wm.rotate(RS_Math::rad2deg(-angle));
    wm.scale(factor.x, factor.y);
    setWorldMatrix(wm);


    drawImage(0,-img.height(), img);

    restore();
}
Esempio n. 23
0
void CNavigationDiagramView::ScaleDown(){
	QWMatrix matrix = worldMatrix();
	matrix.scale(0.75, 0.75);
	setWorldMatrix(matrix);
}
Esempio n. 24
0
gxScene::gxScene( gxGraphics *g,gxCanvas *t ):
graphics(g),target(t),dir3dDev( g->dir3dDev ),
n_texs(0),tris_drawn(0){

	memset( d3d_rs,0x55,sizeof(d3d_rs) );
	memset( d3d_tss,0x55,sizeof(d3d_tss) );

	//nomalize normals
	setRS( D3DRENDERSTATE_NORMALIZENORMALS,TRUE );

	//vertex coloring
	setRS( D3DRENDERSTATE_COLORVERTEX,FALSE );
	setRS( D3DRENDERSTATE_DIFFUSEMATERIALSOURCE,D3DMCS_COLOR1 );
	setRS( D3DRENDERSTATE_AMBIENTMATERIALSOURCE,D3DMCS_COLOR1 );
	setRS( D3DRENDERSTATE_EMISSIVEMATERIALSOURCE,D3DMCS_MATERIAL );
	setRS( D3DRENDERSTATE_SPECULARMATERIALSOURCE,D3DMCS_MATERIAL );

	//Alpha test
	setRS( D3DRENDERSTATE_ALPHATESTENABLE,false );
	setRS( D3DRENDERSTATE_ALPHAFUNC,D3DCMP_GREATER );
	setRS( D3DRENDERSTATE_ALPHAREF,128 );

	//source/dest blending modes
	setRS( D3DRENDERSTATE_SRCBLEND,D3DBLEND_SRCALPHA );
	setRS( D3DRENDERSTATE_DESTBLEND,D3DBLEND_INVSRCALPHA );

	//suss out caps
	can_wb=false;
	hw_tex_stages=1;
	D3DDEVICEDESC7 devDesc={0};
	if( dir3dDev->GetCaps( &devDesc )>=0 ){
		DWORD caps=devDesc.dpcTriCaps.dwRasterCaps;
		//texture stages
		hw_tex_stages=devDesc.wMaxSimultaneousTextures;
		//depth buffer mode
		if( (caps & D3DPRASTERCAPS_WBUFFER) && graphics->zbuffFmt.dwRGBBitCount==16 ) can_wb=true;
		//fog mode
		if( (caps&D3DPRASTERCAPS_FOGTABLE)&&(caps&D3DPRASTERCAPS_WFOG) ){
			setRS( D3DRENDERSTATE_FOGVERTEXMODE,D3DFOG_NONE );
			setRS( D3DRENDERSTATE_FOGTABLEMODE,D3DFOG_LINEAR );
		}else{
			setRS( D3DRENDERSTATE_FOGTABLEMODE,D3DFOG_NONE );
			setRS( D3DRENDERSTATE_FOGVERTEXMODE,D3DFOG_LINEAR );
		}
	}
	tex_stages=hw_tex_stages;

	caps_level=100;
	if( devDesc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_CUBEMAP ){
		caps_level=110;
	}

	//default texture states
	for( int n=0;n<hw_tex_stages;++n ){
		setTSS( n,D3DTSS_COLORARG1,D3DTA_TEXTURE );
		setTSS( n,D3DTSS_COLORARG2,D3DTA_CURRENT );
		setTSS( n,D3DTSS_ALPHAARG1,D3DTA_TEXTURE );
		setTSS( n,D3DTSS_ALPHAARG2,D3DTA_CURRENT );
		setTSS( n,D3DTSS_MINFILTER,D3DTFN_LINEAR );
		setTSS( n,D3DTSS_MAGFILTER,D3DTFG_LINEAR );
		setTSS( n,D3DTSS_MIPFILTER,D3DTFP_LINEAR );
	}
	setHWMultiTex( true );

	//ATI lighting hack
	dir3dDev->LightEnable( 0,true );
	dir3dDev->LightEnable( 0,false );

	//globals
	sphere_mat._11=.5f;sphere_mat._22=-.5f;sphere_mat._33=.5f;
	sphere_mat._41=.5f;sphere_mat._42=.5f;sphere_mat._43=.5f;
	nullmatrix._11=nullmatrix._22=nullmatrix._33=nullmatrix._44=1;

	//set null renderstate
	memset(&material,0,sizeof(material));
	shininess=0;blend=BLEND_REPLACE;fx=0;
	for( int k=0;k<MAX_TEXTURES;++k ) memset( &texstate[k],0,sizeof(texstate[k]) );

	wbuffer=can_wb;
	dither=false;setDither( true );
	antialias=true;setAntialias( false );
	wireframe=true;setWireframe( false );
	flipped=true;setFlippedTris( false );
	ambient=~0;setAmbient( GRAY );
	ambient2=~0;setAmbient2( BLACK );
	fogcolor=~0;setFogColor( BLACK );
	fogrange_nr=fogrange_fr=0;setFogRange( 1,1000 );
	fogmode=FOG_LINEAR;setFogMode( FOG_NONE );
	zmode=-1;setZMode( ZMODE_NORMAL );
	memset(&projmatrix,0,sizeof(projmatrix));
	ortho_proj=true;frustum_nr=frustum_fr=frustum_w=frustum_h=0;setPerspProj( 1,1000,1,1 );
	memset(&viewport,0,sizeof(viewport));viewport.dvMaxZ=1;setViewport( 0,0,target->getWidth(),target->getHeight() );
	viewmatrix=nullmatrix;setViewMatrix( 0 );
	worldmatrix=nullmatrix;setWorldMatrix( 0 );

	//set default renderstate
	blend=fx=~0;shininess=1;
	RenderState state;memset(&state,0,sizeof(state));
	state.color[0]=state.color[1]=state.color[2]=state.alpha=1;
	state.blend=BLEND_REPLACE;
	setRenderState( state );
}
Esempio n. 25
0
void CNavigationDiagramView::ScaleUp(){
	QWMatrix matrix = worldMatrix();
	matrix.scale((4.0/3.0), (4.0/3.0));
	setWorldMatrix(matrix);
}
Esempio n. 26
0
std::shared_ptr<Volume> curlVolume(std::shared_ptr<const Volume> volume) {
    auto newVolume = std::make_shared<Volume>(volume->getDimensions(), DataVec3Float32::get());
    newVolume->setModelMatrix(volume->getModelMatrix());
    newVolume->setWorldMatrix(volume->getWorldMatrix());

    newVolume->dataMap_ = volume->dataMap_;

    auto m = newVolume->getCoordinateTransformer().getDataToWorldMatrix();

    auto a = m * vec4(0, 0, 0, 1);
    auto b = m * vec4(1.0f / vec3(volume->getDimensions() - size3_t(1)), 1);
    auto spacing = b - a;

    vec3 ox = vec3(spacing.x, 0, 0);
    vec3 oy = vec3(0, spacing.y, 0);
    vec3 oz = vec3(0, 0, spacing.z);

    VolumeDoubleSampler<4> sampler(volume);
    auto worldSpace = VolumeDoubleSampler<3>::Space::World;

    util::IndexMapper3D index(volume->getDimensions());
    auto data = static_cast<vec3*>(newVolume->getEditableRepresentation<VolumeRAM>()->getData());

            float minV = std::numeric_limits<float>::max(), maxV = std::numeric_limits<float>::lowest();

    std::function<void(const size3_t&)> func = [&](const size3_t& pos) {
        vec3 world = (m * vec4(vec3(pos) / vec3(volume->getDimensions() - size3_t(1)), 1)).xyz();

        auto Fx =
            (sampler.sample(world + ox, worldSpace) - sampler.sample(world - ox, worldSpace)) /
            (2.0 * spacing.x);
        auto Fy =
            (sampler.sample(world + oy, worldSpace) - sampler.sample(world - oy, worldSpace)) /
            (2.0 * spacing.y);
        auto Fz =
            (sampler.sample(world + oz, worldSpace) - sampler.sample(world - oz, worldSpace)) /
            (2.0 * spacing.z);

        vec3 c;
        c.x = static_cast<float>(Fy.z - Fz.y);
        c.y = static_cast<float>(Fz.x - Fx.z);
        c.z = static_cast<float>(Fx.y - Fy.x);

                minV = std::min(minV, c.x);
                minV = std::min(minV, c.y);
                minV = std::min(minV, c.z);
                maxV = std::max(maxV, c.x);
                maxV = std::max(maxV, c.y);
                maxV = std::max(maxV, c.z);

        data[index(pos)] = c;
    };

    util::forEachVoxel(*volume->getRepresentation<VolumeRAM>(), func);

            auto range = std::max(std::abs(minV), std::abs(maxV));
            newVolume->dataMap_.dataRange = dvec2(-range, range);
            newVolume->dataMap_.valueRange = dvec2(minV, maxV);


    return newVolume;
}