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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#include "Headers/Scene.h"

#include "Core/Headers/ParamHandler.h"
#include "Rendering/Headers/Frustum.h"

void Scene::findSelection(const vec3<F32>& camOrigin, U32 x, U32 y){
	F32 value_fov = tan(RADIANS(_paramHandler.getParam<F32>("runtime.verticalFOV")) * 0.5f);
    F32 value_aspect = _paramHandler.getParam<F32>("runtime.aspectRatio");
	F32 half_resolution_width = renderState()._cachedResolution.width * 0.5f;
	F32 half_resolution_height = renderState()._cachedResolution.height * 0.5f;

	//mathematical handling of the difference between
    //your mouse position and the 'center' of the window
    F32 modifier_x, modifier_y;
        
     F32 point_dist = _paramHandler.getParam<F32>("runtime.zFar");
        //it'll be put this far on the Z plane

    vec3<F32> camera_origin;
        //this is where the camera sits, in 3dspace

    vec3<F32> point_xformed;
        //this is the transformed point

    vec3<F32> final_point;
    vec4<F32> color(0.0, 1.0, 0.0, 1.0);

    //These lines are the biggest part of this function.
    //This is where the mouse position is turned into a mathematical
    //'relative' of 3d space. The conversion to an actual point
    modifier_x = value_fov * (( 1.0f - x / half_resolution_width ) * ( value_aspect ) );
    modifier_y = value_fov * -( 1.0f - y / half_resolution_height );

    //These 3 take our modifier_x/y values and our 'casting' distance
    //to throw out a point in space that lies on the point_dist plane.
    //If we were using completely untransformed, untranslated space,
    //this would be fine - but we're not :)
	//the untransformed ray will be put here
    vec3<F32> point(modifier_x * point_dist, modifier_y * point_dist, point_dist);

    //Next we make a call to grab our MODELVIEW_MATRIX -
    //This is the matrix that rasters 3d points to 2d space - which is
    //kinda what we're doing, in reverse
    mat4<GLfloat> temp;
    GFX_DEVICE.getMatrix(VIEW_MATRIX,temp);
    //Some folks would then invert the matrix - I invert the results.

    //First, to get the camera_origin, we transform the 12, 13, 14
    //slots of our pulledMatrix - this gets us the actual viewing
    //position we are 'sitting' at when the function is called
    camera_origin.x = -(
        temp.mat[0] * temp.mat[12] +
        temp.mat[1] * temp.mat[13] +
        temp.mat[2] * temp.mat[14]);
    camera_origin.y = -(
        temp.mat[4] * temp.mat[12] +
        temp.mat[5] * temp.mat[13] +
        temp.mat[6] * temp.mat[14]);
    camera_origin.z = -(
        temp.mat[8] * temp.mat[12] +
        temp.mat[9] * temp.mat[13] +
        temp.mat[10] * temp.mat[14]);

    //Second, we transform the position we generated earlier - the '3d'
    //mouse position - by our viewing matrix.
    point_xformed.x = -(
        temp.mat[0] * point[0] +
        temp.mat[1] * point[1] +
        temp.mat[2] * point[2]);
    point_xformed.y = -(
        temp.mat[4] * point[0] +
        temp.mat[5] * point[1] +
        temp.mat[6] * point[2]);
    point_xformed.z = -(
        temp.mat[8] * point[0] +
        temp.mat[9] * point[1] +
        temp.mat[10] * point[2]);

    final_point = point_xformed + camera_origin;

	vec3<F32> origin(camOrigin);
	vec3<F32> dir = origin.direction(final_point);

	Ray r(origin,dir);
	SceneGraphNode* previousSelection = _currentSelection;
	_currentSelection = _sceneGraph->Intersect(r,Frustum::getInstance().getZPlanes().x,
												 Frustum::getInstance().getZPlanes().y/2.0f);
	if(previousSelection) previousSelection->setSelected(false);
	if(_currentSelection) _currentSelection->setSelected(true);
	
}

void Scene::onMouseClickDown(const OIS::MouseEvent& key,OIS::MouseButtonID button){
	_mousePressed[button] = true;
}

void Scene::onMouseClickUp(const OIS::MouseEvent& key,OIS::MouseButtonID button){
	_mousePressed[button] = false;
}

