Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include "Headers/Camera.h"

#include "Rendering/Headers/Frustum.h"
#include "Hardware/Video/GFXDevice.h"
#include "Managers/Headers/SceneManager.h"

void Camera::SaveCamera(){

	tSaveVectors[0] = vEye;
	tSaveVectors[1] = vCenter;
	tSaveVectors[2] = vViewDir;
	tSaveVectors[3] = vLeftDir;
	tSaveVectors[4] = vUp;

	tSaveFloats[0] = fAngleX;
	tSaveFloats[1] = fAngleY;

	bSaved = true;
}

void Camera::RestoreCamera() {

	if(bSaved) {
		vEye = tSaveVectors[0];
		vCenter = tSaveVectors[1];
		vViewDir = tSaveVectors[2];
		vLeftDir = tSaveVectors[3];
		vUp = tSaveVectors[4];

		fAngleX = tSaveFloats[0];
		fAngleY = tSaveFloats[1];
	}

	bSaved = false;
}


Camera::Camera() : Resource() {

	fAngleX	=	3.0f;
	fAngleY	=	M_PI/2;

	vUp			= vec3<F32>(0.0f, 1.0f, 0.0f);
	vEye		= vec3<F32>(0.0f, 0.0f, 0.0f);
	bSaved = false;
	Refresh();
}


void Camera::Refresh() {	

	switch(eType) {
	case FREE_FLY:
		vViewDir.x = cosf(fAngleX) * sinf(fAngleY);
		vViewDir.y = cosf(fAngleY);
		vViewDir.z = sinf(fAngleX) * sinf(fAngleY);
		vCenter = vEye + vViewDir;
		vLeftDir.cross(vUp, vViewDir);
		vLeftDir.normalize();
		break;

	case SCRIPTED:
		vViewDir = vCenter - vEye;
		vViewDir.normalize();
		vLeftDir.cross(vUp, vViewDir);
		vLeftDir.normalize();
		break;
	}
}

///Tell the rendering API to set up our desired PoV
void Camera::RenderLookAt(bool invertx, bool inverty, F32 planey) {
	///Tell the Rendering API to draw from our desired PoV
	if(inverty){							 
		///If we need to flip the camera upside down (ex: for reflections)
		GFX_DEVICE.lookAt(vec3<F32>(vEye.x,2.0f*planey-vEye.y,vEye.z),
						  vec3<F32>(vCenter.x,2.0f*planey-vCenter.y,vCenter.z),
						  vec3<F32>(-vUp.x,-vUp.y,-vUp.z),invertx);
	}else{
		GFX_DEVICE.lookAt(vEye,vCenter,vUp);
	}
	///Extract the frustum associated with our current PoV
	Frustum::getInstance().Extract(vEye);
	///Inform all listeners of a new event
    updateListeners();
}

void Camera::MoveForward(F32 factor)	{	
	vEye += vViewDir * factor;

	Refresh();
}

void Camera::TranslateForward(F32 factor)	{	
	vEye += vViewDir * factor;

	Refresh();
}

void Camera::MoveStrafe(F32 factor)	{
	vEye += vLeftDir * factor;

	Refresh();
}

void Camera::TranslateStrafe(F32 factor)	{
	vEye += vLeftDir * factor;

	Refresh();
}


void Camera::MoveAnaglyph(F32 factor){

	vEye += vLeftDir * factor;
	vCenter += vLeftDir * factor;
}

void Camera::RenderLookAtToCubeMap(const vec3<F32>& eye, U8 nFace){

	assert(nFace < 6);
	///Get the center and up vectors for each cube face
	vec3<F32> TabCenter[6] = {	vec3<F32>(eye.x+1.0f,	eye.y,		eye.z),
							    vec3<F32>(eye.x-1.0f,	eye.y,		eye.z),
							    vec3<F32>(eye.x,		eye.y+1.0f,	eye.z),
							    vec3<F32>(eye.x,		eye.y-1.0f,	eye.z),
      							vec3<F32>(eye.x,		eye.y,		eye.z+1.0f),
							    vec3<F32>(eye.x,		eye.y,		eye.z-1.0f) };


	static vec3<F32> TabUp[6] = {	vec3<F32>(0.0f,	-1.0f,	0.0f),
									vec3<F32>(0.0f,	-1.0f,	0.0f),

									vec3<F32>(0.0f,	0.0f,	1.0f),
									vec3<F32>(0.0f,	0.0f,	-1.0f),

									vec3<F32>(0.0f,	-1.0f,	0.0f),
									vec3<F32>(0.0f,	-1.0f,	0.0f) };
	///Set our eye position
	setEye( eye );
	///Set our Rendering API to render the desired face
	GFX_DEVICE.lookAt(eye,TabCenter[nFace],TabUp[nFace]);
	///Extract the view frustum associated with this face
	Frustum::getInstance().Extract(eye);
	///Inform all listeners of a new event
    updateListeners();
}

