int main() { srand(time(NULL)); aspect::GLWindow window(XRES, YRES); glfwMakeContextCurrent(window.get_window()); glfwSetKeyCallback(window.get_window(), key_callback); glfwSetInputMode(window.get_window(), GLFW_CURSOR, GLFW_CURSOR_DISABLED); glfwSetCursorPos(window.get_window(), XRES/2, YRES/2); gs.camera.set_position(glm::vec3(+0.0f, +10.0f, +0.0f)); double currentframe = glfwGetTime(); double lastframe = currentframe; aspect::GLProgram monkey_program("shaders/vshader-nm.glsl", "shaders/fshader-nm.glsl"); aspect::Mesh monkey_mesh("models/monkey.dae"); aspect::ModelAsset monkey_asset(&monkey_mesh, &monkey_program); aspect::ModelInstance monkey(&monkey_asset); monkey.offset_position(glm::vec3(40, 6, 60)); monkey.update(); gs.model_instances.push_back(&monkey); aspect::GLProgram chunk_program("shaders/vshader-tex-light.glsl", "shaders/fshader-tex-light.glsl"); for(int x = 0; x < 16; x++) { for(int y = 0; y < 1; y++) { for(int z = 0; z < 16; z++) { aspect::CubeChunk *chunk = new aspect::CubeChunk(&chunk_program, x*CCOUNTX, y*CCOUNTY, z*CCOUNTZ); chunk->update(); gs.cube_chunks.push_back(chunk); } } } glClearColor(0.20, 0.6, 0.7, 0.00); while(!glfwWindowShouldClose(window.get_window())) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); for_each(begin(gs.model_instances), end(gs.model_instances), [](aspect::ModelInstance *instance) { instance->draw(gs.camera.matrix()); walk(instance); }); for_each(begin(gs.cube_chunks), end(gs.cube_chunks), [](aspect::CubeChunk *chunk) { chunk->draw(gs.camera.matrix()); }); handle_mouse(window.get_window()); update_fps_counter(window.get_window()); window.update_fps_counter(); glfwSwapBuffers(window.get_window()); glfwPollEvents(); currentframe = glfwGetTime(); gs.delta_time = currentframe - lastframe; lastframe = currentframe; } return 0; }
// main関数 int main(void) { enum animal selected; do { switch (selected = select()) { case Dog : dog(); break; case Cat : cat(); break; case Monkey : monkey(); break; } } while (selected != Invalid); return (0); }
void RunAITest(void) { AI::Brain::Ptr brain(new AI::Brain); // 1. Note that parts are implicitly created. // 2. Set up actions. // Set up Move action. // Post conditions are NOT required, because they are only used to // add influence to an action based on the possibility that they will lead to a goal. // TODO: Passing the brain to the action suggests the brain should // control creating the action... Monkey_Action move("Move", brain); // For an action to be available, the current actor state must have the same values for the parts listed. move.pre("ToBox", "MonkeyAndBox", "Away"); // Pre-Condition -> Part, Value move.post("ToBox", "MonkeyAndBox", "NextTo"); // Post-Condition -> Part, Value move.pre("FromBox", "MonkeyAndBox", "NextTo"); move.post("FromBox", "MonkeyAndBox", "Away"); // Set up Push action Monkey_Action pushBox("PushBox", brain); pushBox.pre("UnderBannanas", "MonkeyAndBox", "NextTo"); // Pre-Condition -> Part, Value pushBox.pre("UnderBannanas", "BoxUnderBannanas", "F"); // -> Part, Value pushBox.post("UnderBannanas", "BoxUnderBannanas", "T"); pushBox.pre("NotUnder", "MonkeyAndBox", "NextTo"); pushBox.pre("NotUnder", "BoxUnderBannanas", "T"); pushBox.post("NotUnder", "BoxUnderBannanas", "F"); // Set up Climb action Monkey_Action climbBox( "ClimbBox", brain ); climbBox.pre("Up", "MonkeyAndBox", "NextTo"); climbBox.post("Up", "MonkeyAndBox", "OnBox"); climbBox.pre("Down", "MonkeyAndBox", "OnBox" ); climbBox.post("Down", "MonkeyAndBox", "NextTo" ); // Set up Take action Monkey_Action takeBannanas( "TakeBannanas", brain ); takeBannanas.pre("Yum", "MonkeyAndBox", "OnBox" ); takeBannanas.pre("Yum", "BoxUnderBannanas","T"); takeBannanas.post("Yum", "HasBannanas", "T"); // 3. Setup an actor. AI::Actor monkey(brain); // Give the actor actions it can perform. monkey.addAction( &move ); monkey.addAction( &pushBox ); monkey.addAction( &climbBox ); monkey.addAction( &takeBannanas ); const int ITERATIONS = 1; float avg = 0.0f; for ( int i = 0; i < ITERATIONS; ++i ) { // Set the actor's current state part values. monkey.currentValue("BoxUnderBannanas", "F"); monkey.currentValue("HasBannanas", "F"); monkey.currentValue("MonkeyAndBox", "Away"); // Set the actor's current goal. AI::Actor::Goal getBannanas; getBannanas.influence(10.0f); getBannanas.state().setValue(brain->part("HasBannanas"), "T"); monkey.addGoal(getBannanas); int actions = 0; AI::Action::Outcome outcome = AI::Action::Impossible; do { actions ++; outcome = monkey.getAction()->perform(monkey); } while(outcome != AI::Action::Impossible && monkey.goalsSatisfied().size() == 0); assert(monkey.goalsSatisfied().size() == 1); avg += actions; } AI::Output::Out() << "Actions: " << avg / ITERATIONS << AI::Output::endl(); }
int main() { LabMonkey monkey(9600, true); monkey.run(); return 0; }
static void on_eom(uint64_t id) { monkey(id); }
static void on_data(uint64_t id) { monkey(id); }
static void on_rcpt(uint64_t id, struct mailaddr *rcpt) { monkey(id); }
static int on_helo(uint64_t id, const char *helo) { return monkey(id); }
static void on_helo(uint64_t id, const char *helo) { monkey(id); }
static void on_connect(uint64_t id, struct filter_connect *conn) { monkey(id); }
int main(int argc, char ** argv[]) { Display display(800, 600, "TSBK07 Level of Detail on Terrain"); Basic_Shader base_shader("./shaders/space"); Phong_Shader phong("./shaders/phong"); Texture texture("./textures/dirt.tga"); Camera camera(glm::vec3(0, 1, 0), 70.0f, display.GetAspectRation(), 0.01f, 1000.0f); Terrain terr("./textures/terrain2.jpg", "./textures/terrain2.jpg"); Skybox sky; sky.SkyboxInit("./textures/skybox/", "back.jpg", "front.jpg", "left.jpg", "right.jpg", "top.jpg", "bottom.jpg"); Transform transform; Keyboard keyboard; Mouse mouse; float counter = 0.0f; Mesh monkey("./models/monkey3.obj"); Mesh box("./models/box.obj"); std::cout << "init complete" << std::endl; bool wireframe = true; bool lock = false; while (!display.IsClosed()) { display.Clear(1, 0, 1, 1); SDL_Event e; while (SDL_PollEvent(&e)) { if (e.type == SDL_QUIT) { display.HandleEvent(e); } if (e.type == SDL_MOUSEMOTION || e.type == SDL_MOUSEBUTTONDOWN || e.type == SDL_MOUSEBUTTONUP) { mouse.HandleEvent(e, camera); } } const Uint8* currentKeyStates = SDL_GetKeyboardState(NULL); keyboard.HandleEvent(currentKeyStates, camera); sky.Draw(transform, camera); if (currentKeyStates[SDL_SCANCODE_B]) { lock = !lock; } if (currentKeyStates[SDL_SCANCODE_F]) { wireframe = !wireframe; } terr.Draw(transform, camera, lock, wireframe); display.Update(); counter += 0.001f; } return 0; }
static int on_eom(uint64_t id, size_t size) { return monkey(id); }
static int on_data(uint64_t id) { return monkey(id); }
static int on_rcpt(uint64_t id, struct mailaddr *rcpt) { return monkey(id); }
static int on_mail(uint64_t id, struct mailaddr *mail) { return monkey(id); }
static void on_mail(uint64_t id, struct mailaddr *mail) { monkey(id); }
void ShadowMapping::initialize(){ std::shared_ptr<gland::BaseController> cameraController(new gland::CameraController(camera_, window_)); std::shared_ptr<gland::BaseController> smController(new gland::SMController(params_, window_)); controllers_.push_back(cameraController); controllers_.push_back(smController); glfwSetKeyCallback(window_, &gland::Controller<gland::SMController>::keyCallback); params_["offsetFactor"] = gland::Param("Polygon offset factor"); params_["offsetFactor"] = 4.0f; params_["offsetUnits"] = gland::Param("Polygon offset units"); params_["offsetUnits"] = 4.0f; params_["renderDepth"] = gland::Param("Render depth"); params_["renderDepth"] = false; params_["manualLight"] = gland::Param("Manual light"); params_["manualLight"] = false; params_["angle"] = 0.0f; params_["lightSpeed"] = gland::Param("Light Rotation Speed"); params_["lightSpeed"] = 1.0f; params_["lightRadius"] = gland::Param("Light circ. radius"); params_["lightRadius"] = 10.0f; cameraController->generateHelpText(help_); smController->generateHelpText(help_); gland::ShaderDough shaderDough; shaderDough.addShaderFromFile("../src/shaders/shadowmapping_vs.glsl", GL_VERTEX_SHADER); shaderDough.addShaderFromFile("../src/shaders/shadowmapping_fs.glsl", GL_FRAGMENT_SHADER); gland::ShaderManager shaderManager; nViewProgram_ = shaderManager.cookDough(shaderDough); shaderPrograms_.push_back(nViewProgram_); //Light program gland::ShaderDough lightDough; lightDough.addShaderFromFile("../src/shaders/shadowmappinglight_vs.glsl", GL_VERTEX_SHADER); lightDough.addShaderFromFile("../src/shaders/shadowmappinglight_fs.glsl", GL_FRAGMENT_SHADER); nLightProgram_ = shaderManager.cookDough(lightDough); shaderPrograms_.push_back(nLightProgram_); //Depth program gland::ShaderDough depthDough; depthDough.addShaderFromFile("../src/shaders/shadowmappingdepth_vs.glsl", GL_VERTEX_SHADER); depthDough.addShaderFromFile("../src/shaders/shadowmappingdepth_fs.glsl", GL_FRAGMENT_SHADER); nDepthProgram_ = shaderManager.cookDough(depthDough); shaderPrograms_.push_back(nDepthProgram_); //Light source program gland::ShaderDough lightSourceDough; lightSourceDough.addShaderFromFile("../src/shaders/lightsource_vs.glsl", GL_VERTEX_SHADER); lightSourceDough.addShaderFromFile("../src/shaders/lightsource_fs.glsl", GL_FRAGMENT_SHADER); nLightSourceProgram_ = shaderManager.cookDough(lightSourceDough); shaderPrograms_.push_back(nLightSourceProgram_); //Frame buffer for depth glGenFramebuffers(1, &nDepthFbo_); glBindFramebuffer(GL_FRAMEBUFFER, nDepthFbo_); glGenTextures(1, &nDepthTex_); glBindTexture(GL_TEXTURE_2D, nDepthTex_); glTexStorage2D(GL_TEXTURE_2D, 11, GL_DEPTH_COMPONENT32F, DEPTH_TEXTURE_SIZE, DEPTH_TEXTURE_SIZE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, nDepthTex_, 0); glGenTextures(1, &nDepthDebug_); glBindTexture(GL_TEXTURE_2D, nDepthDebug_); glTexStorage2D(GL_TEXTURE_2D, 1, GL_R32F, DEPTH_TEXTURE_SIZE, DEPTH_TEXTURE_SIZE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, nDepthDebug_, 0); glBindTexture(GL_TEXTURE_2D, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0); //VAO for drawing depth texture glGenVertexArrays(1, &nQuadVao_); glBindVertexArray(nQuadVao_); glEnable(GL_DEPTH_TEST); //Add object std::string inputfile = "../res/sphere.obj"; std::vector<tinyobj::shape_t> shapes; std::string err = tinyobj::LoadObj(shapes, inputfile.c_str()); std::shared_ptr<gland::Body> obj(new gland::Body(shapes[0])); obj->setShader(nViewProgram_); obj->translate(3.0f, 0.0f, -3.0f); standardObjects_.push_back(obj); //Add another sphere std::shared_ptr<gland::Body> sphere2(new gland::Body(shapes[0])); sphere2->setShader(nViewProgram_); sphere2->translate(-10.0f, -0.0f, -2.0f); standardObjects_.push_back(sphere2); inputfile = "../res/thickblock.obj"; err = tinyobj::LoadObj(shapes, inputfile.c_str()); std::shared_ptr<gland::Body> floor(new gland::Body(shapes[0])); floor->setShader(nViewProgram_); floor->rotate(0.0f, 1.0f, 0.0f, 0.0f); floor->translate(0.0f, 0.0f, -5.0f); standardObjects_.push_back(floor); inputfile = "../res/monkey.obj"; err = tinyobj::LoadObj(shapes, inputfile.c_str()); std::shared_ptr<gland::Body> monkey(new gland::Body(shapes[0])); monkey->setShader(nViewProgram_); monkey->translate(-2.0f, -0.0f, 0.0f); standardObjects_.push_back(monkey); inputfile = "../res/light.obj"; err = tinyobj::LoadObj(shapes, inputfile.c_str()); std::shared_ptr<gland::Body> lightSource(new gland::Body(shapes[0])); lightSource->setShader(nLightSourceProgram_); lightSources_.push_back(lightSource); glEnable (GL_CULL_FACE); // cull face glCullFace (GL_BACK); // cull back face //glFrontFace (GL_CW); // GL_CCW for counter clock-wise //Look at center camera_->lookAt(glm::vec3(0.0f, 0.0f, 20.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f)); }
static int on_connect(uint64_t id, struct filter_connect *conn) { return monkey(id); }