Graphics::Graphics(const RECT& rect) : stage(rect) {
	linePainter = new LinePainter(rect);

	AssertEx(rect.bottom - rect.top == rect.right - rect.left, "only square stage is supported");

	camera = new Camera(moveSpeed, rotateSpeed, rect.bottom - rect.top);

	LightAttribute lightAttr;
	lightAttr.diffuse = Color(255, 255, 255);
	lightAttr.direction = Vector3::right;
	lightAttr.lightOn = true;
	lightAttr.lightType = LightTypeDirection;
	lightAttr.position.Set(200, 0, 0);
	camera->AddLight(Light(lightAttr));

	lightAttr.ambient = Color(90, 90, 90);
	lightAttr.lightType = LightTypeAmbient;
	lightAttr.lightOn = true;
	camera->AddLight(Light(lightAttr));

	zBuffer = new ZBuffer(stage.right - stage.left, stage.bottom - stage.top);

	VertexContainer vertices;
	IndexedTriangleContainer triangles;
	CreatePlane(vertices, triangles, Texture("bmp/metal.bmp"), 2, 3);
	street = new Object();
	//street->Initialize(vertices, triangles, 5.f, 12.f, Vector3(), Vector3());
	AddObject(street);

	xmin = stage.left + 1;
	xmax = stage.right - 2;
	ymin = stage.top + 1;
	ymax = stage.bottom - 2;
}
Example #2
0
//-------------------------------------------------------------------------------
// @ Player::Player()
//-------------------------------------------------------------------------------
// Constructor
//-------------------------------------------------------------------------------
Player::Player()
{
    mRotate.Identity();
    mScale = 1.0f;
    mTranslate.Zero();

    mPlaneIndices = nullptr;

    mPlaneVerts = nullptr;

    mColorTexture = nullptr;
    mNormalTexture = nullptr;

    // Load the color and normal textures
    IvImage* image = IvImage::CreateFromFile("brickwork-texture.tga");
    if (image)
    {
        mColorTexture = IvRenderer::mRenderer->GetResourceManager()->CreateTexture(
            (image->GetBytesPerPixel() == 4) ? kRGBA32TexFmt : kRGB24TexFmt,
            image->GetWidth(), image->GetHeight(), image->GetPixels(), kImmutableUsage);

        delete image;
        image = 0;
    }
    mColorTexture->SetMagFiltering(kBilerpTexMagFilter);
    mColorTexture->SetMinFiltering(kBilerpTexMinFilter);
    mColorTexture->SetAddressingU(kWrapTexAddr);
    mColorTexture->SetAddressingV(kWrapTexAddr);

    image = IvImage::CreateFromFile("brickwork_normal-map.tga");
    if (image)
    {
        mNormalTexture = IvRenderer::mRenderer->GetResourceManager()->CreateTexture(
            (image->GetBytesPerPixel() == 4) ? kRGBA32TexFmt : kRGB24TexFmt,
            image->GetWidth(), image->GetHeight(), image->GetPixels(), kImmutableUsage);

        delete image;
        image = 0;
    }
    mNormalTexture->SetMagFiltering(kBilerpTexMagFilter);
    mNormalTexture->SetMinFiltering(kBilerpTexMinFilter);
    mNormalTexture->SetAddressingU(kWrapTexAddr);
    mNormalTexture->SetAddressingV(kWrapTexAddr);

    mShader = IvRenderer::mRenderer->GetResourceManager()->CreateShaderProgram(
        IvRenderer::mRenderer->GetResourceManager()->CreateVertexShaderFromFile(
        "normalShader"),
        IvRenderer::mRenderer->GetResourceManager()->CreateFragmentShaderFromFile(
        "normalShader"));

    mShader->GetUniform("NormalTexture")->SetValue(mNormalTexture);
    mShader->GetUniform("ColorTexture")->SetValue(mColorTexture);

    mLightPos = IvVector3(-0.8f, 0.8f, 0.8f);
    mLightPos.Normalize();

    IvRenderer::mRenderer->SetShaderProgram(mShader);

    CreatePlane();
}   // End of Player::Player()
Example #3
0
void BaseMesh::CreateViewPlane(float EyeDist, UINT slices, MatrixController &MC)
{
    Matrix4 Perspective = MC.Perspective, PInverse;

    PInverse = Perspective.Inverse();

    Vec3f PerspectiveCoord(0.0f, 0.0f, EyeDist);
    PerspectiveCoord = Perspective.TransformPoint(PerspectiveCoord);    //get the top-left coord in persp. space

    PerspectiveCoord.x = 1.0f;
    PerspectiveCoord.y = -1.0f;
    PerspectiveCoord = PInverse.TransformPoint(PerspectiveCoord);        //get the bottom-right coord in persp. space

    CreatePlane(2.0f, slices, slices);    //create the X-Y plane

    Matrix4 Scale = Matrix4::Scaling(Vec3f(PerspectiveCoord.x, PerspectiveCoord.y, 1.0f));    //scale it appropriately,
    Matrix4 Translate = Matrix4::Translation(Vec3f(0.0f,0.0f,PerspectiveCoord.z));            //translate it away from the eye,

    Matrix4 VInverse = MC.View.Inverse();    //we need to transform our mesh and we want to fact the view and world transforms in
    Matrix4 WInverse = MC.World.Inverse();

    //
    // Translate and scale, then go into object space by multiplying through the inverse of view/world.
    //
    ApplyMatrix(Translate * Scale * VInverse * WInverse);
}
Example #4
0
cBackWall::cBackWall()
{
	m_pVB=NULL; 
	m_pIB=NULL;
	m_pTexture=NULL;
	CreatePlane();
	GetPlane()->Make(D3DXVECTOR3(0.0f,0.0f,-1.0f),250);
}
CWaterEntity::CWaterEntity(float32 waterHeight, CTexture* normaTexture, const vec2f& dimension)
: m_fWaterHeight(waterHeight), m_pOffscreenRT(NULL), m_iScreenHeight(480), m_iScreenWidth(320), m_pNormalTexture(normaTexture)
{
    m_pOffscreenRT = new COffscreenRenderTarget();
    m_pOffscreenRT->Initialize(kCONTEXT_COLOR | kCONTEXT_DEPTH,  256);
    m_mMirror.identity();
    m_mMirror[5] = -1.f;
    m_mTransformationMatrix = mat4f::createTranslation(0, 0, waterHeight);
    CreatePlane(dimension);
}
//----------------------------------------------------------------------------
bool WaterDropFormation::OnInitialize ()
{
    if ( !Application::OnInitialize() )
        return false;

    // create scene
    m_spkScene = new Node;
    m_spkTrnNode = new Node(3);
    m_spkScene->AttachChild(m_spkTrnNode);
    CreatePlane();
    CreateWall();
    CreateWaterRoot();

    // wireframe
    m_spkWireframe = new WireframeState;
    m_spkScene->SetRenderState(m_spkWireframe);

    // depth buffer
    ZBufferState* pkZBuffer = new ZBufferState;
    pkZBuffer->Enabled() = true;
    pkZBuffer->Writeable() = true;
    pkZBuffer->Compare() = ZBufferState::CF_LEQUAL;
    m_spkScene->SetRenderState(pkZBuffer);

    Configuration0();

    // center-and-fit for camera viewing
    m_spkScene->UpdateGS(0.0f);
    Bound kWBound = m_spkScene->WorldBound();
    m_spkTrnNode->Translate() = -kWBound.Center();
    ms_spkCamera->SetFrustum(0.1f,1000.0f,-0.055f,0.055f,0.04125f,-0.04125f);
    float fAngle = 0.01f*Mathf::PI;
    float fCos = Mathf::Cos(fAngle), fSin = Mathf::Sin(fAngle);
    Vector3f kCUp(fSin,0.0f,-fCos);
    Vector3f kCDir(-fCos,0.0f,-fSin);
    Vector3f kCLeft(0.0f,1.0f,0.0f);
    Vector3f kCLoc = -0.9f*kWBound.Radius()*kCDir;
    ms_spkCamera->SetFrame(kCLoc,kCLeft,kCUp,kCDir);

    // initial update of objects
    ms_spkCamera->Update();
    m_spkScene->UpdateGS(0.0f);
    m_spkScene->UpdateRS();

    m_spkMotionObject = m_spkScene;
    m_bTurretActive = true;
    SetTurretAxes();
    m_fTrnSpeed = 0.01f;
    m_fRotSpeed = 0.001f;

    m_fLastSeconds = GetTimeInSeconds();

    return true;
}
//----------------------------------------------------------------------------
void PolyhedronDistance::CreateScene ()
{
    // ** layout of scene graph **
    // scene
    //     tetra[4]
    //     plane
    //     line[2]

    // Create the objects.
    mScene = new0 Node();
    mWireState = new0 WireState();
    mRenderer->SetOverrideWireState(mWireState);

    TriMesh* plane = CreatePlane();
    int i;
    for (i = 0; i < 2; ++i)
    {
        // Build the display tetrahedra.
        float size = 0.3f + 0.2f*(i + 1);
        if (i == 0)
        {
            mEdgeLength = size;
        }
        mTetras[i] = CreateTetra(size, false);
        mSegments[i] = CreateSegment();

        // Build the point tetrahedra.
        mSmall = 0.02f;
        mTetras[i + 2] = CreateTetra(mSmall, true);
    }

    // Tetrahedra faces.
    mFaces = new1<Tuple<3,int> >(4);
    mFaces[0][0] = 1;  mFaces[0][1] = 2;  mFaces[0][2] = 0;
    mFaces[1][0] = 0;  mFaces[1][1] = 3;  mFaces[1][2] = 2;
    mFaces[2][0] = 0;  mFaces[2][1] = 1;  mFaces[2][2] = 3;
    mFaces[3][0] = 1;  mFaces[3][1] = 2;  mFaces[3][2] = 3;

    // Transform the tetrahedra.
    mTetras[0]->LocalTransform.SetRotate(HMatrix(AVector::UNIT_Z, 1.1f));
    mTetras[0]->LocalTransform.SetTranslate(APoint(-0.25f, 0.1f, 0.3f));
    mTetras[1]->LocalTransform.SetRotate(HMatrix(AVector::UNIT_Z, 0.3f));
    mTetras[1]->LocalTransform.SetTranslate(APoint(0.25f, 0.4f, 0.5f));

    // Set parent-child links.
    mScene->AttachChild(plane);
    for (i = 0; i < 2; ++i)
    {
        mScene->AttachChild(mTetras[i]);
        mScene->AttachChild(mSegments[i]);
        mScene->AttachChild(mTetras[i + 2]);
    }
}
Example #8
0
void Lighting::buildScene()
{
	// the root of our scenegraph.
	m_rootGroup = new osg::Group;

	// Load the cow model.
	m_rootGroup->addChild( LoadModel().get() );

	m_rootGroup->addChild( CreatePlane().get() );

	m_rootGroup->addChild( CreateLight().get() );
}
Example #9
0
static void CreateFrustrum(EERIE_FRUSTRUM & frustrum, const Vec3f & pos,
                           const EERIEPOLY & ep, bool cull) {
	if(cull) {
		CreatePlane(frustrum, 0, pos, ep.v[0].p, ep.v[1].p);
		CreatePlane(frustrum, 1, pos, ep.v[3].p, ep.v[2].p);
		CreatePlane(frustrum, 2, pos, ep.v[1].p, ep.v[3].p);
		CreatePlane(frustrum, 3, pos, ep.v[2].p, ep.v[0].p);
	} else {
		CreatePlane(frustrum, 0, pos, ep.v[1].p, ep.v[0].p);
		CreatePlane(frustrum, 1, pos, ep.v[2].p, ep.v[3].p);
		CreatePlane(frustrum, 2, pos, ep.v[3].p, ep.v[1].p);
		CreatePlane(frustrum, 3, pos, ep.v[0].p, ep.v[2].p);
	}
}
//----------------------------------------------------------------------------
void WaterDropFormation::CreateScene ()
{
	mScene = new0 Node();
	mTrnNode = new0 Node();
	mScene->AttachChild(mTrnNode);
	mWireState = new0 WireState();
	mRenderer->SetOverrideWireState(mWireState);

	CreatePlane();
	CreateWall();
	CreateWaterRoot();

	Configuration0();
}
Example #11
0
static unsigned int
AddPlane(GArray * planes, const position * a, const position * b, const position * c)
{
    unsigned int index;
    plane p;
    CreatePlane(&p, a, b, c);

    for (index = 0; index < planes->len; index++) {
        if (!memcmp(&p, &g_array_index(planes, plane, index), sizeof(plane)))
            return index;
    }

    g_array_append_val(planes, p);
    return planes->len - 1;
}
Example #12
0
bool Scene::Startup()
{
	MobileCamera* camera = new MobileCamera(100.0f, 0.1f);
	camera->SetInputWindow(window);
	camera->SetupPerspective(glm::pi<float>() * 0.25f, 16.0f / 9.0f, 0.1f, 10000.0f);
	camera->LookAt(glm::vec3(100, 100, 100), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0));
	m_camera = camera;

	//SHADERS
	//procedural gen
	terrainShader = ShaderHandler::Get()->LoadShader((string)"TerrainShader", "Data/shaders/proceduralGen.vert", "Data/shaders/proceduralGen.frag");
	planeShader = ShaderHandler::Get()->LoadShader((string) "PlaneShader", "Data/shaders/bluePlane.vert", "Data/shaders/bluePlane.frag");
	//particles

	//objects


	//AntBar init
	/*TwInit(TW_OPENGL_CORE, nullptr);
	TwWindowSize(1280, 720);
	glfwSetMouseButtonCallback(window, OnMouseButton);
	glfwSetCursorPosCallback(window, OnMousePosition);
	glfwSetScrollCallback(window, OnMouseScroll);
	glfwSetKeyCallback(window, OnKey);
	glfwSetCharCallback(window, OnChar);
	glfwSetWindowSizeCallback(window, OnWindowResize);*/

	tweakBar = TwNewBar("World_Editor");
	TwAddVarRW(tweakBar, "Terrain Amplitude", TW_TYPE_FLOAT, &editAmplitude, "");
	TwAddVarRW(tweakBar, "Terrain Persistance", TW_TYPE_FLOAT, &editScale, "");

	//variable init
	barChanged = false;
	editAmplitude = 3.0f;
	editScale = 8;
	perlinSeed = 10;

	GenerateTerrain(64, editScale, editAmplitude);
	CreatePlane(64);

	return true;
}
Example #13
0
void BaseMesh::CreatePlane(const Vec3f &_start, const Vec3f &_end, UINT slicesX, UINT slicesY)
{
    Vec3f start = _start, end = _end;
    CreatePlane(1.0f, slicesX, slicesY);

    if(start.x > end.x)
    {
        Utility::Swap(start.x, end.x);
    }
    if(start.y > end.y)
    {
        Utility::Swap(start.y, end.y);
    }
    
    Matrix4 T1 = Matrix4::Translation(Vec3f(0.5f,0.5f,0.0f));
    Matrix4 Scale = Matrix4::Scaling(Vec3f((end.x-start.x),(end.y-start.y),1.0f));
    Matrix4 T2 = Matrix4::Translation(start);

    ApplyMatrix(T1 * Scale * T2);
}
void mitk::PlanesPerpendicularToLinesFilter::GenerateData()
{
  mitk::Mesh::ConstPointer input  = this->GetInput();
  mitk::GeometryData::Pointer output = this->GetOutput();

  if(m_Plane.IsNotNull())
  {
    targetRight   = m_Plane->GetMatrixColumn(0);
    targetSpacing = m_Plane->GetSpacing();
    bounds = m_Plane->GetBoundingBox()->GetBounds();
    halfWidthInMM  = m_Plane->GetExtentInMM(0)*0.5;
    halfHeightInMM = m_Plane->GetExtentInMM(1)*0.5;
  }
  else
  {
    FillVector3D(targetRight, 1.0, 0.0, 0.0);
    targetSpacing.Fill(1.0);
    halfWidthInMM=halfHeightInMM=100.0;
    ScalarType stdBounds[6] = {0.0, 2.0*halfWidthInMM, 0.0, 2.0*halfHeightInMM, 0.0, 0.0};
    bounds = stdBounds;
  }

  if(m_UseAllPoints==false)
  {
    int i, size;
    //iterate through all cells and build planes
    Mesh::ConstCellIterator cellIt, cellEnd;
    cellEnd = input->GetMesh()->GetCells()->End();
    for( cellIt = input->GetMesh()->GetCells()->Begin(); cellIt != cellEnd; ++cellIt )
    {
      Mesh::CellType& cell = *cellIt->Value();

      Mesh::PointIdIterator ptIt, ptEnd;
      ptEnd = cell.PointIdsEnd();

      size=cell.GetNumberOfPoints();
      if(size<=1)
        continue;

      ptIt = cell.PointIdsBegin();
      last = input->GetPoint(*ptIt);
      ++ptIt;
      for(i=1;i<size;++i, ++ptIt)
      {
        CreatePlane(input->GetPoint(*ptIt));
      }
    }
  }
  else //m_UseAllPoints==true
  {
    //iterate through all points and build planes
    mitk::PointSet::PointsConstIterator it, pend = input->GetPointSet()->GetPoints()->End();
    it=input->GetPointSet()->GetPoints()->Begin();
    last = it.Value();
    ++it;
    for(;it!=pend;++it)
    {
        CreatePlane(it.Value());
    }
  }

  if(planes.size()>0)
  {
    //initialize sliced-geometry for the number of created planes
    m_CreatedGeometries->InitializeSlicedGeometry(planes.size()+1);

    //set last plane at last point with same normal as the one before the last
    PlaneGeometry::Pointer plane = static_cast<PlaneGeometry*>((*planes.rbegin())->Clone().GetPointer());
    itk2vtk(last.GetVnlVector()-right*halfWidthInMM-down*halfHeightInMM, origin);
    plane->SetOrigin(origin);
    m_CreatedGeometries->SetGeometry2D(plane, planes.size());

    //add all planes to sliced-geometry
    int s;
    for(s=0; planes.empty()==false; planes.pop_front(), ++s)
    {
      m_CreatedGeometries->SetGeometry2D(planes.front(), s);
    }

    m_CreatedGeometries->SetEvenlySpaced(false);

    if(m_FrameGeometry.IsNotNull())
    {
      m_CreatedGeometries->SetIndexToWorldTransform(m_FrameGeometry->GetIndexToWorldTransform());
      m_CreatedGeometries->SetBounds(m_FrameGeometry->GetBounds());
      m_CreatedGeometries->SetReferenceGeometry(m_FrameGeometry);
    }
  }

  output->SetGeometry(m_CreatedGeometries);
}
Example #15
0
void Setup(CPlatform * const  pPlatform)
{
	//for the shapes
	unsigned int nTorusFloats;
	float *pTorusVertices = 0;
	float *pPlaneVertices = 0;	
	float colour[] = {1.0f,0.0f,0.0f, 0.0f,1.0f,0.0f, 0.0f,0.0f,1.0f};
	unsigned int torusSegments = 36, torusTubeSegments = 36;

	//for the shaders
	const char *pVertStr[3] = {0,0,0}, *pFragStr = 0;
	const char *pFragTexStr = 0, *pVertTexStr = 0;

	//fbo stuff
	WRender::Texture::SDescriptor descDepth = {WRender::Texture::TEX_2D, WRender::Texture::DEPTH_COMPONENT, TEX_DIMENSIONS, TEX_DIMENSIONS, 0, 0, WRender::Texture::DONT_GEN_MIPMAP};
	WRender::Texture::SParam param[] ={	
		{ WRender::Texture::MIN_FILTER, WRender::Texture::LINEAR},
		{ WRender::Texture::MAG_FILTER, WRender::Texture::LINEAR},
		{ WRender::Texture::WRAP_S, WRender::Texture::CLAMP_TO_EDGE},
		{ WRender::Texture::WRAP_T, WRender::Texture::CLAMP_TO_EDGE},
	};	
	
	glswInit();
	glswSetPath("../resources/", ".glsl");
	WRender::SetClearColour(0,0,0,0);	
	WRender::EnableCulling(true);
	// - - - - - - - - - - 
	//setup the shaders
	// - - - - - - - - - - 

	//normal shader
	glswGetShadersAlt("shaders.Version+shaders.Shared+shaders.SingleShadow.Vertex", pVertStr, 3);
	pFragStr = glswGetShaders("shaders.Version+shaders.SingleShadow.Fragment");
	CShader vertexShader(CShader::VERT, pVertStr, 3);
	CShader fragmentShader(CShader::FRAG, &pFragStr, 1);
	
	program.Initialise();
	program.AddShader(&vertexShader);
	program.AddShader(&fragmentShader);
	program.Link();
	uShadowMtx = program.GetUniformLocation("shadowMtx");
	program.Start();
	program.SetTextureUnit("shadowMap", 0);
	program.Stop();

	//debug shader for textures in screen space
	pVertTexStr = glswGetShaders("shaders.Version+shaders.Dbg.ScreenSpaceTexture.Vertex");
	pFragTexStr = glswGetShaders("shaders.Version+shaders.Dbg.ScreenSpaceTexture.Fragment");
	CShader vTexShader(CShader::VERT, &pVertTexStr, 1);
	CShader fTexShader(CShader::FRAG, &pFragTexStr, 1);	

	textureShader.Initialise();
	textureShader.AddShader(&vTexShader);
	textureShader.AddShader(&fTexShader);
	textureShader.Link();
	textureShader.Start();
	textureShader.SetTextureUnit("texture",0);
	textureShader.Stop();

	// - - - - - - - - - - 
	//set up shapes
	// - - - - - - - - - - 
	//shared colours
	abColour = WRender::CreateBuffer(WRender::ARRAY, WRender::STATIC, sizeof(colour), colour);

	//Torus
	nTorusVertices = 2*torusTubeSegments*torusSegments*3;
	nTorusFloats = nTorusVertices*3;
	pTorusVertices = new float[nTorusFloats];
	CreateTorus(pTorusVertices, torusSegments, 3.0f, torusTubeSegments, 1.0f);	
	vaoTorus = WRender::CreateVertexArrayObject();
	abTorus = WRender::CreateBuffer(WRender::ARRAY, WRender::STATIC, sizeof(float)*nTorusFloats, pTorusVertices);	

	WRender::BindVertexArrayObject(vaoTorus);
	WRender::VertexAttribute vaTorus[2] = {
		{abTorus, 0, 3, WRender::FLOAT, 0, sizeof(float)*3, 0, 0},
		{abColour, 1, 3, WRender::FLOAT, 0, sizeof(float)*9, sizeof(float)*6, 1},
	};
	WRender::SetAttributeFormat( vaTorus, 2, 0);
	delete[] pTorusVertices;

	//Plane
	pPlaneVertices = new float[4*3*3];
	CreatePlane(pPlaneVertices, 20.0f, 20.0f);
	vaoPlane = WRender::CreateVertexArrayObject();
	abPlane = WRender::CreateBuffer(WRender::ARRAY, WRender::STATIC, sizeof(float)*4*3*3, pPlaneVertices);	

	WRender::BindVertexArrayObject(vaoPlane);
	WRender::VertexAttribute vaFrustum[2] = {
		{abPlane, 0, 3, WRender::FLOAT, 0, sizeof(float)*3, 0, 0},
		{abColour, 1, 3, WRender::FLOAT, 0, sizeof(float)*9, sizeof(float)*3, 1},
	};
	WRender::SetAttributeFormat( vaFrustum, 2, 0);
	delete[] pPlaneVertices;

	//for screen aligned texture
	sqVao = WRender::CreateVertexArrayObject();	
	sqEab = WRender::CreateBuffer(WRender::ELEMENTS, WRender::STATIC, sizeof(sqIndices), sqIndices);
	sqAb = WRender::CreateBuffer(WRender::ARRAY, WRender::STATIC, sizeof(sqVertices), sqVertices);
	WRender::BindVertexArrayObject(sqVao);
	WRender::BindBuffer(WRender::ELEMENTS, sqEab);
	WRender::VertexAttribute sqVa[2] = {
		{sqAb, 0, 3, WRender::FLOAT, 0, sizeof(float)*5, 0, 0},				//vertices
		{sqAb, 1, 2, WRender::FLOAT, 0, sizeof(float)*5, sizeof(float)*3, 0},	//texture coordinates
	};
	WRender::SetAttributeFormat( sqVa, 2, 0);
	WRender::UnbindVertexArrayObject();

	// - - - - - - - - - - 
	//ubo for cameras etc
	// - - - - - - - - - - 
	ubo = WRender::CreateBuffer(WRender::UNIFORM, WRender::DYNAMIC, sizeof(Transforms), &transform);
	WRender::BindBufferToIndex(WRender::UNIFORM, ubo, 1);

	//create the texture and FBO for rendering to when drawing 
	//during shadow stage
	WRender::CreateBaseTexture(depthTexture, descDepth);	
	WRender::SetTextureParams(depthTexture,param,4);

	WRender::CreateFrameBuffer(fbo);
	WRender::AddTextureRenderBuffer(fbo, depthTexture, WRender::ATT_DEPTH, 0);
	WRender::BindFrameBuffer(WRender::FrameBuffer::DRAW, fbo);
	WRender::SetDrawBuffer(WRender::DB_NONE);
	WRender::CheckFrameBuffer(fbo);

	//set the projection matrix
	Transform::CreateProjectionMatrix(transforms.proj, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 50.0f);
	WRender::BindTexture(depthTexture,WRender::Texture::UNIT_0);	
}
Example #16
0
HRESULT HelloShadowVolume::RestoreDeviceObjects()
{
    HRESULT hr;
    IDirect3DDevice8* device;
    hr = m_spD3D->CreateDevice(
             D3DADAPTER_DEFAULT,
             D3DDEVTYPE_HAL,
             m_hWnd,
             D3DCREATE_HARDWARE_VERTEXPROCESSING,
             &m_dpps,
             &device);
    if (FAILED(hr))
    {
        MessageBox(0, L"CreateDevice failed", 0, 0);
        return E_FAIL;
    }
    m_spDevice.reset(device, [](IDirect3DDevice8* device) {
        device->Release();
    });

    m_spDevice->SetRenderState(D3DRS_ZENABLE, TRUE);
    m_spDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
    m_spDevice->SetRenderState(D3DRS_DITHERENABLE, TRUE);
    D3DVIEWPORT8 viewport = { 0, 0, m_iWidth, m_iHeight };
    m_spDevice->SetViewport(&viewport);

    D3DXVECTOR3 eye(0.0f, 0.0f, 30.0f);
    D3DXVECTOR3 target(0.0f, 0.0f, 0.0f);
    D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
    D3DXMatrixLookAtLH(&m_mtView, &eye, &target, &up);

    D3DXMatrixPerspectiveFovLH(&m_mtProj, 0.2*D3DX_PI, (float)m_iWidth / (float)m_iHeight, 1.0f, 100.f);

    m_cPlaneTint = { 0.7f, 0.6f, 0.4f, 1.0f };


    ID3DXMesh* plane;
    //D3DXCreatePolygon(m_spDevice.get(), 2.0f, 4, &plane, NULL);
    CreatePlane(m_spDevice.get(), 15.0f, 10, &plane);
    //D3DXCreateSphere(m_spDevice.get(), 1.0f,20,20, &plane, NULL);

    IDirect3DVertexBuffer8* vb;
    IDirect3DIndexBuffer8* ib;
    plane->GetVertexBuffer(&vb);
    plane->GetIndexBuffer(&ib);
    m_spPlaneVB.reset(vb, [](IDirect3DVertexBuffer8* vb) {
        vb->Release();
    });
    m_spPlaneIB.reset(ib, [](IDirect3DIndexBuffer8* ib) {
        ib->Release();
    });
    m_dwPlaneNumVertices = plane->GetNumVertices();
    m_dwPlaneNumFaces = plane->GetNumFaces();

    plane->Release();

    DWORD decl[] = {
        D3DVSD_STREAM(0),
        D3DVSD_REG(0, D3DVSDT_FLOAT3),
        D3DVSD_REG(3, D3DVSDT_FLOAT3),
        D3DVSD_END()
    };
    hr = CreateVSFromBinFile(m_spDevice.get(), decl, L"plane.vso", &m_dwPlaneVSH);
    if (FAILED(hr))
    {
        MessageBox(0, 0, L"CreateVSFromBinFile failed", 0);
        return E_FAIL;
    }
    hr = CreatePSFromBinFile(m_spDevice.get(), L"plane.pso", &m_dwPlanePSH);
    if (FAILED(hr))
    {
        MessageBox(0, 0, L"CreatePSFromBinFile failed", 0);
        return E_FAIL;
    }

    D3DXMATRIX Rx, Tz;
    D3DXMatrixRotationX(&Rx, D3DX_PI*0.5f);
    D3DXMatrixTranslation(&Tz, 0.0f, -3.0f, 0.0f);
    m_mtPlaneWorld = Rx * Tz;

    ID3DXMesh* occluder;
    CreateOccluder(m_spDevice.get(), &occluder);
    IDirect3DVertexBuffer8* vbOccluder;
    IDirect3DIndexBuffer8* ibOccluder;
    occluder->GetVertexBuffer(&vbOccluder);
    occluder->GetIndexBuffer(&ibOccluder);
    m_spOccluderVB.reset(vbOccluder, [](IDirect3DVertexBuffer8* vb) {
        vb->Release();
    });
    m_spOccluderIB.reset(ibOccluder, [](IDirect3DIndexBuffer8* ib) {
        ib->Release();
    });
    m_dwOccluderNumVertices = occluder->GetNumVertices();
    m_dwOccluderNumFaces = occluder->GetNumFaces();
    occluder->Release();

    hr = CreateVSFromBinFile(m_spDevice.get(), decl, L"occluder.vso", &m_dwOccluderVSH);
    if (FAILED(hr))
    {
        MessageBox(0, 0, L"CreateVSFromBinFile failed", 0);
        return E_FAIL;
    }
    hr = CreatePSFromBinFile(m_spDevice.get(), L"occluder.pso", &m_dwOccluderPSH);
    if (FAILED(hr))
    {
        MessageBox(0, 0, L"CreatePSFromBinFile failed", 0);
        return E_FAIL;
    }
    m_cOccluderTint = { 0.3f, 0.0f, 0.8f, 1.0f };
    D3DXMATRIX Rz, T;
    D3DXMatrixTranslation(&T, 5.1f * cosf(0.5), 0.0f, 5.1f * sinf(0.5));
    D3DXMatrixIdentity(&m_mtVolumeWorld);
    D3DXMatrixRotationZ(&Rz, 0.5f);
    m_mtOccluderWorld = T * Rz;

    ID3DXMesh* volume;
    CreateVolume(m_spDevice.get(), &volume);
    IDirect3DVertexBuffer8* vbVolume;
    IDirect3DIndexBuffer8* ibVolume;
    volume->GetVertexBuffer(&vbVolume);
    volume->GetIndexBuffer(&ibVolume);
    m_spVolumeVB.reset(vbVolume, [](IDirect3DVertexBuffer8* vb) {
        vb->Release();
    });
    m_spVolumeIB.reset(ibVolume, [](IDirect3DIndexBuffer8* ib) {
        ib->Release();
    });
    m_dwVolumeNumVertices = volume->GetNumVertices();
    m_dwVolumeNumFaces = volume->GetNumFaces();
    volume->Release();

    hr = CreateVSFromBinFile(m_spDevice.get(), decl, L"volume.vso", &m_dwVolumeVSH);
    if (FAILED(hr))
    {
        MessageBox(0, 0, L"CreateVSFromBinFile failed", 0);
        return E_FAIL;
    }
    hr = CreatePSFromBinFile(m_spDevice.get(), L"volume.pso", &m_dwVolumePSH);
    if (FAILED(hr))
    {
        MessageBox(0, 0, L"CreatePSFromBinFile failed", 0);
        return E_FAIL;
    }
    m_cVolumeTint = { 0.7f, 0.0f, 0.0f, 1.0f };

    D3DXMATRIX Sx;
    D3DXMatrixIdentity(&m_mtVolumeWorld);
    D3DXMatrixScaling(&Sx, 6.0f, 1.0f, 1.0f);
    D3DXMatrixRotationZ(&Rz, 0.5f);
    m_mtVolumeWorld = Sx * Rz;

    return S_OK;
}
    MeshWeakPtr	CMeshManager::CreateMesh(xst_castring& strName, const IInputLayout* pIL, BASIC_SHAPE eShape, xst_unknown pShapeOptions, xst_castring& strGroupName)
    {
        MeshWeakPtr pMesh = CreateMesh( strName, pIL, strGroupName );
        if( pMesh->m_bIsCloned )
        {
            return pMesh;
        }

        switch( eShape )
        {
            case BasicShapes::BOX:
            {
                SBoxOptions Options;
                if( pShapeOptions != xst_null ) 
                    Options = *(SBoxOptions*)pShapeOptions;
                if( XST_FAILED( CreateBox( pMesh.GetPtr(), pIL, Options ) ) )
                {
                    this->DestroyResource( pMesh );
                    pMesh = xst_null;
                }
            }
            break;

            case BasicShapes::LINE_BOX:
            {
                SLineBoxOptions Options;
                if( pShapeOptions != xst_null ) 
                    Options = *(SLineBoxOptions*)pShapeOptions;
                if( XST_FAILED( CreateBox( pMesh.GetPtr(), pIL, Options ) ) )
                {
                    this->DestroyResource( pMesh );
                    pMesh = xst_null;
                }
            }
            break;

            case BasicShapes::CIRCLE:
            {
                SCircleOptions Options;
                if( pShapeOptions != xst_null )
                    Options = *(SCircleOptions*)pShapeOptions;
                if( XST_FAILED( CreateCircle( pMesh.GetPtr(), pIL, Options ) ) )
                {
                    this->DestroyResource( pMesh );
                    pMesh = xst_null;
                }
            }
            break;

            case BasicShapes::PLANE:
            {
                SPlaneOptions Options;
                if( pShapeOptions != xst_null ) Options = *(SPlaneOptions*)pShapeOptions;
                if( XST_FAILED( CreatePlane( pMesh.GetPtr(), pIL, Options ) ) )
                {
                    this->DestroyResource( pMesh );
                    pMesh = xst_null;
                }
            }
            break;

            case BasicShapes::RECT_2D:
            {
                SRect2DOptions Options;
                if( pShapeOptions != xst_null ) Options = *(SRect2DOptions*)pShapeOptions;
                if( XST_FAILED( CreateRect2D( pMesh.GetPtr(), pIL, Options ) ) )
                {
                    this->DestroyResource( pMesh );
                    pMesh = xst_null;
                }
            }
            break;

            default:
            {
                this->DestroyResource( pMesh );
                pMesh = xst_null;
            }
            break;
        };

        return pMesh;
    }