void Camera::updateListeners(){
	for_each(boost::function0<void > listener, _listeners){
		listener();
	}
}

Commits for Divide-Framework/trunk/Source Code/Rendering/Camera/Camera.cpp

Diff revisions: vs.
Revision Author Commited Message
117 Diff Diff k1ngp1n picture k1ngp1n Tue 05 Jun, 2012 17:30:40 +0000

[Ionut] [[BR]]
-Separated responsibilities between “Application” and “Kernel” [[BR]]
--“Application” handles data such as window dimensions, logs, “ParamHandler” etc [[BR]]
--“Kernel” handles the main loop, SFX, GFX, physics, sceneManager etc updates [[BR]]
---“Kernel” is now a “Core” component [[BR]]
-Reduced coupling between some classes by passing more info via parameters rather than relying on singleton access [[BR]]
--Ex: eyePos in “Terrain”,“Water” and “Trigger” classes is now passed as a "vec3<F32>" on render call rather than querying “CameraManager” [[BR]]
-Reworked “GLWrapper” shutdown routine [[BR]]
Singleton witch hunt [[BR]]
-“Kernel” is no longer a singleton and it’s initialized on application startup in the “Application” class[[BR]]
-“CameraManager” is no longer a singleton and it’s instantiated in the kernel [[BR]]

106 Diff Diff k1ngp1n picture k1ngp1n Wed 28 Mar, 2012 21:50:23 +0000

[Ionut] [[BR]]
Unstable revision – New animation code is not yet optimized and loading performance is low [[BR]]
[[BR]]
-Added animation loading and bone matrix calculations (actual skinning not implemented yet)[[BR]]
-Modified VBO classes to support dynamic data and faster updates [[BR]]
-Templatized Math classes (vec2,vec3,vec4,mat3,mat4) for greater flexibility [[BR]]
-Separated Rendering API from Rendering API version [[BR]]
-Fixed buggy GL error checking [[BR]]
-Small bugs fixed in Projectile and Weapon classes [[BR]]

103 Diff Diff k1ngp1n picture k1ngp1n Mon 12 Mar, 2012 19:06:00 +0000

[Ionut] [[BR]]
Features: [[BR]]
-Added a proper RenderState Management system similar to the D3D default one[[BR]]
--All possible states are managed: cull, blend, alpha-blend, color mask, lighting, stencil mask, fill mode etc [[BR]]
--Every material has different states for normal rendering, shadow rendering and reflection rendering [[BR]]
--Nodes are sorted by shader first then by state hash depending on current render stage [[BR]]
--Redundant states are not changed [[BR]]
--Every entity submits it’s desired state before render [[BR]]
--Every state is checked before rendering a VBO or other primitive type[[BR]]
[[BR]]
-Added a Reflector base class used for reflection calculations and updates (useful for water, mirrors, portals etc)[[BR]]
--Reflections are triggered between pre-render and render calls [[BR]]
--Water now derives from Reflector class as well [[BR]]
[[BR]]
-Material now properly calculates if it has transparency or is double sided, setting desired states to handle this feature (cull, blend) [[BR]]
-Added some basic defines or inline template functions to facilitate access to useful classes and methods (hardware devices, resource management, console printing, etc) [[BR]]
-Lights are updated after every camera update[[BR]]
-Added a new FrameListener event triggered after pre-render call is finished (used by reflectors) [[BR]]
-Added a CRC class to compute unique hash values for entities[[BR]]
-Added D3D dummy files [[BR]]
-Removed executables from subversion [[BR]]
Performance: [[BR]]
-Image loading has been improved a bit [[BR]]
-Terrain texel density now varies with LOD level [[BR]]
-Light API specific calls,except position, are set only if values changed[[BR]]
-Specific GUI casting and rendering are the Rendering API’s job now, not the GUI class [[BR]]
-Rendering Queue processing is now more efficient in sorting valid visible nodes and setting appropriate states/materials
[[BR]]
Bug fixes: [[BR]]
-Better drawState checks[[BR]]
-Proper light effects in deferred rendering[[BR]]
-Light dummy now renders properly[[BR]]
-Reworked bounding box computation [[BR]]
[[BR]]
Known bugs: [[BR]]
-Terrain infinite plain still not visible [[BR]]
-Some z-fighting occurs when looking at certain objects from a distance. (looking at another object and back again fixes it) [[BR]]

