/src/renderer/render.cpp
https://bitbucket.org/vivkin/gam3b00bs/ · C++ · 225 lines · 152 code · 37 blank · 36 comment · 22 complexity · eb3dc409e00a9815426d238d3ba37fa8 MD5 · raw file
- #include "app/app.h"
- #include "renderer/device.h"
- #include "renderer/mesh.h"
- #include "renderer/particles.h"
- #include "load_data.h"
- #include "visual.h"
- #include "app/app.h"
- #include "log.h"
- #include "load_data.h"
- //-----------------------------------------------------------------------------
-
- texture_h texture;
- mesh_h mesh;
- camera_t camera;
- //mesh_h text_mesh;
- //texture_h text_texture;
- render_op rop;
- environment_state_t env;
- D3DXMATRIX view;
- D3DXMATRIX proj;
- visual_h vis, boobs;
- particle_system_t psys;
- //-----------------------------------------------------------------------------
-
- float yaw = 0.0f;
- //-----------------------------------------------------------------------------
-
- bool test_init()
- {
- // some test data initialisation
- memset(&env, 0, sizeof(environment_state_t));
-
- env.light[0].Type = D3DLIGHT_POINT;
- env.light[0].Ambient = D3DXCOLOR(0.2f, 0.2f, 0.2f, 1.0f);
- env.light[0].Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
- env.light[0].Specular = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
- env.light[0].Position = D3DXVECTOR3(0.0f, 100.0f, 0.0f);
- env.light[0].Range = 200.0f;
- env.light[0].Attenuation0 = 1.0f;
- env.light[0].Attenuation1 = 0.0f;
- env.light[0].Attenuation2 = 0.0001f;
- // env.light_enable[0] = true;
-
- env.light[1].Type = D3DLIGHT_SPOT;
- env.light[1].Ambient = D3DXCOLOR(0.2f, 0.2f, 0.2f, 1.0f);
- env.light[1].Diffuse = D3DXCOLOR(1.0f, 0.0f, 1.0f, 1.0f);
- env.light[1].Specular = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
- env.light[1].Position = D3DXVECTOR3(0.0f, 100.0f, 0.0f);
- env.light[1].Direction = D3DXVECTOR3(-1.0f, -1.0f, -1.0f);
- env.light[1].Range = 200.0f;
- env.light[1].Falloff = 1.0f;
- env.light[1].Phi = 3.14f / 2.0f;
- env.light[1].Theta = 3.14f / 3.0f;
- env.light[1].Attenuation0 = 1.0f;
- env.light[1].Attenuation1 = 0.0f;
- env.light[1].Attenuation2 = 0.0001f;
- // env.light_enable[1] = true;
-
- env.light[2].Type = D3DLIGHT_SPOT;
- env.light[2].Ambient = D3DXCOLOR(0.2f, 0.2f, 0.2f, 1.0f);
- env.light[2].Diffuse = D3DXCOLOR(0.0f, 0.0f, 1.0f, 1.0f);
- env.light[2].Specular = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
- env.light[2].Position = D3DXVECTOR3(0.0f, 100.0f, 0.0f);
- env.light[2].Direction = D3DXVECTOR3(-1.0f, 0.0f, 0.0f);
- env.light[2].Range = 200.0f;
- env.light[2].Falloff = 1.0f;
- env.light[2].Phi = 3.14f / 3.0f;
- env.light[2].Theta = 3.14f / 4.0f;
- env.light[2].Attenuation0 = 1.0f;
- env.light[2].Attenuation1 = 0.0f;
- env.light[2].Attenuation2 = 0.0001f;
- // env.light_enable[2] = true;
-
- env.light[3].Type = D3DLIGHT_SPOT;
- env.light[3].Ambient = D3DXCOLOR(0.2f, 0.2f, 0.2f, 1.0f);
- env.light[3].Diffuse = D3DXCOLOR(0.0f, 1.0f, 0.0f, 1.0f);
- env.light[3].Specular = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
- env.light[3].Position = D3DXVECTOR3(200.0f, 200.0f, 200.0f);
- env.light[3].Direction = D3DXVECTOR3(-1.0f, -1.0f, -1.0f);
- env.light[3].Range = 400.0f;
- env.light[3].Falloff = 1.0f;
- env.light[3].Phi = 3.14f / 3.0f;
- env.light[3].Theta = 3.14f / 4.0f;
- env.light[3].Attenuation0 = 1.0f;
- env.light[3].Attenuation1 = 0.01f;
- env.light[3].Attenuation2 = 0.0f;
- // env.light_enable[3] = true;
-
- env.light[4].Type = D3DLIGHT_DIRECTIONAL;
- env.light[4].Ambient = D3DXCOLOR(0.2f, 0.2f, 0.2f, 1.0f);
- env.light[4].Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
- env.light[4].Specular = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
- env.light[4].Direction = D3DXVECTOR3(-1.0f, -1.0f, -1.0f);
- env.light_enable[4] = true;
-
- D3DXVec3Normalize((D3DXVECTOR3*)&env.light[1].Direction, (D3DXVECTOR3*)&env.light[1].Direction);
- D3DXVec3Normalize((D3DXVECTOR3*)&env.light[2].Direction, (D3DXVECTOR3*)&env.light[2].Direction);
- D3DXVec3Normalize((D3DXVECTOR3*)&env.light[3].Direction, (D3DXVECTOR3*)&env.light[3].Direction);
- D3DXVec3Normalize((D3DXVECTOR3*)&env.light[4].Direction, (D3DXVECTOR3*)&env.light[4].Direction);
-
- camera.angle = 0.0f;
- camera.aspect = 1.333f;
- camera.fov = 3.14f / 4.0f;
- camera.position = D3DXVECTOR3(200.0f, 200.0f, 200.0f);
- camera.target = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
- camera.zfar = 1000.0f;
- camera.znear = 1.0f;
- camera.radius = 200.0f;
- camera.phi = 3.14f / 3.0f;
-
- // camera_look_at(camera, D3DXVECTOR3(200.0f, 200.0f, 200.0f), D3DXVECTOR3(0.0f, 80.0f, 0.0f), D3DXVECTOR3(0.0f, 1.0f, 0.0f));
- // camera_perspective(camera, 3.14f / 4.0f, 1.333f, 1.0f, 1000.0f);
-
- D3DXVECTOR3 eye(200.0f, 200.0f, 200.0f);
- D3DXVECTOR3 at(0.0f, 80.0f, 0.0f);
- D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
- D3DXMatrixLookAtLH(&view, &eye, &at, &up);
-
- D3DXMatrixPerspectiveFovLH(&proj, 3.14f / 4.0f, 1.333f, 1.0f, 1000.0f);
-
- particle_system_create(&psys);
-
- byte* texture_data;
- uint32 texture_data_size;
- texture = 0;
- if (!load_data("..\\textures\\particle.dds", &texture_data, &texture_data_size))
- {
- texture = renderer::texture_create(texture_data, texture_data_size);
- free(texture_data);
- }
-
- particle_desc_t emitter_desc = {
- texture,
- D3DXVECTOR3(0.0f, 80.0f, 0.0f),
- D3DXVECTOR3(0.0f, 1.0f, 0.0f),
- {10, 12},
- {10, 12},
- {30, 50},
- {{1, 1, 0}, {1, 0, 0}},
- 20.0f,
- 100000.0f
- };
-
- particle_system_add(&psys, &emitter_desc);
-
- return true;
- }
- //-----------------------------------------------------------------------------
-
- namespace renderer
- {
-
- void tick()
- {
- if( !renderer::begin() )
- return;
-
- app::timings TM = app::time();
-
- particle_system_update(&psys, camera, TM.dt);
-
- renderer::clear(0xFF000000);
-
- set_environment_state(env);
- //set_view(view);
- //set_projection(proj);
- set_camera(camera);
-
- set_sampler(0, SAMPLER_DEFAULT);
- /*
- rop.vb = mesh->vb;
- rop.ib = mesh->ib;
- rop.index_count = mesh->header.index_count;
- rop.vertex_count = mesh->header.vertex_count;
- rop.material.texture[0] = texture;
-
- for( uint32 i=0; i<mesh->header.subset_count; i++ )
- {
- rop.index_count = mesh->subsets[i].index_count;
- rop.index_offset = mesh->subsets[i].index_offset;
- rop.vertex_offset = mesh->subsets[i].vertex_offset;
- renderer::render(rop);
- }
- */
- // visual_draw( vis );
- // visual_draw( boobs );
-
- visuals_render_all();
- particle_system_render(&psys, camera, renderer::device_get());
-
- // float dt = app::time().dt;
- // yaw += dt;
-
- // visual_set_rotation(boobs, 0.0f, yaw, 0.0f);
-
- renderer::end();
-
- int16 xr, yr;
- app::timings time = app::time();
- app::input::get_cursor_rel(&xr, &yr);
- if( app::input::get_button_state(2) == app::input::DOWN || app::input::get_button_state(2) == app::input::PRESSED )
- camera_rotate(camera, xr * time.dt);
-
- if( app::input::get_key_state(0x21) == app::input::DOWN || app::input::get_key_state(0x21) == app::input::PRESSED )
- camera.phi += time.dt;
-
- if( app::input::get_key_state('R') == app::input::DOWN || app::input::get_key_state('R') == app::input::PRESSED )
- camera.phi += time.dt;
-
- if( app::input::get_key_state(0x22) == app::input::DOWN || app::input::get_key_state(0x22) == app::input::PRESSED )
- camera.phi -= time.dt;
-
- if( app::input::get_key_state('F') == app::input::DOWN || app::input::get_key_state('F') == app::input::PRESSED )
- camera.phi -= time.dt;
-
- int wr = app::input::get_wheel_rel();
- camera_zoom(camera, -(float)wr * time.dt * 5.0f);
-
- float dx = (float)(app::input::get_key_state('A') > 0) - (float)(app::input::get_key_state('D') > 0);
- float dz = (float)(app::input::get_key_state('S') > 0) - (float)(app::input::get_key_state('W') > 0);
- camera_move(camera, dx * time.dt * 200.0f, dz * time.dt * 200.0f);
- }
-
- }
- //-----------------------------------------------------------------------------