Exemplo n.º 1
0
//----------------------------------------------------------
void of3dPrimitive::enableNormals() {
    getMesh().enableNormals();
}
Exemplo n.º 2
0
//----------------------------------------------------------
void ofConePrimitive::setMode( ofPrimitiveMode mode ) {
    ofPrimitiveMode currMode = getMesh().getMode();
    if(currMode != mode)
        set( getRadius(), getHeight(), getResolution().x, getResolution().y, getResolution().z, mode );
}
Exemplo n.º 3
0
//--------------------------------------------------------------
void ofConePrimitive::setCapColor( ofColor color ) {
    if(getMesh().getMode() != OF_PRIMITIVE_TRIANGLE_STRIP) {
        ofLogWarning("ofConePrimitive") << "setCapColor(): must be in triangle strip mode";
    }
    getMesh().setColorForIndices( strides[1][0], strides[1][0]+strides[1][1], color );
}
Exemplo n.º 4
0
//----------------------------------------------------------
bool of3dPrimitive::hasNormalsEnabled() {
    return getMesh().hasNormals();
}
Exemplo n.º 5
0
//--------------------------------------------------------------
void ofConePrimitive::setResolution( int radiusRes, int heightRes, int capRes ) {
    ofPrimitiveMode mode = getMesh().getMode();
    set( getRadius(), getHeight(), radiusRes, heightRes, capRes, mode );
}
Exemplo n.º 6
0
//----------------------------------------------------------
void of3dPrimitive::enableColors() {
    getMesh().enableColors();
}
Exemplo n.º 7
0
void
ImageMesh::buildMesh3D(const std::vector<std::string> & filenames)
{
  // If the user gave us a "stack" with 0 or 1 files in it, we can't
  // really create a 3D Mesh from that
  if (filenames.size() <= 1)
    mooseError("ImageMesh error: Cannot create a 3D ImageMesh from an image stack with " << filenames.size() << " images.");

  // For each file in the stack, process it using the 'file' command.
  // We want to be sure that all the images in the stack are the same
  // size, for example...
  int
    xpixels = 0,
    ypixels = 0,
    zpixels = filenames.size();

  // Take pixel info from the first image in the stack to determine the aspect ratio
  GetPixelInfo(filenames[0], xpixels, ypixels);

  // TODO: Check that all images are the same aspect ratio and have
  // the same number of pixels?  ImageFunction does not currently do
  // this...
  // for (unsigned i=0; i<filenames.size(); ++i)
  // {
  //   // Extract the number of pixels from the image using the file command
  //   GetPixelInfo(filenames[i], xpixels, ypixels);
  //
  //   // Moose::out << "Image " << filenames[i] << " has size: " << xpixels << " by " << ypixels << std::endl;
  // }

  // Use the number of x and y pixels and the number of images to
  // determine the the x, y, and z dimensions of the mesh.  We assume
  // that there is 1 pixel in the z-direction for each image in the
  // stack.

  // Set the maximum dimension to 1.0 while scaling the other
  // directions to maintain the aspect ratio.
  Real
    xmax = xpixels,
    ymax = ypixels,
    zmax = zpixels;

  if (_scale_to_one)
  {
    Real max = std::max(std::max(xmax, ymax), zmax);
    xmax /= max;
    ymax /= max;
    zmax /= max;
  }

  // Compute the number of cells in the x and y direction based on
  // the user's cells_per_pixel parameter.  Note: we use ints here
  // because the GeneratedMesh params object uses ints for these...
  int
    nx = static_cast<int>(_cells_per_pixel * xpixels),
    ny = static_cast<int>(_cells_per_pixel * ypixels),
    nz = static_cast<int>(_cells_per_pixel * zpixels);

  // Actually build the Mesh
  MeshTools::Generation::build_cube(dynamic_cast<UnstructuredMesh&>(getMesh()),
                                    nx, ny, nz,
                                    /*xmin=*/0., /*xmax=*/xmax,
                                    /*ymin=*/0., /*ymax=*/ymax,
                                    /*zmin=*/0., /*zmax=*/zmax,
                                    HEX8);

  // We've determined the correct xmax, ymax, zmax values, so set them in
  // our InputParameters object.
  _pars.set<Real>("xmax") = xmax;
  _pars.set<Real>("ymax") = ymax;
  _pars.set<Real>("zmax") = zmax;

  // Set the number of cells in the x, y, and z directions that we determined.
  _pars.set<int>("nx") = nx;
  _pars.set<int>("ny") = ny;
  _pars.set<int>("nz") = nz;
}
Exemplo n.º 8
0
//----------------------------------------------------------
void ofSpherePrimitive::setResolution( int res ) {
    resolution             = res;
    ofPrimitiveMode mode   = getMesh().getMode();
    
    set(getRadius(), getResolution(), mode );
}
Exemplo n.º 9
0
//----------------------------------------------------------
void ofSpherePrimitive::setMode( ofPrimitiveMode mode ) {
    ofPrimitiveMode currMode = getMesh().getMode();
    if(currMode != mode)
        set(getRadius(), getResolution(), mode );
}
Exemplo n.º 10
0
//--------------------------------------------------------------
void ofPlanePrimitive::setResolution( int columns, int rows ) {
    resolution.set( columns, rows );
    ofPrimitiveMode mode = getMesh().getMode();
    
    set( getWidth(), getHeight(), getResolution().x, getResolution().y, mode );
}
Exemplo n.º 11
0
//--------------------------------------------------------------
void ofPlanePrimitive::setMode(ofPrimitiveMode mode) {
    ofPrimitiveMode currMode = getMesh().getMode();
    
    if( mode != currMode )
        set( getWidth(), getHeight(), getResolution().x, getResolution().y, mode );
}
Exemplo n.º 12
0
//----------------------------------------------------------
void of3dPrimitive::disableColors() {
    getMesh().disableColors();
}
Exemplo n.º 13
0
//----------------------------------------------------------
void of3dPrimitive::disableTextures() {
    getMesh().disableTextures();
}
Exemplo n.º 14
0
void Engine::Graphics::render(Drawable object, Camera *cam)
{
	D3DXMATRIX transMat, scaleMat, rotMat, worldMat;

	D3DXMatrixIdentity(&transMat);
	D3DXMatrixIdentity(&scaleMat);
	D3DXMatrixIdentity(&rotMat);
	D3DXMatrixIdentity(&worldMat);


	if(!object.get3D())
	{
		D3DXMatrixScaling(&scaleMat, object.getScale().x, object.getScale().y, object.getScale().z);
		D3DXMatrixTranslation(&transMat, object.getTranslate().x, object.getTranslate().y, object.getTranslate().z);
		D3DXMatrixRotationYawPitchRoll(&rotMat, D3DXToRadian(object.getRotate().y),D3DXToRadian(object.getRotate().x), D3DXToRadian(object.getRotate().z));
		D3DXMatrixMultiply(&scaleMat, &scaleMat, &rotMat);
		D3DXMatrixMultiply(&worldMat, &scaleMat, &transMat);

		Engine::DX::instance()->getSprite()->SetTransform(&worldMat);

		Engine::DX::instance()->getSprite()->Draw(
			getTexture(object.getHandle()),
			object.getIsSpriteSheet() ? &object.getRect() : 0,
			object.getIsSpriteSheet() ? &dVec3(object.getWidth() * 0.5f, object.getHeight() * 0.5f, 0.0f) : &dVec3(getInfo(object.getHandle()).Width *0.5f, getInfo(object.getHandle()).Height *0.5f, 0.0f),
			0,
			object.getColor());
	}

	if(object.get3D())
	{
		//camera.setLookAt(object.getTranslate().x, object.getTranslate().y, object.getTranslate().z);
		//camera.setProj(800,600);

		D3DXMATRIX WIT;		

		UINT numPasses = 0;
		m_Effect->Begin(&numPasses, 0);

		Mesh *tempMesh = getMesh(object.getHandle());
		 

		for(UINT i = 0; i < numPasses; i++)
		{
			m_Effect->BeginPass(i);

			D3DXMatrixScaling(&scaleMat, object.getScale().x, object.getScale().y, object.getScale().z);
			D3DXMatrixTranslation(&transMat, object.getTranslate().x, object.getTranslate().y, object.getTranslate().z);
			D3DXMatrixRotationYawPitchRoll(&rotMat, D3DXToRadian(object.getRotate().y),D3DXToRadian(object.getRotate().x), D3DXToRadian(object.getRotate().z));
			D3DXMatrixMultiply(&scaleMat, &scaleMat, &rotMat);
			D3DXMatrixMultiply(&worldMat, &scaleMat, &transMat);

			D3DXMatrixInverse(&WIT, 0, &worldMat);
			D3DXMatrixTranspose(&WIT, &WIT);
			m_Effect->SetMatrix("worldViewProjMat", &(worldMat * cam->getView() * cam->getProjection()));
			m_Effect->SetMatrix("worldInverseTransposeMat", &WIT);
			m_Effect->SetMatrix("worldMat", &worldMat);

			for(DWORD i = 0; i < tempMesh->getNumMaterials(); i++)
			{
				m_Effect->SetValue("ambientMaterial", &tempMesh->getMeshMaterial()[i].Ambient, sizeof(D3DXCOLOR));
				m_Effect->SetValue("diffuseMaterial", &tempMesh->getMeshMaterial()[i].Diffuse, sizeof(D3DXCOLOR));
				m_Effect->SetValue("specularMaterial", &tempMesh->getMeshMaterial()[i].Specular, sizeof(D3DXCOLOR));
				m_Effect->SetFloat("specularPower", tempMesh->getMeshMaterial()[i].Power);
				
				if(object.getHasTexture())
				{
					m_Effect->SetTexture("tex", tempMesh->getMeshTexture()[i]);
					m_Effect->SetBool("isTex", true);
				}else
					m_Effect->SetBool("isTex", false);

				m_Effect->CommitChanges();
				tempMesh->getMesh()->DrawSubset(i);
			}

			m_Effect->EndPass();

			//tempMesh = nullptr;
		}
		m_Effect->End();
	}
}
Exemplo n.º 15
0
//--------------------------------------------------------------
vector<ofIndexType> ofConePrimitive::getCapIndices() {
    if(getMesh().getMode() != OF_PRIMITIVE_TRIANGLE_STRIP) {
        ofLogWarning("ofConePrimitive") << "getCapIndices(): must be in triangle strip mode";
    }
    return of3dPrimitive::getIndices( strides[1][0], strides[1][0] + strides[1][1] );
}
Exemplo n.º 16
0
//--------------------------------------------------------------
void ofCylinderPrimitive::setResolution( int radiusSegments, int heightSegments, int capSegments ) {
    ofPrimitiveMode mode = getMesh().getMode();
    set( getRadius(), getHeight(), radiusSegments, heightSegments, capSegments, getCapped(), mode );
}
Exemplo n.º 17
0
//----------------------------------------------------------
void of3dPrimitive::enableTextures() {
    getMesh().enableTextures();
}
Exemplo n.º 18
0
//----------------------------------------------------------
vector<ofIndexType> of3dPrimitive::getIndices( int startIndex, int endIndex ) {
    vector<ofIndexType> indices;
    indices.assign( getMesh().getIndices().begin()+startIndex, getMesh().getIndices().begin()+endIndex );
    return indices;
}
Exemplo n.º 19
0
//----------------------------------------------------------
void of3dPrimitive::disableNormals() {
    getMesh().disableNormals();
}
Exemplo n.º 20
0
	//----------
	void Device::drawWorld() {
		auto colorSource = this->getColorSource();
		auto depthSource = this->getDepthSource();
		auto bodySource = this->getBodySource();

		if (!depthSource) {
			ofLogError("ofxKinectForWindows2::Device::drawPrettyMesh") << "No depth source initialised";
			return;
		}
		
		//point cloud
		{
			//setup some point cloud properties for kicks
			auto mainWindow = std::static_pointer_cast<ofAppGLFWWindow>(ofGetCurrentWindow());
			bool usePointSize = mainWindow ? mainWindow->getSettings().glVersionMajor <= 2 : false;
			if (usePointSize) {
				glPushAttrib(GL_POINT_BIT);
				glPointSize(5.0f);
				glEnable(GL_POINT_SMOOTH);
			}

			ofPushStyle();

			if (colorSource) {
				//bind kinect color camera texture and draw mesh from depth (which has texture coordinates)
				colorSource->getTexture().bind();
			}

			auto opts = Source::Depth::PointCloudOptions(true, Source::Depth::PointCloudOptions::TextureCoordinates::ColorCamera);
			auto mesh = depthSource->getMesh(opts);

			//draw point cloud
			mesh.drawVertices();

			//draw triangles
			ofSetColor(255, 150);
			mesh.drawWireframe();

			//draw fills faded
			ofSetColor(255, 50);
			mesh.drawFaces();

			if (colorSource) {
				//unbind colour camera
				colorSource->getTexture().unbind();
			}

			ofPopStyle();

			//clear the point cloud drawing attributes
			if (usePointSize) {
				glPopAttrib();
			}
		}
		
		//bodies and floor
		if (bodySource) {
			bodySource->drawWorld();

			ofPushMatrix();
			ofRotate(90, 0, 0, 1);
			ofMultMatrix(bodySource->getFloorTransform());
			ofDrawGridPlane(5.0f);
			ofPopMatrix();
		}

		//draw the view cones of depth and colour cameras
		ofPushStyle();
		ofNoFill();
		ofSetLineWidth(2.0f);
		ofSetColor(100, 200, 100);
		depthSource->drawFrustum();
		if (colorSource) {
			ofSetColor(200, 100, 100);
			colorSource->drawFrustum();
		}
		ofPopStyle();
	}