100 Diff Diff k1ngp1n picture k1ngp1n Mon 05 Mar, 2012 17:45:11 +0000

[Ionut] [[BR]]
Features: [[BR]]
-Added a physics system interface instead of direct PhysX interaction to allow other physics engines (Bullet, ODE etc) to be easily implemented [[BR]]
--This will aid in Object-Object collisions and character control in future revisions [[BR]]
-Added an Ogre3D inspired FrameListener which now allows Before-frame/during-frame/after-frame event plugins of callbacks [[BR]]
-Added a renderInViewport system to draw elements in a user defined rectangle on screen [[BR]]
--Current uses: shadowmap preview (F10) [[BR]]
-Separated Shaders from ShaderPrograms[[BR]]
--ShaderPrograms can now use multiple Shaders [[BR]]
-Error output is now sent to errors.log[[BR]]
-All SceneNode based elements now have a postDraw calls as well [[BR]]
-A cubemap generating function has been added to the GFXDevice class[[BR]]
-Added debug only print options to the Console class [[BR]]
[[BR]]
Performance: [[BR]]
-All shadows are now filtered by a faster Gaussian 3x3 blur filter [[BR]]
-All renderables are now sorted and rendered by material/front-to-back/back-to-front, depending on case [[BR]]
-RenderQueue now sorts and queue’s translucent and opaque objects separately[[BR]]
-Shader uniforms/attributes are now cached to reduce number of address calls to the GPU[[BR]]
-Shaders are now cached, so that if multiple ShaderPrograms use an already compiled Shader, that Shader is returned from memory instead of creating a new copy[[BR]]
-Shaders are not unbound/rebound except when an objects demands so (vastly improves performance)[[BR]]
-Reduced calls to glEnable[[BR]]
[[BR]]
Bug fixes: [[BR]]
-Preprocessor configurations now work properly [[BR]]
-Video API is now unloaded before destruction [[BR]]
-Manager base class now properly frees memory [[BR]]
-Materials are saved to XML only if they are changed at any point [[BR]]

97 Diff Diff k1ngp1n picture k1ngp1n Tue 07 Feb, 2012 15:23:45 +0000

[ Ionut ] [[BR]]
-Restructured code base to a more logical layout [[BR]]
--Geometry folder contains shapes, materials, animations and the importer; Environment folder holds sky, terrain, water, vegetation; etc [[BR]]
--All header files are moved to a “Headers” sub-folder [[BR]]
--Renamed most of the Romanian code/comments/files/folders to English [[BR]]
--Added comments to parts of the code (ongoing from now on) [[BR]]
[[BR]]
-Rewrote the entire lighting system [[BR]]
--Added a LightManager class to handle all lights [[BR]]
---LightManager calls updates and render calls to all lights it manages [[BR]]
--Lights have all needed properties stored in 2 maps (one for vector values, one for float values) [[BR]]
--Added a LightImpostor class that takes the light’s properties and applies it to a dummy sphere [[BR]]
--If a light should draw it’s impostor, the impostor draws the dummy sphere [[BR]]
--Rewrote the Light <-> GFXDevice interaction [[BR]]
---Each light stores it’s type in a variable and passes all properties to the rendering API that then decides what to use based on that type [[BR]]
--Each light handles it’s own ShadowMapping [[BR]]
[[BR]]
-ShadowMapping: [[BR]]
-Each light stores it’s own depth maps and generates them based on it’s type [[BR]]
-LightManager binds all available depth maps and shaders pick them up automatically for use [[BR]]
-Each shadow map (of a total of 3 per light) corresponds to a detail level[[BR]]
-The final shadow map resolution is decided by the shadow detail level set in the config [[BR]]
--Camera and Frustum are set up for shadow rendering and applied to the render callback set for the current light (for example, Scene::render()) [[BR]]
--The light manager tells every light that has “_castShadows = true” to generate shadowmaps automatically after the Scene::PreRender stage [[BR]]
--ShadowMaps are blurred before applied to the fragment’s final color via shaders. [[BR]]
[[BR]]
-Added detail level configuration options [[BR]]
--ToDo: add shaders for each detail level [[BR]]
[[BR]]
-Moved all predefined geometry from immediate mode to VBO’s [[BR]]
--This allowed the rendering pipeline to be more streamlined (one render function for all geometry) [[BR]]
[[BR]]
-Fixed GuiElement visibility toggle [[BR]]
-Fixed GuiText color state problem [[BR]]
-Added FBO texture format options [[BR]]
-VBO rendering uses U16 as default instead of U32 (better for GPU) [[BR]]
-VBO’s now contain BiTangent data as well [[BR]]
-Added OpenGL 2.0 compatibility (not guaranteed!) [[BR]]
-Added static (on load) shader selection based on detail level [[BR]]
-Added SSAO PostFX option, but this won’t work until the implementation of “plugins” for PostFX system [[BR]]
-Optimized/Fixed code based on VisualLint + CppCheck analysis [[BR]]

