void Pipeline::CameraKeyboard(unsigned int key, int x, int y) { // z if (key == 122) { SetCameraPosition(Vector3f(vPosition.x, vPosition.y, vPosition.z+1)); } // x else if (key == 120) { SetCameraPosition(Vector3f(vPosition.x, vPosition.y, vPosition.z-1)); } }
void Viewport :: Update (GameData& data) { PlayerDatabase* playerdb = data.GetPlayerDatabase(); if (playerdb != NULL) { UUID CurrentPLayerID = playerdb->GetCurrentPlayerID(); Player* player = playerdb->GetPlayer (CurrentPLayerID); Vector v = player->GetViewFocus (); v.z += NormalZDepth; SetCameraPosition(v); } float ViewAngle = 0.11f;// simply for setting the proper frustum glFrustum (-ViewAngle, ViewAngle, -ViewAngle, ViewAngle, 0.1, 9000); // I can't express how important setting the Frustrum before rotating and translating is. // We will end up with very strange clipping in 3-space if we don't keep these // ordered thusly. Vector LookAt = -CameraAngle; glRotated (LookAt.pitch, 1.0, 0, 0); glRotated (LookAt.yaw, 0, 1.0, 0); glRotated (LookAt.roll, 0, 0, 1.0); glTranslated (-Position.x, -Position.y, -Position.z); }
int main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [models] example - drawing billboards"); // Define the camera to look into our 3d world Camera camera = {{ 5.0, 4.0, 5.0 }, { 0.0, 2.0, 0.0 }, { 0.0, 1.0, 0.0 }}; Texture2D bill = LoadTexture("resources/billboard.png"); // Our texture billboard Vector3 billPosition = { 0.0, 2.0, 0.0 }; // Position where draw billboard SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode SetCameraPosition(camera.position); // Set internal camera position to match our camera position SetCameraTarget(camera.target); // Set internal camera target to match our camera target SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- UpdateCamera(&camera); // Update internal camera and our camera //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); Begin3dMode(camera); DrawBillboard(camera, bill, billPosition, 2.0f, WHITE); DrawGrid(10.0, 1.0); // Draw a grid End3dMode(); DrawFPS(10, 10); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- UnloadTexture(bill); // Unload texture CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; }
void Pane2D::FlipHorizontally() { this->CameraLeftToRightVector[0] *= -1; SetCameraPosition(); }
void Pane2D::FlipVertically() { this->CameraBottomToTopVector[1] *= -1; SetCameraPosition(); }
int main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; SetConfigFlags(FLAG_MSAA_4X_HINT); // Enable Multi Sampling Anti Aliasing 4x (if available) InitWindow(screenWidth, screenHeight, "raylib [shaders] example - postprocessing shader"); // Define the camera to look into our 3d world Camera camera = {{ 3.0, 3.0, 3.0 }, { 0.0, 1.5, 0.0 }, { 0.0, 1.0, 0.0 }}; Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture SetModelTexture(&dwarf, texture); // Bind texture to model Vector3 position = { 0.0, 0.0, 0.0 }; // Set model position Shader shader = LoadShader("resources/shaders/base.vs", "resources/shaders/bloom.fs"); // Load postpro shader SetPostproShader(shader); // Set fullscreen postprocessing shader // Setup orbital camera SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode SetCameraPosition(camera.position); // Set internal camera position to match our camera position SetCameraTarget(camera.target); // Set internal camera target to match our camera target SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- UpdateCamera(&camera); // Update internal camera and our camera //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); Begin3dMode(camera); DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture DrawGrid(10.0, 1.0); // Draw a grid End3dMode(); DrawText("(c) Dwarf 3D model by David Moreno", screenWidth - 200, screenHeight - 20, 10, BLACK); DrawFPS(10, 10); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- UnloadShader(shader); // Unload shader UnloadTexture(texture); // Unload texture UnloadModel(dwarf); // Unload model CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; }
void xForm::SetFrustum(const xFrustum& f) { SetPerspectiveByWidthZ(f.NearLeft()*2, f.NearUp()*2, f.NearDistance(), f.FarDistance()); SetCameraPosition(f.Origin(), f.Axis()); }
void xForm::SetCameraPosition(const xVec3& origin, const xAngles& angles) { SetCameraPosition(origin, angles.ToMat3()); }
void AugmentedView::Render(OpenGL * openGL) { if (!canDraw) return; OpenGLRenderData renderData = openGL->renderData; struct timespec start,end; SET_TIME(&start); SetCameraPosition(renderData); OpenGLSettings(); SelectedObject * newSelection = SelectObjects(openGL); struct timespec now; SET_TIME(&now); double timediff = calc_time_double(lastSelectionTime,now); if (unselectNext) { if (selectedObject != NULL) UpdateObjectPosition(projection,selectedObject); unselectNext = false; } //Only allowed to change selections every 1.0 seconds else if (newSelection != NULL && timediff > 800000.0) { //Unselect object if selected twice if (selectedObject != NULL && selectedObject->arObject == newSelection->arObject) { UpdateObjectPosition(projection,selectedObject); } else { delete selectedObject; selectedObject = newSelection; // //Point3f cameraPosition = getCameraPosition(projection); //Point3f cameraOffset = selectedObject->arObject->position - cameraPosition; ////Initial offset between object and camera selectedObject->objectPositionDelta = getObjectScreenCoord(selectedObject->arObject->position,projection);//scameraOffset; projection.copyTo(selectedObject->originalProjectionMat); cancelSelection->SetVisible(true); releaseSelection->SetVisible(true); //LOGD(LOGTAG_ARINPUT,"CameraPositionOffset(%f,%f,%f)",cameraOffset.x,cameraOffset.y,cameraOffset.z); } lastSelectionTime = now; }else if (newSelection != NULL) { LOGD(LOGTAG_ARINPUT,"Time spacing too short for unselect. Diff=%lf",timediff); } SET_TIME(&now); bool popVector = false; timediff = calc_time_double(cursorShowTime,now); if (timediff < 5000000.0) { objectVector.push_back(testObject); popVector = true; } LOGV(LOGTAG_OPENGL,"Drawing %d ARObjects",objectVector.size()); for (int i=0;i<objectVector.size();i++) { ARObject * object = objectVector.at(i); //LOGV(LOGTAG_OPENGL,"Drawing ARObject at (%f,%f,%f)",object->position.x,object->position.y,object->position.z); //LOGV(LOGTAG_OPENGL,"With rotation (%f,%f,%f)",object->rotation.x,object->rotation.y,object->rotation.z); Mat modelMatrix = Mat::eye(4,4,CV_32F); if (selectedObject != NULL && selectedObject->arObject == object) { //Point3f cameraPosition = getCameraPosition(projection); selectedObject->arObject->position = getObject3DCoord(selectedObject->objectPositionDelta,projection);//selectedObject->objectPositionDelta + cameraPosition; /* Point3f cameraRotation = getCameraRotation(); selectedObject->arObject->rotation = selectedObject->objectRotationDelta + cameraRotation; */ } OpenGLHelper::translate(modelMatrix,Point3f(object->position.x,object->position.y,object->position.z)); OpenGLHelper::rotate(modelMatrix,object->rotation.x, Point3f(1.0f, 0.0f, 0.0f)); OpenGLHelper::rotate(modelMatrix,object->rotation.y, Point3f(0.0f, 1.0f, 0.0f)); OpenGLHelper::rotate(modelMatrix,object->rotation.z, Point3f(0.0f, 0.0f, 1.0f)); Mat tmpModelMatrix; //Use seperate scale for selection indicator if (selectedObject != NULL && selectedObject->arObject == object) { modelMatrix.copyTo(tmpModelMatrix); } OpenGLHelper::scale(modelMatrix,object->scale); Mat mt = Mat(modelMatrix.t()); glUniformMatrix4fv(renderData.modelMatrixLocation, 1, GL_FALSE, mt.ptr<float>(0)); openGL->DrawGLObject(object->glObject); if (selectedObject != NULL && selectedObject->arObject == object) { float selectorSize = object->BoundingSphereRadius*2.25f; OpenGLHelper::scale(tmpModelMatrix,Point3f(selectorSize,selectorSize,selectorSize)); Mat mt = Mat(tmpModelMatrix.t()); glUniformMatrix4fv(renderData.modelMatrixLocation, 1, GL_FALSE, mt.ptr<float>(0)); openGL->DrawGLObject(selectionIndicator->glObject); } } //Get rid of test object if (popVector) objectVector.pop_back(); ResetGLSettings(); SET_TIME(&end); LOG_TIME("AugmentedView Render",start,end); canDraw = false; }
int main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d picking"); // Define the camera to look into our 3d world Camera camera = {{ 0.0, 10.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }}; Vector3 cubePosition = { 0.0, 1.0, 0.0 }; Ray ray; // Picking line ray SetCameraMode(CAMERA_FREE); // Set a free camera mode SetCameraPosition(camera.position); // Set internal camera position to match our camera position SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- UpdateCamera(&camera); // Update internal camera and our camera if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) { // NOTE: This function is NOT WORKING properly! ray = GetMouseRay(GetMousePosition(), camera); // TODO: Check collision between ray and box } //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); Begin3dMode(camera); DrawCube(cubePosition, 2, 2, 2, GRAY); DrawCubeWires(cubePosition, 2, 2, 2, DARKGRAY); DrawGrid(10.0, 1.0); DrawRay(ray, MAROON); End3dMode(); DrawText("Try selecting the box with mouse!", 240, 10, 20, GRAY); DrawFPS(10, 10); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; }
int main() { // Initialization //-------------------------------------------------------------------------------------- const int screenWidth = 800; const int screenHeight = 450; SetConfigFlags(FLAG_MSAA_4X_HINT); InitWindow(screenWidth, screenHeight, "raylib [shaders] example - basic lighting"); // Camera initialization Camera camera = {{ 8.0f, 8.0f, 8.0f }, { 0.0f, 3.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }}; // Model initialization Vector3 position = { 0.0f, 0.0f, 0.0f }; Model model = LoadModel("resources/model/dwarf.obj"); Shader shader = LoadShader("resources/shaders/phong.vs", "resources/shaders/phong.fs"); SetModelShader(&model, shader); // Shader locations initialization int lIntensityLoc = GetShaderLocation(shader, "light_intensity"); int lAmbientLoc = GetShaderLocation(shader, "light_ambientColor"); int lDiffuseLoc = GetShaderLocation(shader, "light_diffuseColor"); int lSpecularLoc = GetShaderLocation(shader, "light_specularColor"); int lSpecIntensityLoc = GetShaderLocation(shader, "light_specIntensity"); int mAmbientLoc = GetShaderLocation(shader, "mat_ambientColor"); int mSpecularLoc = GetShaderLocation(shader, "mat_specularColor"); int mGlossLoc = GetShaderLocation(shader, "mat_glossiness"); // Camera and light vectors shader locations int cameraLoc = GetShaderLocation(shader, "cameraPos"); int lightLoc = GetShaderLocation(shader, "lightPos"); // Model and View matrix locations (required for lighting) int modelLoc = GetShaderLocation(shader, "modelMatrix"); //int viewLoc = GetShaderLocation(shader, "viewMatrix"); // Not used // Light and material definitions Light light; Material matBlinn; // Light initialization light.position = (Vector3){ 4.0f, 2.0f, 0.0f }; light.direction = (Vector3){ 5.0f, 1.0f, 1.0f }; light.intensity = 1.0f; light.diffuse = WHITE; light.ambient = (Color){ 150, 75, 0, 255 }; light.specular = WHITE; light.specIntensity = 1.0f; // Material initialization matBlinn.colDiffuse = WHITE; matBlinn.colAmbient = (Color){ 50, 50, 50, 255 }; matBlinn.colSpecular = WHITE; matBlinn.glossiness = 50.0f; // Setup camera SetCameraMode(CAMERA_FREE); // Set camera mode SetCameraPosition(camera.position); // Set internal camera position to match our camera position SetCameraTarget(camera.target); // Set internal camera target to match our camera target SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- UpdateCamera(&camera); // Update camera position // NOTE: Model transform can be set in model.transform or directly with params at draw... WATCH OUT! SetShaderValueMatrix(shader, modelLoc, model.transform); // Send model matrix to shader //SetShaderValueMatrix(shader, viewLoc, GetCameraMatrix(camera)); // Not used // Glossiness input control if(IsKeyDown(KEY_UP)) matBlinn.glossiness += SHININESS_SPEED; else if(IsKeyDown(KEY_DOWN)) { matBlinn.glossiness -= SHININESS_SPEED; if( matBlinn.glossiness < 0) matBlinn.glossiness = 0.0f; } // Light X movement if (IsKeyDown(KEY_D)) light.position.x += LIGHT_SPEED; else if(IsKeyDown(KEY_A)) light.position.x -= LIGHT_SPEED; // Light Y movement if (IsKeyDown(KEY_LEFT_SHIFT)) light.position.y += LIGHT_SPEED; else if (IsKeyDown(KEY_LEFT_CONTROL)) light.position.y -= LIGHT_SPEED; // Light Z movement if (IsKeyDown(KEY_S)) light.position.z += LIGHT_SPEED; else if (IsKeyDown(KEY_W)) light.position.z -= LIGHT_SPEED; // Send light values to shader SetShaderValue(shader, lIntensityLoc, &light.intensity, 1); SetShaderValue(shader, lAmbientLoc, ColorToFloat(light.ambient), 3); SetShaderValue(shader, lDiffuseLoc, ColorToFloat(light.diffuse), 3); SetShaderValue(shader, lSpecularLoc, ColorToFloat(light.specular), 3); SetShaderValue(shader, lSpecIntensityLoc, &light.specIntensity, 1); // Send material values to shader SetShaderValue(shader, mAmbientLoc, ColorToFloat(matBlinn.colAmbient), 3); SetShaderValue(shader, mSpecularLoc, ColorToFloat(matBlinn.colSpecular), 3); SetShaderValue(shader, mGlossLoc, &matBlinn.glossiness, 1); // Send camera and light transform values to shader SetShaderValue(shader, cameraLoc, VectorToFloat(camera.position), 3); SetShaderValue(shader, lightLoc, VectorToFloat(light.position), 3); //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); Begin3dMode(camera); DrawModel(model, position, 4.0f, matBlinn.colDiffuse); DrawSphere(light.position, 0.5f, GOLD); DrawGrid(20, 1.0f); End3dMode(); DrawFPS(10, 10); // Draw FPS EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- UnloadShader(shader); UnloadModel(model); CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; }
int main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [models] example - cubesmap loading and drawing"); // Define the camera to look into our 3d world Camera camera = {{ 16.0, 14.0, 16.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }}; Image image = LoadImage("resources/cubicmap.png"); // Load cubicmap image (RAM) Texture2D cubicmap = LoadTextureFromImage(image); // Convert image to texture to display (VRAM) Model map = LoadCubicmap(image); // Load cubicmap model (generate model from image) // NOTE: By default each cube is mapped to one part of texture atlas Texture2D texture = LoadTexture("resources/cubicmap_atlas.png"); // Load map texture SetModelTexture(&map, texture); // Bind texture to map model Vector3 mapPosition = { -16, 0.0, -8 }; // Set model position UnloadImage(image); // Unload cubesmap image from RAM, already uploaded to VRAM SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode SetCameraPosition(camera.position); // Set internal camera position to match our custom camera position SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- UpdateCamera(&camera); // Update internal camera and our camera //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); Begin3dMode(camera); DrawModel(map, mapPosition, 1.0f, WHITE); End3dMode(); DrawTextureEx(cubicmap, (Vector2){ screenWidth - cubicmap.width*4 - 20, 20 }, 0.0f, 4.0f, WHITE); DrawRectangleLines(screenWidth - cubicmap.width*4 - 20, 20, cubicmap.width*4, cubicmap.height*4, GREEN); DrawText("cubicmap image used to", 658, 90, 10, GRAY); DrawText("generate map 3d model", 658, 104, 10, GRAY); DrawFPS(10, 10); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- UnloadTexture(cubicmap); // Unload cubicmap texture UnloadTexture(texture); // Unload map texture UnloadModel(map); // Unload map model CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; }
int main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free"); // Define the camera to look into our 3d world Camera camera = {{ 0.0, 10.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }}; Vector3 cubePosition = { 0.0, 0.0, 0.0 }; SetCameraMode(CAMERA_FREE); // Set a free camera mode SetCameraPosition(camera.position); // Set internal camera position to match our camera position SetCameraTarget(camera.target); // Set internal camera target to match our camera target SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- UpdateCamera(&camera); // Update internal camera and our camera //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(WHITE); Begin3dMode(camera); DrawCube(cubePosition, 2, 2, 2, RED); DrawCubeWires(cubePosition, 2, 2, 2, MAROON); DrawGrid(10.0, 1.0); End3dMode(); DrawText("Free camera default controls:", 20, 20, 10, GRAY); DrawText("- Mouse Wheel to Zoom in-out", 40, 50, 10, DARKGRAY); DrawText("- Mouse Wheel Pressed to Pan", 40, 70, 10, DARKGRAY); DrawText("- Alt + Mouse Wheel Pressed to Rotate", 40, 90, 10, DARKGRAY); DrawText("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 40, 110, 10, DARKGRAY); DrawText("- Z to zoom to (0, 0, 0)", 40, 130, 10, DARKGRAY); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; }