PageRenderTime 32ms CodeModel.GetById 2ms app.highlight 27ms RepoModel.GetById 1ms app.codeStats 0ms

/src/renderer/render.cpp

https://bitbucket.org/vivkin/gam3b00bs/
C++ | 225 lines | 152 code | 37 blank | 36 comment | 22 complexity | eb3dc409e00a9815426d238d3ba37fa8 MD5 | raw file
  1#include "app/app.h"
  2#include "renderer/device.h"
  3#include "renderer/mesh.h"
  4#include "renderer/particles.h"
  5#include "load_data.h"
  6#include "visual.h"
  7#include "app/app.h"
  8#include "log.h"
  9#include "load_data.h"
 10//-----------------------------------------------------------------------------
 11
 12texture_h			texture;
 13mesh_h				mesh;
 14camera_t            camera;
 15//mesh_h				text_mesh;
 16//texture_h			text_texture;
 17render_op			rop;
 18environment_state_t env;
 19D3DXMATRIX			view;
 20D3DXMATRIX			proj;
 21visual_h			vis, boobs;
 22particle_system_t   psys;
 23//-----------------------------------------------------------------------------
 24
 25float yaw = 0.0f;
 26//-----------------------------------------------------------------------------
 27
 28bool test_init()
 29{
 30	// some test data initialisation
 31	memset(&env, 0, sizeof(environment_state_t));
 32
 33	env.light[0].Type = D3DLIGHT_POINT;
 34	env.light[0].Ambient = D3DXCOLOR(0.2f, 0.2f, 0.2f, 1.0f);
 35	env.light[0].Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
 36	env.light[0].Specular = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
 37	env.light[0].Position = D3DXVECTOR3(0.0f, 100.0f, 0.0f);
 38	env.light[0].Range = 200.0f;
 39	env.light[0].Attenuation0 = 1.0f;
 40	env.light[0].Attenuation1 = 0.0f;
 41	env.light[0].Attenuation2 = 0.0001f;
 42//	env.light_enable[0] = true;
 43
 44	env.light[1].Type = D3DLIGHT_SPOT;
 45	env.light[1].Ambient = D3DXCOLOR(0.2f, 0.2f, 0.2f, 1.0f);
 46	env.light[1].Diffuse = D3DXCOLOR(1.0f, 0.0f, 1.0f, 1.0f);
 47	env.light[1].Specular = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
 48	env.light[1].Position = D3DXVECTOR3(0.0f, 100.0f, 0.0f);
 49	env.light[1].Direction = D3DXVECTOR3(-1.0f, -1.0f, -1.0f);
 50	env.light[1].Range = 200.0f;
 51	env.light[1].Falloff = 1.0f;
 52	env.light[1].Phi = 3.14f / 2.0f;
 53	env.light[1].Theta = 3.14f / 3.0f;
 54	env.light[1].Attenuation0 = 1.0f;
 55	env.light[1].Attenuation1 = 0.0f;
 56	env.light[1].Attenuation2 = 0.0001f;
 57//	env.light_enable[1] = true;
 58
 59	env.light[2].Type = D3DLIGHT_SPOT;
 60	env.light[2].Ambient = D3DXCOLOR(0.2f, 0.2f, 0.2f, 1.0f);
 61	env.light[2].Diffuse = D3DXCOLOR(0.0f, 0.0f, 1.0f, 1.0f);
 62	env.light[2].Specular = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
 63	env.light[2].Position = D3DXVECTOR3(0.0f, 100.0f, 0.0f);
 64	env.light[2].Direction = D3DXVECTOR3(-1.0f, 0.0f, 0.0f);
 65	env.light[2].Range = 200.0f;
 66	env.light[2].Falloff = 1.0f;
 67	env.light[2].Phi = 3.14f / 3.0f;
 68	env.light[2].Theta = 3.14f / 4.0f;
 69	env.light[2].Attenuation0 = 1.0f;
 70	env.light[2].Attenuation1 = 0.0f;
 71	env.light[2].Attenuation2 = 0.0001f;
 72//	env.light_enable[2] = true;
 73
 74	env.light[3].Type = D3DLIGHT_SPOT;
 75	env.light[3].Ambient = D3DXCOLOR(0.2f, 0.2f, 0.2f, 1.0f);
 76	env.light[3].Diffuse = D3DXCOLOR(0.0f, 1.0f, 0.0f, 1.0f);
 77	env.light[3].Specular = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
 78	env.light[3].Position = D3DXVECTOR3(200.0f, 200.0f, 200.0f);
 79	env.light[3].Direction = D3DXVECTOR3(-1.0f, -1.0f, -1.0f);
 80	env.light[3].Range = 400.0f;
 81	env.light[3].Falloff = 1.0f;
 82	env.light[3].Phi = 3.14f / 3.0f;
 83	env.light[3].Theta = 3.14f / 4.0f;
 84	env.light[3].Attenuation0 = 1.0f;
 85	env.light[3].Attenuation1 = 0.01f;
 86	env.light[3].Attenuation2 = 0.0f;
 87//	env.light_enable[3] = true;
 88
 89	env.light[4].Type = D3DLIGHT_DIRECTIONAL;
 90	env.light[4].Ambient = D3DXCOLOR(0.2f, 0.2f, 0.2f, 1.0f);
 91	env.light[4].Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
 92	env.light[4].Specular = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
 93	env.light[4].Direction = D3DXVECTOR3(-1.0f, -1.0f, -1.0f);
 94	env.light_enable[4] = true;
 95
 96	D3DXVec3Normalize((D3DXVECTOR3*)&env.light[1].Direction, (D3DXVECTOR3*)&env.light[1].Direction);
 97	D3DXVec3Normalize((D3DXVECTOR3*)&env.light[2].Direction, (D3DXVECTOR3*)&env.light[2].Direction);
 98	D3DXVec3Normalize((D3DXVECTOR3*)&env.light[3].Direction, (D3DXVECTOR3*)&env.light[3].Direction);
 99	D3DXVec3Normalize((D3DXVECTOR3*)&env.light[4].Direction, (D3DXVECTOR3*)&env.light[4].Direction);
100
101	camera.angle = 0.0f;
102	camera.aspect = 1.333f;
103	camera.fov = 3.14f / 4.0f;
104	camera.position = D3DXVECTOR3(200.0f, 200.0f, 200.0f);
105	camera.target = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
106	camera.zfar = 1000.0f;
107	camera.znear = 1.0f;
108	camera.radius = 200.0f;
109	camera.phi = 3.14f / 3.0f;
110
111//	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));
112//	camera_perspective(camera, 3.14f / 4.0f, 1.333f, 1.0f, 1000.0f);
113
114	D3DXVECTOR3 eye(200.0f, 200.0f, 200.0f);
115	D3DXVECTOR3 at(0.0f, 80.0f, 0.0f);
116	D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
117	D3DXMatrixLookAtLH(&view, &eye, &at, &up);
118
119	D3DXMatrixPerspectiveFovLH(&proj, 3.14f / 4.0f, 1.333f, 1.0f, 1000.0f);
120
121	particle_system_create(&psys);
122
123	byte* texture_data;
124	uint32 texture_data_size;
125	texture = 0;
126	if (!load_data("..\\textures\\particle.dds", &texture_data, &texture_data_size))
127	{
128		texture = renderer::texture_create(texture_data, texture_data_size);
129		free(texture_data);
130	}
131
132	particle_desc_t emitter_desc = {
133		texture,
134		D3DXVECTOR3(0.0f, 80.0f, 0.0f),
135		D3DXVECTOR3(0.0f, 1.0f, 0.0f),
136		{10, 12},
137		{10, 12},
138		{30, 50},
139		{{1, 1, 0}, {1, 0, 0}},
140		20.0f,
141		100000.0f
142	};
143
144	particle_system_add(&psys, &emitter_desc);
145
146	return true;
147}
148//-----------------------------------------------------------------------------
149
150namespace renderer
151{
152
153void tick()
154{
155	if( !renderer::begin() )
156		return;
157
158	app::timings TM = app::time();
159
160	particle_system_update(&psys, camera, TM.dt);
161
162	renderer::clear(0xFF000000);
163
164	set_environment_state(env);
165	//set_view(view);
166	//set_projection(proj);
167	set_camera(camera);
168
169	set_sampler(0, SAMPLER_DEFAULT);
170/*
171	rop.vb = mesh->vb;
172	rop.ib = mesh->ib;
173	rop.index_count = mesh->header.index_count;
174	rop.vertex_count = mesh->header.vertex_count;
175	rop.material.texture[0] = texture;
176
177	for( uint32 i=0; i<mesh->header.subset_count; i++ )
178	{
179		rop.index_count = mesh->subsets[i].index_count;
180		rop.index_offset = mesh->subsets[i].index_offset;
181		rop.vertex_offset = mesh->subsets[i].vertex_offset;
182		renderer::render(rop);
183	}
184*/
185//	visual_draw( vis );
186//	visual_draw( boobs );
187
188	visuals_render_all();
189	particle_system_render(&psys, camera, renderer::device_get());
190
191//	float dt = app::time().dt;
192//	yaw += dt;
193
194//	visual_set_rotation(boobs, 0.0f, yaw, 0.0f);
195
196	renderer::end();
197
198	int16 xr, yr;
199	app::timings time = app::time();
200	app::input::get_cursor_rel(&xr, &yr);
201	if( app::input::get_button_state(2) == app::input::DOWN || app::input::get_button_state(2) == app::input::PRESSED )
202		camera_rotate(camera, xr * time.dt);
203
204	if( app::input::get_key_state(0x21) == app::input::DOWN || app::input::get_key_state(0x21) == app::input::PRESSED )
205		camera.phi += time.dt;
206
207	if( app::input::get_key_state('R') == app::input::DOWN || app::input::get_key_state('R') == app::input::PRESSED )
208		camera.phi += time.dt;
209
210	if( app::input::get_key_state(0x22) == app::input::DOWN || app::input::get_key_state(0x22) == app::input::PRESSED )
211		camera.phi -= time.dt;
212
213	if( app::input::get_key_state('F') == app::input::DOWN || app::input::get_key_state('F') == app::input::PRESSED )
214		camera.phi -= time.dt;
215
216	int wr = app::input::get_wheel_rel();
217	camera_zoom(camera, -(float)wr * time.dt * 5.0f);
218
219	float dx = (float)(app::input::get_key_state('A') > 0) - (float)(app::input::get_key_state('D') > 0);
220	float dz = (float)(app::input::get_key_state('S') > 0) - (float)(app::input::get_key_state('W') > 0);
221	camera_move(camera, dx * time.dt * 200.0f, dz * time.dt * 200.0f);
222}
223
224}
225//-----------------------------------------------------------------------------