87 Diff Diff k1ngp1n picture k1ngp1n Wed 16 Nov, 2011 22:06:17 +0000

[Ionut Cava] [[BR]]
-Major changes: [[BR]]
--Transformations are now part of the SceneGraphNode and not the object itself[[BR]]
--Resource reference counting is now per-resource instead of centralized in the ResourceManager[[BR]]
--Resource reference counting now supports copying all of the resource’s dependencies[[BR]]
--SceneGraph rendering/updating routines changed dramatically for future threading/batching considerations[[BR]]
--Added SSE2 matrix transformations[[BR]]
--All used materials are dumped to XML and loaded from there if found. Makes editing materials easier[[BR]]
--Depth maps and shadows are automatically enabled if a scene creates the depthMap[] FBO’s [[BR]]
--SceneGraph automatically unloads child objects from nodes (clearing up Sky, Terrain, Water etc)[[BR]]
[[BR]]
-Minor changes / bug fixes[[BR]]
--Terrain material+shader are now properly set and used[[BR]]
--SceneGraph structure can be printed in the console[[BR]]
--Converted most tga resources to png only due to size[[BR]]
--Mesh-SubMesh <-> SceneGraphNode Parent-Children conversion fixed[[BR]]
--inline’d most functions that could be inlined[[BR]]
--Fixed PostFX frame buffer generation at init step[[BR]]
--cached BoundingBox data on retrieval [[BR]]
--fixed some transformation code (rotation on specific axis was buggy)[[BR]]
--resources can not be copied! (copy constructor and assignment operator are private). Use ResourceManager to get a new reference to the resource [[BR]]
--SceneNodes now have 2 functions, prepareMaterial and releaseMaterial that are called before respectively after the node is rendered [[BR]]
--SceneGraphNodes now call a SceneNode’s function called postLoad that passes a pointer to the SGN from which it’s called so that the SN can update accordingly.[[BR]]
--cleaned up OpenGL-specific rendering pipeline[[BR]]
--removed most iterator based map traversal with boost’s foreach allowing future support for tr1’s foreach with lambda expressions[[BR]]
--A lot of other small changes not worth mentioning as of yet[[BR]]
[[BR]]

86 Diff Diff k1ngp1n picture k1ngp1n Thu 20 Oct, 2011 18:24:23 +0000

[Ionut Cava] [[BR]]
-Major changes: [[BR]]
--Fixed water reflections and refractions (depth sorting still not working). [[BR]]
---Reworked shadow map calculation and water reflection FBO calculations [[BR]]

--Added Post Processing Full Screen Effects framework with support for: [[BR]]
---3D Anaglyph Rendering [[BR]]
---Depth of Field (next commit) [[BR]]
---Full screen radial blur (next commit) [[BR]]
---Full screen noise effect (next commit) [[BR]]
---Bloom effect (next commit) [[BR]]
---- (next commit) elements already have XML toggle options and FBO support in the engine, but the actual calculations are not implemented yet [[BR]]

-Minor changes [[BR]]
--Materials and transforms are no longer mandatory for SceneNodes (e.g.: node->setMaterial(NULL); node->useDefaultMaterial(NULL). same for transforms) [[BR]]
--Prevent double-bind of textures [[BR]]

85 Diff Diff k1ngp1n picture k1ngp1n Sun 16 Oct, 2011 16:28:05 +0000

