void init(){ ///--- Sets background color glClearColor(/*gray*/ .937,.937,.937, /*solid*/1.0 ); triangle.init(); quad.init(); }
///Initializes the image by performing all perlin, mesh, heightmap, and other calls that generate the terrain. void init(){ glfwEnable(GLFW_KEY_REPEAT); ///--- Initializes the Perlin noise texture ///--- Initializes the fBm texture ///--- Sets background color glClearColor(/*gray*/ .8,.8,.8, /*solid*/1.0 ); glEnable(GL_DEPTH_TEST); ///--- Initlializes the terrain quad mesh (?takes the fBm as an input for displacing the height of vertices?) quad.init(perlin.init()); }
void insertPoints(const Point* points_begin, const Point* points_end) { const auto pointCount = points_end - points_begin; pointRegion.alloc(pointCount); const auto quadCount = 1 + (pointCount / Quad::MAX_LEAF_POINTS + 1) * 4; quadRegion.alloc(quadCount); quad = quadRegion.next(); quad->init(0); auto my_points = pointRegion.next(); memcpy(my_points, points_begin, pointCount * sizeof(Point)); quad->insertPoints(quadRegion, my_points, my_points + pointCount); }
void ColoredCubeApp::initApp() { D3DApp::initApp(); line1.init(md3dDevice, 10.0f, GREEN); line2.init(md3dDevice, 10.0f, BLUE); line3.init(md3dDevice, 10.0f, RED); xLine.init(&line1, Vector3(0,0,0), 5); xLine.setPosition(Vector3(0,0,0)); yLine.init(&line2, Vector3(0,0,0), 5); yLine.setPosition(Vector3(0,0,0)); yLine.setRotationZ(ToRadian(90)); zLine.init(&line3, Vector3(0,0,0), 5); zLine.setPosition(Vector3(0,0,0)); zLine.setRotationY(ToRadian(90)); quad1.init(md3dDevice, 50, CYAN); quad1.setPosition(Vector3(0,-5,0)); quad2.init(md3dDevice, 50, RED); quad2.setPosition(Vector3(0,5,0)); quad3.init(md3dDevice, 50, BEACH_SAND); quad3.setPosition(Vector3(5,5,0)); quad3.setRotXAngle(ToRadian(90)); quad3.setRotYAngle(ToRadian(90)); quad4.init(md3dDevice, 50, BEACH_SAND); quad4.setPosition(Vector3(-5,5,0)); quad4.setRotXAngle(ToRadian(90)); quad4.setRotYAngle(ToRadian(90)); quad4.init(md3dDevice, 50, BEACH_SAND); quad4.setPosition(Vector3(-5,5,0)); quad4.setRotXAngle(ToRadian(90)); quad5.init(md3dDevice, 50, DARKBROWN); quad5.setPosition(Vector3(0,0,-7)); quad5.setRotXAngle(ToRadian(90)); for(int i = 0; i < WALL_SIZE; ++i) { wall[i].init(md3dDevice, 1, GREEN); wall[i].setPosition(Vector3((rand() % MAX_RADIUS) - (MAX_RADIUS / 2), (rand() % MAX_RADIUS) - (MAX_RADIUS / 2), -6)); wall[i].setRotXAngle(ToRadian(90)); wall[i].setRotZAngle(ToRadian(45)); } buildFX(); buildVertexLayouts(); }
void CubeMapApp::initApp() { D3DApp::initApp(); fx::InitAll(md3dDevice); InputLayout::InitAll(md3dDevice); GetTextureMgr().init(md3dDevice); mTech = fx::CubeMapFX->GetTechniqueByName("CubeMapTech"); mfxLightVar = fx::CubeMapFX->GetVariableByName("gLight"); mfxEyePosVar = fx::CubeMapFX->GetVariableByName("gEyePosW"); mfxWVPVar = fx::CubeMapFX->GetVariableByName("gWVP")->AsMatrix(); mfxWorldVar = fx::CubeMapFX->GetVariableByName("gWorld")->AsMatrix(); mfxTexMtxVar = fx::CubeMapFX->GetVariableByName("gTexMtx")->AsMatrix(); mfxReflectMtrlVar = fx::CubeMapFX->GetVariableByName("gReflectMtrl")->AsVector(); mfxCubeMapEnabledVar = fx::CubeMapFX->GetVariableByName("gCubeMapEnabled")->AsScalar(); mfxDiffuseMapVar = fx::CubeMapFX->GetVariableByName("gDiffuseMap")->AsShaderResource(); mfxSpecMapVar = fx::CubeMapFX->GetVariableByName("gSpecMap")->AsShaderResource(); mfxCubeMapVar = fx::CubeMapFX->GetVariableByName("gCubeMap")->AsShaderResource(); //mClearColor = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f); GetCamera().position() = D3DXVECTOR3(0.0f, 1.8f, -10.0f); mBallMapRV = GetTextureMgr().createTex(L"blackdiffuse.dds"); //mSpecMapRV = GetTextureMgr().createTex(L"spec.dds"); mDefaultSpecMapRV = GetTextureMgr().createTex(L"defaultspec.dds"); mEnvMapRV = GetTextureMgr().createCubeTex(L"grassenvmap1024.dds"); mFloor.init(md3dDevice, 41, 21, 1.0f); mBase.init(md3dDevice, 2.0f); mBall.init(md3dDevice, 0.5f, 30, 30); mColumn.init(md3dDevice, 0.25f, 1.0f, 3.0f, 30, 30); mSky.init(md3dDevice, mEnvMapRV, 5000.0f); mParallelLight.dir = D3DXVECTOR3(0.57735f, -0.57735f, 0.57735f); mParallelLight.ambient = D3DXCOLOR(0.3f, 0.3f, 0.3f, 1.0f); mParallelLight.diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); mParallelLight.specular = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f); }
void ColoredCubeApp::initApp() { D3DApp::initApp(); buildFX(); buildVertexLayouts(); mBox.init(md3dDevice, 1.0f, D3DXCOLOR(0.5,0.5,0.5,1)); redBox.init(md3dDevice, 1.0f, DARKBROWN); greenBox.init(md3dDevice, 1.0f, D3DXCOLOR(0.1,0.1,0.8,1)); shootBox.init(md3dDevice, 1.0f, BEACH_SAND); line.init(md3dDevice, 1.0f, DARKBROWN); line2.init(md3dDevice, 1.0f, RED); line3.init(md3dDevice, 1.0f, GREEN); /*xLine.init(&line, mfxWVPVar, Vector3(0,0,0), 1); xLine.setPosition(Vector3(0,0,0)); yLine.init(&line, mfxWVPVar, Vector3(0,0,0), 1); yLine.setPosition(Vector3(0,0,0)); yLine.setRotationZ(ToRadian(90)); zLine.init(&line, mfxWVPVar, Vector3(0,0,0), 1); zLine.setPosition(Vector3(0,0,0)); zLine.setRotationY(ToRadian(90));*/ shootCube.init(&shootBox,mfxWVPVar,sqrt(2.0f),Vector3(10,0,10),Vector3(0,0,0),0,Vector3(1,1,1)); //shootCube.setRotation(Vector3(ToRadian(-20),ToRadian(45),0)); leftWall.init(&redBox,mfxWVPVar,sqrt(2.0f),Vector3(20,0,0),Vector3(0,0,0),0,Vector3(0.5,20,100)); //leftWall.setRotation(Vector3(ToRadian(-20),ToRadian(45),0)); floor.init(&redBox,mfxWVPVar,sqrt(2.0f),Vector3(0,-5,0),Vector3(0,0,0),0,Vector3(20,0.2,20)); //floor.setRotation(Vector3(ToRadian(-26),ToRadian(45),0)); ceiling.init(&mBox,mfxWVPVar,sqrt(2.0f),Vector3(0,20,0),Vector3(0,0,0),0,Vector3(20,0.2,100)); ceiling.setRotation(Vector3(ToRadian(-20),ToRadian(45),0)); rightWall.init(&redBox,mfxWVPVar,sqrt(2.0f),Vector3(-20,0,0),Vector3(0,0,0),0,Vector3(0.5,20,100)); //rightWall.setRotation(Vector3(ToRadian(-20),ToRadian(45),0)); //srand(time(0)); for(int i = 0; i < 20; i++) { tiles[i].init(&greenBox,mfxWVPVar,sqrt(2.0f),Vector3((-5+rand()%10)*3,-100,(-5+rand()%10)*3),Vector3(0,0,0),0,Vector3(1,1,1)); } origin.init(&line,&line2,&line3,mfxWVPVar,10); quad1.init(md3dDevice, 10, CYAN); quad1.setPosition(Vector3(0,0,0)); spinAmount = 0; // init sound system audio = new Audio(); if (*WAVE_BANK != '\0' && *SOUND_BANK != '\0') // if sound files defined { if( FAILED( hr = audio->initialize() ) ) { exit(1); //if( hr == HRESULT_FROM_WIN32( ERROR_FILE_NOT_FOUND ) ) // throw(GameError(gameErrorNS::FATAL_ERROR, "Failed to initialize sound system because media file not found.")); //else // throw(GameError(gameErrorNS::FATAL_ERROR, "Failed to initialize sound system.")); } } hitCubes = new CubeHoard(100,10,5,5,1,-15,15,-15,15,-100,40); hitCubes->init(&redBox,mfxWVPVar,sqrt(4.0f),Vector3(0,0,0),Vector3(0,100,0),70,Vector3(2,2,2)); avoidCubes = new CubeHoard(100,20,10,10,1,-20,20,-20,20,-100,50); avoidCubes->init(&greenBox,mfxWVPVar,sqrt(4.0f),Vector3(0,0,0),Vector3(0,100,0),70,Vector3(2,2,2)); audio->playCue(MUSIC); //input->initialize(this->getMainWnd(), false); }
void ColoredCubeApp::initApp() { D3DApp::initApp(); //input->initialize(getMainWnd(), false); //audio->initialize(); float boxScale = 0.5f; float collisionFixFactor = 1.1f; currentBullet = 0; explosionTimer = 0; explosionRunning = false; shotRelease = true; // increments when you run into a cube // just for now score = 0; mAxes.init(md3dDevice, 1.0f); mEnemy.init(md3dDevice, .5f, RED); mPlayer.init(md3dDevice, .5f, BLUE); mBullet.init(md3dDevice, .25f, D3DXCOLOR(0.0f, 1.0f, 0.0f, 0.0f)); particleBox.init(md3dDevice, .01f, GREEN); particleBox2.init(md3dDevice, .04f, RED); starBox.init(md3dDevice, 0.05f, WHITE); //mBox.init(md3dDevice, boxScale); mLine.init(md3dDevice, 1.0f); //mTriangle.init(md3dDevice, 1.0f); //mQuad.init(md3dDevice, 10.0f); mQuad.init(md3dDevice, 0.0f); gameObject1.init(&mPlayer, sqrt(2.0f), Vector3(6,.5,0), Vector3(0,0,0), 5.0f,1.0f); //gameObject1.init(&mBox, sqrt(2.0f), Vector3(6,.5,0), Vector3(0,0,0), 5000.0f,1.0f); gameObject1.setRadius(gameObject1.getRadius()*boxScale*collisionFixFactor); int step = 2; for (int i = 0; i < MAX_NUM_ENEMIES; i++) { enemyObjects[i].init(&mEnemy, sqrt(2.0), Vector3(-5,.5,step*i - 3.8), Vector3(1,0,0), 8.0f, 1); //enemyObjects[i].init(&mBox, sqrt(2.0), Vector3(-5,.5,step*i - 3.8), Vector3(1,0,0), 3000.0f, 1); enemyObjects[i].setRadius(enemyObjects[i].getRadius()*boxScale * collisionFixFactor); enemyObjects[i].setInActive(); } for (int i = 0; i < MAX_NUM_BULLETS; i++) { playerBullets[i].init(&mBullet, 0.5f, Vector3(0,0,0), Vector3(-12,0,0), 0.0f, 1); playerBullets[i].setInActive(); } for (int i = 0; i < MAX_NUM_EXP_PARTICLES; i++) { if(i%5 == 0)particles[i].init(&particleBox2, 0.5f, Vector3(0,0,0), Vector3(0,0,0), 7000.0f, 1); else particles[i].init(&particleBox, 0.5f, Vector3(0,0,0), Vector3(0,0,0), 7000.0f, 1); particles[i].setInActive(); } for (int i = 0; i < MAX_NUM_STARS; i++) { stars[i].init(&starBox, 0.5f, Vector3(0,0,0), Vector3(0,0,0), 7000.0f, 1); stars[i].setActive(); } buildFX(); buildVertexLayouts(); audio = new Audio(); if (*WAVE_BANK != '\0' && *SOUND_BANK != '\0') // if sound files defined { if (!audio->initialize()) { } /*if( FAILED( hr = audio->initialize() ) ) { if( hr == HRESULT_FROM_WIN32( ERROR_FILE_NOT_FOUND ) ) throw(GameError(gameErrorNS::FATAL_ERROR, "Failed to initialize sound system because media file not found.")); else throw(GameError(gameErrorNS::FATAL_ERROR, "Failed to initialize sound system.")); }*/ } enemyBuffer.resetClock(); shotBuffer.resetClock(); gameTimer.resetClock(); D3DXVECTOR3 pos(10.0f, 2.0f, 0.0f); D3DXVECTOR3 target(0.0f, 0.0f, 0.0f); D3DXVECTOR3 up(0.0f, 1.0f, 0.0f); //Camera Object camera.init(pos, Vector3(0,0,0), Vector3(0,0,0)); camera.setPerspective(); // camera cameraPos = pos; audio->playCue(BKG); //Places stars in scene placeStars(); }
void ColoredCubeApp::initApp() { D3DApp::initApp(); //0: Parallel //1: Point //2: Spot hurtLight = D3DXCOLOR(1,0,0,1); ambientLight = D3DXCOLOR(0.3f, 0.03f, 0.2f, 1.0f); //ambientLight = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); lights[1].ambient = ambientLight; lights[1].diffuse = D3DXCOLOR(0.0f, 0.02f, 0.02f, 1.0f); lights[1].specular = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f); lights[1].att.x = 1.0f; lights[1].att.y = 0.0f; lights[1].att.z = 0.0f; lights[1].spotPow = 20; lights[1].range = 100; lights[1].pos = D3DXVECTOR3(-10,20,-10); lights[1].dir = D3DXVECTOR3(0, -1, 0); lights[1].lightType.x = 0; buildFX(); buildVertexLayouts(); Dimension d; d.x = 10; d.z = 10; mazeX = d.x; mazeZ = d.z; maze.init(d,mfxWVPVar,mfxWorldVar,md3dDevice); maze.build(); maze.setTex(mfxDiffuseMapVar,mfxSpecMapVar,L"brickwork-texture.jpg",L"brickwork-bump-map.jpg"); maze.setCeilTex(mfxDiffuseMapVar,mfxSpecMapVar,L"13.free-brick-textures.jpg",L"brickwork-bump-map.jpg"); maze.setFloorTex(mfxDiffuseMapVar,mfxSpecMapVar,L"carpet_diffuse.jpg",L"brickwork-bump-map.jpg"); camera.init(&maze); mBox.init(md3dDevice, 1.0f); //testMesh.init(md3dDevice,1.0f,"surfrev2.dat"); line.init(md3dDevice, 1.0f, DARKBROWN); line2.init(md3dDevice, 1.0f, RED); line3.init(md3dDevice, 1.0f, GREEN); origin.init(&line,&line2,&line3,mfxWVPVar,10); quad1.init(md3dDevice,1,D3DXCOLOR(0.5,0.25,0.1,1.0)); //make the texture init in another function so it is not an issue switching between shaders /*floor.init(&mBox,mfxWVPVar,mfxWorldVar,2,Vector3(0,-3,0),Vector3(0,0,0),0,Vector3(20,0.1,20)); floor.setTex(mfxDiffuseMapVar,mfxSpecMapVar,L"WoodCrate01.dds",L"defaultspec.dds"); wall1.init(&mBox,mfxWVPVar,mfxWorldVar,2,Vector3(-20,-3+20,0),Vector3(0,0,0),0,Vector3(0.1,20,20)); wall2.init(&mBox,mfxWVPVar,mfxWorldVar,2,Vector3(20,-3+20,0),Vector3(0,0,0),0,Vector3(0.1,20,20)); wall3.init(&mBox,mfxWVPVar,mfxWorldVar,2,Vector3(0,-3+20,20),Vector3(0,0,0),0,Vector3(20,20,0.1)); wall4.init(&mBox,mfxWVPVar,mfxWorldVar,2,Vector3(0,-3+20,-20),Vector3(0,0,0),0,Vector3(20,20,0.1));*/ player.init(&mBox,mfxWVPVar,mfxWorldVar,sqrt(2.0f),Vector3(10,0,10),Vector3(0,0,0),0,Vector3(1,1,1)); player.setTex(mfxDiffuseMapVar,mfxSpecMapVar,L"brickwork-texture.jpg",L"brickwork-bump-map.jpg"); Location start = maze.getStartPosition(); start = maze.cellToPx(start); player.setPosition(Vector3(start.x+10,0,start.z+10)); flashLightObject.init(md3dDevice,mfxWVPVar,mfxWorldVar,2,Vector3(0,0,0),Vector3(0,0,0),0,Vector3(0.25,0.25,0.25)); flashLightObject.setRotation(Vector3(ToRadian(90),0,0)); //lightObject1.init(md3dDevice,mfxWVPVar,mfxWorldVar,2,Vector3(10,3,0),Vector3(0,0,0),0,Vector3(0.25,0.25,0.25)); //lightObject1.setTex(mfxDiffuseMapVar,mfxSpecMapVar,L"WoodCrate01.dds",L"ice.dds"); for(int i = 0; i < numLightObjects; i++) { lamps[i].init(md3dDevice,mfxWVPVar,mfxWorldVar,2,Vector3(10,3,0),Vector3(0,0,0),0,Vector3(0.75,0.75,0.75)); lamps[i].setTex(mfxDiffuseMapVar,mfxSpecMapVar,L"WoodCrate01.dds",L"ice.dds"); Location l; l.x = rand()%mazeX; l.z = rand()%mazeZ; auto spot = maze.cellToPx(l); lamps[i].setPosition(Vector3(spot.x,5,spot.z)); lamps[i].setColor(D3DXCOLOR(0.2f, 0.5f, 0.3f, 1.0f)); } key.init(md3dDevice,1,"item1.txt"); for(int i = 0; i < totalKeys; i++) { keyObject[i].init(&key,mfxWVPVar,mfxWorldVar,sqrt(2.0f),Vector3(0,0,0),Vector3(0,0,0),0,Vector3(0.25,0.25,0.25)); Location l; l.x = rand()%mazeX; l.z = rand()%mazeZ; auto spot = maze.cellToPx(l); keyObject[i].setPosition(Vector3(spot.x,-1,spot.z)); } endCube.init(&mBox,mfxWVPVar,mfxWorldVar,sqrt(3.0f),Vector3(0,0,0),Vector3(0,0,0),0,Vector3(2,2,2)); endCube.setTex(mfxDiffuseMapVar,mfxSpecMapVar,L"WoodCrate01.dds",L"ice.dds"); Location end = maze.getEndPosition(); end = maze.cellToPx(end); endCube.setPosition(Vector3(end.x,0,end.z)); //set up the end light endLight.ambient = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f); endLight.diffuse = D3DXCOLOR(1.0f, 1.0f, 0.3f, 1.0f); endLight.specular = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f); endLight.att.x = 1.0f; endLight.att.y = 0.0f; endLight.att.z = 0.0f; endLight.spotPow = 10; endLight.range = 100; endLight.pos = D3DXVECTOR3(end.x,10,end.z); endLight.dir = D3DXVECTOR3(0, -1, 0); endLight.lightType.x = 2; //batteryObject.init(md3dDevice,mfxWVPVar,mfxWorldVar,sqrt(2.0f),Vector3(0,0,5),Vector3(0,0,0),0,Vector3(0.25,0.25,0.25)); for(int i = 0; i < numBatteries; i++) { batteries[i].init(md3dDevice,mfxWVPVar,mfxWorldVar,sqrt(2.0f),Vector3(0,0,5),Vector3(0,0,0),0,Vector3(0.5,0.5,0.5)); Location l; l.x = rand()%mazeX; l.z = rand()%mazeZ; auto spot = maze.cellToPx(l); batteries[i].setPosition(Vector3(spot.x,-1,spot.z)); } ghosts.init(md3dDevice,mfxWVPVar,mfxWorldVar,sqrt(2.0f),Vector3(5,0,0),Vector3(0,0,0),10,Vector3(0.25,0.25,0.25)); ghosts.setTex(mfxDiffuseMapVar,mfxSpecMapVar,L"WoodCrate01.dds",L"ice.dds"); //Normalize(&mParallelLight.dir,&(flashLightObject.getPosition()-wall1.getPosition())); // init sound system audio = new Audio(); if (*WAVE_BANK != '\0' && *SOUND_BANK != '\0') // if sound files defined { if( FAILED( hr = audio->initialize() ) ) { exit(1); //if( hr == HRESULT_FROM_WIN32( ERROR_FILE_NOT_FOUND ) ) // throw(GameError(gameErrorNS::FATAL_ERROR, "Failed to initialize sound system because media file not found.")); //else // throw(GameError(gameErrorNS::FATAL_ERROR, "Failed to initialize sound system.")); } } //set up the camera camera.setHeightAndWidth(mClientWidth,mClientHeight); audio->playCue(MUSIC); //input->initialize(this->getMainWnd(), false); //sound object /*testSound = new SoundItem(audio,Vector3(0,0,0),50); static string sounds[] = {"gun_sound_effect","Light Bulb Breaking-SoundBible.com-53066515"}; testSound->setSounds(sounds,2);*/ }