void Scene::onKeyDown(const OIS::KeyEvent& key){
	switch(key.key){
		default: break;
		case OIS::KC_LEFT  : state()._angleLR = -1; break;
		case OIS::KC_RIGHT : state()._angleLR =  1; break;		
		case OIS::KC_UP    : state()._angleUD = -1; break;
		case OIS::KC_DOWN  : state()._angleUD =  1; break;
		case OIS::KC_END   : deleteSelection(); break;
		case OIS::KC_ADD   : {
			Camera& cam = renderState().getCamera();
			F32 currentCamMoveSpeedFactor = cam.getMoveSpeedFactor();
			if (currentCamMoveSpeedFactor < 5){
				cam.setMoveSpeedFactor( currentCamMoveSpeedFactor + 0.1f);   
				cam.setTurnSpeedFactor( cam.getTurnSpeedFactor() + 0.1f);   
			}
		}break;
		case OIS::KC_SUBTRACT :	{
			Camera& cam = renderState().getCamera();
			F32 currentCamMoveSpeedFactor = cam.getMoveSpeedFactor();
			if (currentCamMoveSpeedFactor > 0.2f){
				cam.setMoveSpeedFactor( currentCamMoveSpeedFactor - 0.1f);  
				cam.setTurnSpeedFactor( cam.getTurnSpeedFactor() - 0.1f);  
			} 
		}break;
		case OIS::KC_F2:{
			D_PRINT_FN(Locale::get("TOGGLE_SCENE_SKELETONS"));
			renderState().toggleSkeletons();
			}break;
		case OIS::KC_B:{
			D_PRINT_FN(Locale::get("TOGGLE_SCENE_BOUNDING_BOXES"));
			renderState().toggleBoundingBoxes();
			}break;
		case OIS::KC_F8:
			_paramHandler.setParam("postProcessing.enablePostFX",!_paramHandler.getParam<bool>("postProcessing.enablePostFX"));
			break;
		case OIS::KC_F10:
			LightManager::getInstance().togglePreviewShadowMaps();
			break;
		case OIS::KC_F12:
			GFX_DEVICE.Screenshot("screenshot_",vec4<F32>(0,0,renderState()._cachedResolution.x,renderState()._cachedResolution.y));
			break;
	}
}

void Scene::onKeyUp(const OIS::KeyEvent& key){
	switch( key.key ){
		case OIS::KC_LEFT :
		case OIS::KC_RIGHT:	state()._angleLR = 0; break;
		case OIS::KC_UP   :
		case OIS::KC_DOWN : state()._angleUD = 0; break;
		case OIS::KC_F3:
			_paramHandler.setParam("postProcessing.enableDepthOfField", !_paramHandler.getParam<bool>("postProcessing.enableDepthOfField"));
			break;
        case OIS::KC_F4:
            _paramHandler.setParam("postProcessing.enableBloom", !_paramHandler.getParam<bool>("postProcessing.enableBloom"));
            break;
        case OIS::KC_F5:
            GFX_DEVICE.drawDebugAxis(!GFX_DEVICE.drawDebugAxis());
            break;
		default:
			break;
	}
}

void Scene::onJoystickMoveAxis(const OIS::JoyStickEvent& key,I8 axis,I32 deadZone){
	if(key.device->getID() != InputInterface::JOY_1) return;

	I32 axisABS = key.state.mAxes[axis].abs;

	if(axis == 1){
		if(axisABS > deadZone)   	 state()._angleLR = 1;
		else if(axisABS < -deadZone) state()._angleLR = -1;
		else 			             state()._angleLR = 0;
	}else if(axis == 0){
		if(axisABS > deadZone)       state()._angleUD = 1;
		else if(axisABS < -deadZone) state()._angleUD = -1;
		else 			             state()._angleUD = 0;
	}else if(axis == 2){
		if(axisABS < -deadZone)  	 state()._moveFB = 1;
		else if(axisABS > deadZone)  state()._moveFB = -1;
		else			             state()._moveFB = 0;
	}else if(axis == 3){
		if(axisABS < -deadZone)      state()._moveLR = -1;
		else if(axisABS > deadZone)  state()._moveLR = 1;
		else                         state()._moveLR = 0;
	}
}

Commits for Divide-Framework/trunk/Source Code/Scenes/SceneInput.cpp

Diff revisions: vs.
Revision Author Commited Message
168 k1ngp1n picture k1ngp1n Sat 26 Oct, 2013 19:03:21 +0000

- Reworked the Camera class[[BR]]
— Now fully quaternion based [[BR]]
— Basic camera types added but not used yet (third person, first person, orbit) [[BR]]
- Cleaned up Material and Texture handling [[BR]]
- Added clipping plane support [[BR]]
— Similar to OpenGL fixed-function clip planes but fully shader driven [[BR]]
— Added a new class, “Plane”, that helps define clip planes [[BR]]
- Optimized the Singleton class to allow faster “getInstance” calls without performance penalties [[BR]]
-- “createInstance” must be called for each singleton class before usage. Or “gerOrCreateInstance” can be used, which is basically the former “getInstance” implementation [[BR]]
- Improved console logging by changing some heap allocations to stack and removing dependencies on the std::string class [[BR]]
- Added a lot of performance optimizations related to coding standards and redundant calculations [[BR]]
— e.g. Frustum AABB check didn’t need to recompute the AABB points as they were calculated already [[BR]]
— e.g. A vector did not need to be set to 0 on initialization as that is already it’s default state on creation [[BR]]
— e.g. Faster Framerate and Timing calculations by using less member variables that are not needed outsied of calling functions [[BR]]
- The SceneState now contains the SceneRenderState and is passed on to the SceneGraph’s update calls [[BR]]
- Better material export/import to/from XML format [[BR]]
- More bug fixes and cleanups [[BR]]