//----------------------------------------------------------------------------
bool InverseKinematics::OnInitialize ()
{
    if ( !Application::OnInitialize() )
        return false;

    // set up camera
    ms_spkCamera->SetFrustum(1.0f,1000.0f,-0.55f,0.55f,0.4125f,-0.4125f);
    Vector3f kCamLoc(0.0f,-2.0f,0.5f);
    Matrix3f kCamOrient(-1.0f,0.0f,0.0f,0.0f,0.0f,1.0f,0.0f,1.0f,0.0f);
    ms_spkCamera->SetFrame(kCamLoc,kCamOrient);


    // ** layout of scene graph **
    // scene
    //     line
    //     iknode
    //         plane
    //         target
    //             goal
    //         root
    //             origin
    //             effector
    //                 end

    // create objects
    m_spkScene = new Node(2);
    Node* pkIKNode = new Node(3);
    m_spkRoot = new Node(2);
    m_spkEffector = new Node(1);
    m_spkTarget = new Node;
    m_spkLine = CreateLine();
    TriMesh* pkPlane = CreatePlane();
    TriMesh* pkGoal = CreateCube();
    TriMesh* pkOrigin = CreateCube();
    TriMesh* pkEnd = CreateCube();

    // transform objects
    pkIKNode->Rotate().FromAxisAngle(Vector3f::UNIT_Y,0.1f);
    pkIKNode->Translate() = Vector3f(0.1f,0.1f,0.1f);
    m_spkTarget->Translate() = 2.0f*Vector3f::UNIT_Y;
    m_spkEffector->Translate() = Vector3f::UNIT_X;

    // set parent-child links
    m_spkScene->AttachChild(m_spkLine);
    m_spkScene->AttachChild(pkIKNode);
    pkIKNode->AttachChild(pkPlane);
    pkIKNode->AttachChild(m_spkTarget);
    pkIKNode->AttachChild(m_spkRoot);
    m_spkTarget->AttachChild(pkGoal);
    m_spkRoot->AttachChild(pkOrigin);
    m_spkRoot->AttachChild(m_spkEffector);
    m_spkEffector->AttachChild(pkEnd);

    // create joints
    IKJoint** apkJoint = new IKJoint*[2];
    apkJoint[0] = new IKJoint(m_spkRoot);
    apkJoint[0]->AllowRotation(2) = true;
    apkJoint[1] = new IKJoint(m_spkEffector);
    apkJoint[1]->AllowTranslation(2) = true;

    // create goal
    IKGoal** apkGoal = new IKGoal*[1];
    apkGoal[0] = new IKGoal(m_spkTarget,m_spkEffector,1.0f);

    // create IK controller
    m_pkIKCtrl = new IKController(2,apkJoint,1,apkGoal,1);
    m_pkIKCtrl->Active() = false;
    m_spkRoot->AttachControl(m_pkIKCtrl);

    // set desired render state
    m_spkWireframeState = new WireframeState;
    m_spkScene->SetRenderState(m_spkWireframeState);
    m_spkZBufferState = new ZBufferState;
    m_spkZBufferState->Enabled() = true;
    m_spkZBufferState->Writeable() = true;
    m_spkZBufferState->Compare() = ZBufferState::CF_LEQUAL;
    m_spkScene->SetRenderState(m_spkZBufferState);

    // initial update of objects
    ms_spkCamera->Update();
    m_spkScene->UpdateGS(0.0f);
    m_spkScene->UpdateRS();
    UpdateLine();

    m_bTurretActive = true;
    SetTurretAxes();
    m_fTrnSpeed = 0.1f;
    m_fRotSpeed = 0.01f;

    return true;
}
Example #19
0
void BaseMesh::CreatePlane(const Plane &p, float length, UINT slices)
{
    CreatePlane(p, length, slices, p.Normal()*-p.d);
}
Example #20
0
void BaseMesh::CreatePlane(const Plane &P, float Length, UINT Slices, const Vec3f &Center)
{
    CreatePlane(Length, Slices, Slices);
    ApplyMatrix(Matrix4::Face(Vec3f(0.0f, 0.0f, 1.0f), P.Normal()) * Matrix4::Translation(Center));
}