Jump to content

Rimerdal

Members
  • Posts

    8
  • Joined

  • Last visited

Everything posted by Rimerdal

  1. Thanks! That pretty much explains everything about why this isn't working... now to rewrite it to not use the pivot parenting and go back to having my water look good. -David
  2. Alright, going to try and organize this in a way that makes sense. I have been using Jecklyn Heights source code as a base for a couple things, trying to get a handle on how everything works. I just tried removing the water plane from the SBX and creating the water in code to the same end. This is the main game class: #include "Game.h" #include "Configuration.h" #include "LevelManager.h" #include "CameraController.h" CGame::CGame() { } CGame::~CGame() { Shutdown(); } int CGame::Initialize() { // Configuration g_Config->LoadXMLConfigurationFile("Content/Configuration.xml"); // Application Title SetAppTitle( g_Config->GetCString("Name","Window") ); // Initialize Window. // Width, Height, Depth (Pass 32 for Fullscreen) Graphics(g_Config->GetInteger("Width","Window"), g_Config->GetInteger("Height","Window"), g_Config->GetBool("Fullscreen","Window") ? 32 : 0, g_Config->GetInteger("Hertz","Window")); // Register ../Assets/ as a media location RegisterAbstractPath(""); // Initialize Framewerk if ( !(m_Framework = CreateFramework()) ) { MessageBoxA(0,"Failed to initialize engine.","(Error)",0); return 0; } // Global Accessor for the Framework object, for Lua, and non-member use. SetGlobalObject("fw", m_Framework); //############################################################################## // Load settings from the XML file and setup anything else needed down the road //############################################################################## // Trilinear Filter TFilter( g_Config->GetBool("TrilinearFilter", "Render") ); // Anisotropic Filtering AFilter(min<int>( g_Config->GetInteger("AnisotropicFilter", "Render"),MaxAFilter()) ); // Set Antialiasing SetAntialias( g_Config->GetBool("Antialias", "Render")); // Default: Disabled // Texture Quality SetTextureQuality( g_Config->GetInteger("TextureQuality", "Render") ); // Shadow Quality SetShadowQuality( g_Config->GetInteger("ShadowQuality", "Render") ); // Full Screen Bloom/Glow // SetBloom( g_Config->GetBool("Bloom", "Render") ); // (Default: Enabled) // SSAO // SetSSAO( g_Config->GetBool("SSAO", "Render") ); // (Default: Disabled) // Water // //SetWater( g_Config->GetBool("Water", "Render") ); // (Default: Disabled) // HDRR // //SetHDR( g_Config->GetBool("HDR", "Render") ); // (Default: Enabled) // Crespecular Rays // SetGodRays( g_Config->GetBool("GodRays", "Render") ); // (Default: Disabled) // Distance Fog // SetDistanceFogRange(0,50); SetDistanceFogColor(Vec4(1,1,1,1)); SetDistanceFogAngle(0,45); SetDistanceFog( g_Config->GetBool("DistanceFog", "Render") ); // (Default: Disabled) // Depth of Field // SetFarDOF( g_Config->GetBool("DepthOfField", "Render") ); // (Default: Disabled) SetFarDOFStrength(0.5f); SetFarDOFRange(20.0f, 200.0f); // Atmospheric Effects // // Brightness // SetBrightness( g_Config->GetFloat("Brightness", "Render") ); // Contrast // SetContrast( g_Config->GetFloat("Contrast", "Render") ); // Saturation // SetSaturation( g_Config->GetFloat("Saturation", "Render") ); // Turn on occlusion culling, this could slow down performance with to many entities OcclusionCulling(true); // This should be an option later on SetWater(1); SetReflectionElements(ENTITY_MESH+ENTITY_TERRAIN); // Statistics (0 = Disabled, 1 = FPS, 2 = Detailed) // SetStats(2); // (Default: 1 [FPS]) //#################################################################### // Set Lua framework variable BP lua = GetLuaState(); lua_pushobject( lua, m_Framework ); lua_setglobal( lua, "fw" ); lua_pop( lua, 1 ); // Set up our collision Collisions(3,1,true); // Load a scene CLevelManager::GetInstance()->LoadLevel("Content/Maps/TestIsland/mypractice.sbx"); // Create a player m_Player = new CPlayerController(PLAYER_LOCAL, "node_1"); // Setup the camera CCameraController::GetInstance()->Initialize(); m_Player->SetAsFocus(); // Setup the games ambient lighting, this will need to be defined later by each level AmbientLight(Vec3(0.3f, 0.3f, 0.3f)); // Return success! return 1; } void CGame::Shutdown() { } int CGame::Run() { while( !KeyHit(KEY_ESCAPE) && !AppTerminate()) { if( !AppSuspended() ) // We are not in focus! { // Update the player m_Player->Update(AppTime()); // Update the level and the objects in the framework CLevelManager::GetInstance()->Update(); // Update the camera CCameraController::GetInstance()->Update(); // Leadwerks Render RenderFramework(); // Screenshot functionality if (KeyHit(KEY_F12)) { std::string picfile = "Screenshots/Screenshot"; std::ostringstream ts; ts << picfile << AppTime()/*pTimer->GetDays() << "." << pTimer->GetHours() << "." << pTimer->GetMinutes() << "." << pTimer->GetSeconds()*/ << ".png"; picfile = ts.str(); SaveBuffer(CurrentBuffer(), const_cast<char*>(picfile.c_str()), 100); } Flip( 0 ); } } return 0; } This is the Player Controller class: #include "PlayerController.h" #include "LevelManager.h" #include "CameraController.h" CPlayerController::CPlayerController() { // Set the type m_Type = PLAYER_LOCAL; // Create a player controller m_Player=CreateController(); EntityType(m_Player,3,1); SetBodyMass(m_Player,60); SweptCollision(m_Player,1); // Movement variables move=0.0; strafe=0.0; } CPlayerController::CPlayerController(PlayerType type, const char* spawnPoint) { // Set the type m_Type = type; // Find the spawn point TEntity spawn=FindChild(CLevelManager::GetInstance()->m_eScene, spawnPoint); // Create a player controller m_Player=CreateController(1.8f, 0.4f, 1.0f, 45, 0.9f); EntityType(m_Player,3,1); SetBodyMass(m_Player,60); SweptCollision(m_Player,1); PositionEntity(m_Player, EntityPosition(spawn)); // Create and parent the controller to the model playerMesh=LoadModel("abstract::crawler.gmf"); RotateEntity(playerMesh, Vec3(0, 180, 0)); SetBodyMass(playerMesh, 60); EntityParent(playerMesh, m_Player, 0); // Movement variables move=0.0; strafe=0.0; } CPlayerController::~CPlayerController() { } void CPlayerController::Update(flt dt) { switch(m_Type) { case PLAYER_LOCAL: { HandleInput(); break; } } // Update the player models animations float framebegin = 0.0f; float frameend = 69.0f; if(KeyDown(KEY_LSHIFT)||KeyDown(KEY_RSHIFT)) { framebegin=131.0; frameend=171.0; } else if((move || strafe) && jump == 0.0f) { framebegin = 70.0f; frameend = 130.0f; } float frame=dt/25.0f; frame=fmodf(frame,frameend-framebegin)+framebegin; Animate(playerMesh,frame,1.0,0,true); //Set controller input float camY = CCameraController::GetInstance()->GetRotation().Y; UpdateController(m_Player,camY,move,strafe,jump, 100.0f, 5); } void CPlayerController::HandleInput() { //Player movement move=((float)KeyDown(KEY_W)-KeyDown(KEY_S)) * 5.0f; strafe=((float)KeyDown(KEY_D)-KeyDown(KEY_A)) * 5.0f; //Jumping jump=0.0; if (KeyHit(KEY_SPACE)) { if (!ControllerAirborne(m_Player)) { jump=10.0; } } //Run if (KeyDown(KEY_LSHIFT)||KeyDown(KEY_RSHIFT)) { if (!ControllerAirborne(m_Player)) { move*=2.0; strafe*=2.0; } } } void CPlayerController::SetAsFocus() { // Set this player as the target focus CCameraController::GetInstance()->SetTarget(playerMesh); } ...and this is the camera: #include "CameraController.h" #include "Platform.h" #define FRAMES 15.0f bool CCameraController::Initialize() { // Default camera settings m_Target = NULL; m_fDesiredDistance = 5.0; m_nMouseZ = 0; m_nDeltaZ = 0; m_nMouseZInterp = 0; // Get the camera from the engine and set its range m_Camera = GetLayerCamera(GetFrameworkLayer(0)); CameraRange(m_Camera,0.1f,10000); // Create our camera pivots and parrents them accordingly m_tTargetPivot = CreatePivot(); m_tCameraPivot = CreatePivot(); PositionEntity(m_Camera,EntityPosition(m_tCameraPivot,GLOBAL_SPACE),GLOBAL_SPACE); EntityParent(m_tCameraPivot,m_tTargetPivot,GLOBAL_SPACE); EntityParent(m_Camera,m_tCameraPivot,GLOBAL_SPACE); // Setup the desired distances MoveEntity(m_tCameraPivot, Vec3(0.0f,3.0f,-m_fDesiredDistance),GLOBAL_SPACE); m_fDesiredDistance = EntityDistance(m_tTargetPivot,m_tCameraPivot); // Hide the mouse and center it HideMouse(); MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2); // Camera was created succesfully return true; } void CCameraController::Update() { // Handles the Z input Scroll(); // We reposition the pivot based on the target if(m_Target) { TVec3 targetPos = EntityPosition(m_Target,GLOBAL_SPACE); PositionEntity(m_tTargetPivot,Vec3(targetPos.X, targetPos.Y + 2.0f, targetPos.Z),GLOBAL_SPACE); ThirdPerson(); } } void CCameraController::ThirdPerson() { // Get the mouse input and smooth it out m_fMouseX = Curve(MouseX() - GraphicsWidth() / 2.0f, m_fMouseX, 6.0f/AppSpeed()); m_fMouseY = Curve(MouseY() - GraphicsHeight() / 2.0f, m_fMouseY, 6.0f/AppSpeed()); // Center the mouse MoveMouse((int)(GraphicsWidth() / 2.0f), (int)(GraphicsHeight() / 2.0f)); // Rotate the camera based on the input m_vCameraRotation.X = EntityRotation(m_tTargetPivot).X + m_fMouseY / 5.0f; m_vCameraRotation.Y = EntityRotation(m_tTargetPivot).Y - m_fMouseX / 5.0f; // Lock the X rotation if(m_vCameraRotation.X > 45.0f) m_vCameraRotation.X = 45.0f; if(m_vCameraRotation.X < -45.0f) m_vCameraRotation.X = -45.0f; RotateEntity(m_tTargetPivot, m_vCameraRotation, GLOBAL_SPACE); // Perform camera collision CameraCollision(); } void CCameraController::Scroll() { // Get the Z input int nMouseZ = MouseZ(); // Save the previous distance from the player float fPrevDistance = m_fDesiredDistance; // If the mouse wheel has been scrolled if (m_nMouseZ != nMouseZ) { m_nMouseZInterp += m_nMouseZ - nMouseZ; m_nMouseZ = nMouseZ; } // If we are scrolling out... if (m_nMouseZInterp > 0) { // Keep the camera from zooming to far out if ((m_fDesiredDistance + float(1.0f/FRAMES) > 8)) { m_fDesiredDistance -= float(1.0f/FRAMES); m_nDeltaZ = ZSCROLLMAX - 1; } // Move the camera m_fDesiredDistance += float(1.0f/FRAMES); m_nDeltaZ++; // Check if we are zoomed all the way out if (m_nDeltaZ == ZSCROLLMAX) { // Reset the counters m_nDeltaZ = 0; m_nMouseZInterp--; } } // If we are zooming in... else if (m_nMouseZInterp < 0) { // Keep the camera from zooming to far in if ((m_fDesiredDistance + float(1.0f/FRAMES) < 2.0f)) { m_fDesiredDistance = 2.0f; m_nDeltaZ = ZSCROLLMAX - 1; } // Move the camera m_fDesiredDistance -= float(1.0f/FRAMES); m_nDeltaZ++; // Check if we are at max zoom if (m_nDeltaZ == ZSCROLLMAX) { // Reset the counters m_nDeltaZ = 0; m_nMouseZInterp++; } } // finding how much we moved and then moving that much float fMoveDelta = fPrevDistance - m_fDesiredDistance; MoveEntity(m_tCameraPivot,Vec3(0.0f,0.0f,fMoveDelta),GLOBAL_SPACE); } void CCameraController::CameraCollision() { // TODO: Add code to this function } void CCameraController::SetTarget(TEntity Target) { m_Target = Target; if (Target == NULL) { return; } PositionEntity(m_tTargetPivot,EntityPosition(Target,GLOBAL_SPACE),GLOBAL_SPACE); RotateEntity(m_tTargetPivot,EntityRotation(Target,GLOBAL_SPACE),GLOBAL_SPACE); PointEntity(m_tCameraPivot,m_tTargetPivot,3); } Both 'Platform.h', 'Configuration.h', and 'LevelManager.h/cpp' are taken directly from Jecklyn Heights at the moment, I can post those also. I wasn't sure what you would need to look at so I posted all of the stuff I have changed or worked on. I also wasn't sure if you would need the headers, those can also be posted. Thanks, David
  3. I have been playing around with the editor and the engine trying out different things and after creating a third person camera I noticed something quirky about the water and was wondering if anyone knew what was going on or hopefully how to fix it... is it something I screwed up in the editor or is it related to the third person camera, maybe something I have forgotten, or its not supported? Just kind of hoping someone has ran into this issue before and has an idea of how to fix it or where I should start looking. I am not really doing anything special in code, this water is setup in the SBX and is loaded in with scene, however, I can post the code if anyone thinks it might help. I can also post the SBX but it uses quite a few models from Arteria3D that I cannot send with the SBX so that could get in the way. Also want to mention that the water looks fine in the editor and is reflecting everything correctly or at least seems to be. It also used to work very well when I was using my first person camera... it seems to have completely screwed up at this point. I based my third person camera code off the code I found in Jecklyn Heights, as it seemed to be a rather solid base to build a more robust third person camera (and I am still kind of riding with the training wheels on as far as LE is concerned.) EDIT: Code is now in a post below Thanks, David
  4. I was having an issue like this when I was setting up my current project... to fix it I believe I had to copy over the Materials folder to my projects content directory and it started working, this was in addition to copying over the shaders.pak and script folder.
  5. I was able to solve my issues by using the second material file provided with the demo which defines the color and depth buffers for you as texture parameters 2 and 3 within the material file itself, I am still kind of curious though if there is a way to do this in code with LEO/Framework.
  6. I have not used the editor much, but of the times I have, I have made quite a few mistakes still getting used to how to use it and having the ability to undo those mistakes would be a big time saver. I am guessing(hoping) the more I use the editor the less I will desire the feature, but just starting out, not having that functionality is quite a pain.
  7. Hey guys, I am fairly new to Leadwerks (Just for the engine a couple days ago) and started going through the tutorials to figure some stuff out. I decided to do them with LEO/Framework that way I would have to do some figuring out to get the tutorials to work and it wasn't just read and type what I see. Well this worked great up until the Transparency and Refraction tutorial. I got Transparency working correctly, but Refraction I have run into somewhat of a roadblock. Basically the Refraction tutorial uses buffers and passes those to the materials shader, but all of the rendering of the worlds and lighting occur in the framework and so I am not sure where or how I would use those buffers... I am sure its something simple I am just missing but any help you can offer would be greatly appreciated. The code is kind of a compilation of a bunch of tutorials thrown together, which is why there is 200 random barrels in the level also. // ==================================================================== // This file was generated by Leadwerks ProjectWizard // http://www.leadwerks.com // ==================================================================== #include "leo.h" using namespace LEO ; inline float rnd( float min=0.0, float max=1.0 ) { return min + ((float)rand()/RAND_MAX)*(max-min); } #if defined( _WINDOWS ) void ErrOut( const char* pstrMessage ) { MessageBoxA(0, pstrMessage, "Error", 0 ); } int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd ) #else #include <string> void ErrOut( const std::string& message ) { puts( message.c_str()); } int main( int argn, char* argv[] ) #endif { // Set graphics mode Engine engine("Leadwerks_Testing",1680,1050); if( !engine.IsValid() ) { ErrOut( "Failed to set graphics mode."); return 1; } RegisterAbstractPath( "C:/Leadwerks Engine SDK" ) ; // Create framework object and set it to a global object so other scripts can access it Framework fw; fw.Create(); if( NULL == fw ) { ErrOut( "Failed to initialize engine." ); return 1; } // Set Lua framework object engine.SetObject( "fw", fw ); // Set Lua framework variable Lua lua; lua.Create(); lua.PushObject( fw ); lua.SetGlobal( "fw" ); lua.Pop( 1 ); // Turn on bloom fw.GetRenderer().SetBloom(1); // Get framework main camera fw.main.GetCamera().SetPosition( Vec3(0,2,-10) ); // Load the scene Model scene("Content\\scene.gmf") ; if ( !scene.IsValid() ) { MessageBoxA( 0, "Failed to load scene.", "Error", 0 ); return engine.Free(); } scene.SetType(1); // Load the oildrum Model model("Content\\oildrum.gmf") ; if ( !model.IsValid() ) { MessageBoxA( 0, "Failed to load scene.", "Error", 0 ); return engine.Free(); } model.SetType(1); model.SetMass(1.0f); // Make a bunch of copies for ( int i=1; i<=200; i++ ) { Entity modelCopy = model.Copy(); modelCopy.SetPosition(Vec3(rnd(-5,5),rnd(5,15),rnd(-5,5))); modelCopy.SetRotation(Vec3(rnd(0,360),rnd(0,360),rnd(0,360))); } fw.transparency.GetWorld().Set(); //Create the transparent object Sphere sphere(50); sphere.SetPosition(Vec3(0, 3, 0)); sphere.SetScale(2.0f); //Load the transparent material Material mat("Content\\glass_refraction.mat"); if( !mat.IsValid() ) { MessageBoxA(0, "Failed to load material.", "Error", 0); return engine.Free(); } sphere.Paint(mat); // Set Shader params Shader shader = mat.GetShader(); shader.Set("refractionstrength",0.05f); fw.main.GetWorld().Set(); // Create a light DirectionalLight light( CREATENOW ); light.SetRotation( Vec3(45) ); // Camera controls TVec3 camrotation=Vec3(0); float mx=0; float my=0; float move=0; float strafe=0; // Center the mouse on the screen and hide it Mouse::Move(engine.GetWidth()/2,engine.GetHeight()/2); Mouse::Hide(); // Turn on Collision Collisions::Set(1,1); while( !engine.IsTerminated() && !Keyboard::I****(KEY_ESCAPE) ) { // Update the mouse input mx=Curve((float)Mouse::GetX()-engine.GetWidth()/2, mx, 6); my=Curve((float)Mouse::GetY()-engine.GetHeight()/2, my, 6); Mouse::Move(engine.GetWidth()/2,engine.GetHeight()/2); // Get keyboard input move=Curve((float)(Keyboard::IsDown(KEY_W)-Keyboard::IsDown(KEY_S)), move, 20); strafe=Curve((float)(Keyboard::IsDown(KEY_D)-Keyboard::IsDown(KEY_A)), strafe, 20); // Lets update the cameras rotation camrotation.X=camrotation.X + (my / 10.0f); camrotation.Y=camrotation.Y - (mx / 10.0f); fw.main.GetCamera().Move( Vec3(strafe / 10.0f,0,move / 10.0f) ); fw.main.GetCamera().SetRotation(camrotation); // Update the world and render it fw.Update(); fw.Render(); engine.Flip( 0 ); } return engine.Free(); } Thanks, -David
×
×
  • Create New...