[Ionut Cava] \\
-Major changes: \\
--All the framework code is now licensed under the GNU Lesser General Public License. Read the copyright files added in this commit as well as the copyright notice in each of the code headers \\
--Added a SceneGraph framework to handle scene hierarchy. The SceneGraph is composed of SceneGraphNodes that have a SceneNode and any number of SceneGraphNode children. Rendering is done recursively for now, but upgrades to spatial ordering and material batching will be added soon.
--More work on the material system. All material properties (diffuse, ambient, specular etc) are now stored in a mat4 vertex and sent to the frag shaders as such. The Material class also does all the shading initialization. The Material class is now a Resource and is also loaded/created/returned using the ResourceManager.\\
--Materials, BoundingBoxes and Transforms are now moved from Object3D to the SceneNode class, making the Object3DFlyWeight superseded. \\
--The ResourceManager now loads resources based on a ResourceDescriptor that holds information such as the resource’s name, physical file location, special flags etc. \\
--Modified terrain rendering and loading algorithms as well as the terrain shaders for better performance, as well as support for an extra channel in the AlphaMask (now textures can be placed based on a RGBA alpha mask). \\
--The Light class is a SceneNode now \\
--The Material class is a SceneNode now \\
--The Manager class has been fixed to support proper loading/unloading/deletion/insertion/extraction of resources to and from the unordered map \\

-Minor changes: \\
--Fixed the buggy removal of resources (pointer reference issue) \\
--More use of std::make_pair() instead of std::pair<>() \\
--More base class initialization from derived class’s constructor as well as some base class unload() calls \\
--Renamed the “Con” class to “Console” for better readability \\
--Added experimental state changing methods to the rendering API and using them in limited cases for now (setting texture matrix, preparing geometry transforms, etc) \\
--Cleaned up the geometry importer a bit. \\
--Water position and depth can now be set in the scene’s XML description file \\
--TerrainManager class is superseded by the SceneGraph => removed \\
--Camera class is now derived from Resource \\
-Known bugs: \\
--Without proper depth sorting, semi-transparent objects render wrong \\
--Water rendering is really bugged \\
--Random crashes may appear during application shutdown do to garbage left in DB’s \\

81 Diff Diff k1ngp1n picture k1ngp1n Fri 15 Jul, 2011 11:27:57 +0000

[Ionut]
-Moved project to Trac
-Moved Visual Studio Data outside of the source code
Added the first step to parent<>children object structure and parent matrix transformation

79 k1ngp1n picture k1ngp1n Sun 10 Jul, 2011 17:35:44 +0000

[Ionut Cava]
Additions:
-Added a SFX and AudioRenderingApi class that plays API independent sound (SDL_mixer,Fmod,OpenAL). Only SDL support for music and simple sound is implemented as of now.
-Added an AudioDescriptor class that holds information about sounds and is used by the SFX device to play what it describes.
-Added an API-independent PixelBufferObject class that builds a texture pixel by pixel;
-Polished up the Material class and now every Object3D derived entity uses it (Box3D,Sphere3D,Quad3D,Text3D,SubMesh etc). It contains a texture vector, color information, shininess and other light parameters(i.e. specular)
-Added a deffered-rendering system (implemented in CubeScene as of this commit. Results are not visible yet / shader incomplete):
--Modified the VertexBufferObject to hold a G-buffer(3 texture’s, one 32bit, one 24bit and the las 16bit). The first contains color information, the second position information, and the last normal information. A shader that calculates the data and adds it to the VBO is also added. (DefferedShadingPass1).
--Light information is written to a PBO (in the form position-color / only point lights supported for now).
--G-buffer and Light PBO’s are bound to a full-screen quad and a shader (DefferedShadingPass2) uses them to render the final product.

Fixes:
Huge code cleanup. Fixed most memory leaks
-Every resource in the game is now loaded through the ResourceManager and removed through it as well. Added a _refCount map for each resource to keep track of how many entities are using it, and delete that resource only when the last owning entity gets deleted;
-Most used memory is cleaned up at shutdown, and all resources are freed and released.
-Fixed threading system, by interrupting running threads, joining them and use shared_ptr for auto-deletion
-Events and Lights are managed via tr1::shared_ptr’s for self-cleanup and destruction
-Cleaned up some headers for useles includes. Added forward declarations were possible. Resized some variables to smaller types for lessening memory usage.
-Fixed a lot of virtual destruction ordering in some classes.
-Fixed boundingBox calculations for terrain. Calculate terrain object’s(trees) boundingbox first, then add it to terrain. Also increase speed of calculation, by using 2 floats for min and max Y-values per step and update BB at the end. (instead of updating BB at every step).
-Object3D base class holds information about shaders, materials, and suplimental BoundingBox information
-The ResourceManager now properly loads Object3D derived classes;
-Fixed memory leak in glTexture destruction after a previous resize (if dimensions where not power of 2 based)
-Removed most unused libraries
-Removing elements from a manager, first calls the “unload” function that should be implemented in every Resource-based class, then deletes the resource, then set’s it’s pointer to NULL;
-Added proper destruction for Object3DFlyweight
-Fixed renderstate activation and attribute appliance.
-More stuff that I can’t remember now ...