Beispiel #1
0
void DaoxWindow_CursorMoveCallback( GLFWwindow *window, double x, double y )
{
	int left = glfwGetMouseButton( window, GLFW_MOUSE_BUTTON_LEFT );
	int right = glfwGetMouseButton( window, GLFW_MOUSE_BUTTON_RIGHT );
	DaoxWindow *self = (DaoxWindow*) glfwGetWindowUserPointer( window );
	DaoxCanvas *canvas;
	DaoxScene *scene;

	if( self == NULL ) return;
	canvas = (DaoxCanvas*) DaoValue_CastCstruct( self->model, daox_type_canvas );
	scene = (DaoxScene*) DaoValue_CastCstruct( self->model, daox_type_scene );

	if( canvas ){
		if( left == GLFW_PRESS ){
			DaoxWindow_RotateCanvas( self, canvas, x, y );
		}else if( right == GLFW_PRESS ){
			DaoxWindow_MoveCanvas( self, canvas, x, y );
		}
	}else if( scene && self->renderer->camera ){
		DaoxCamera *camera = self->renderer->camera;
		DaoxVector3D pos = DaoxCamera_GetPosition( camera );
		float dist = DaoxVector3D_Dist( & pos, & camera->viewTarget );
		float delta = dist / 4;
		float dx = (x - self->cursorPosX) / self->width;
		float dy = (y - self->cursorPosY) / self->height;
		float dd = sqrt( dx*dx + dy*dy );
		if( dd < 0.1 ) DaoxCamera_MoveByXYZ( camera, delta * dx, delta * dy, 0 );
	}
	self->cursorPosX = x;
	self->cursorPosY = y;
}
static void CAM_MoveBy( DaoProcess *proc, DaoValue *p[], int N )
{
	DaoxCamera *self = (DaoxCamera*) p[0];
	float dx = p[1]->xFloat.value;
	float dy = p[2]->xFloat.value;
	float dz = p[3]->xFloat.value;
	DaoxCamera_MoveByXYZ( self, dx, dy, dz );
}
Beispiel #3
0
void DaoxCanvas_glutSpecialKeyboard( int key, int x, int y )
{
	if( daox_current_renderer ){
		DaoxCamera *camera = DaoxRenderer_GetCurrentCamera( daox_current_renderer );
		float dx = 0.0;
		float dy = 0.0;
		float dz = 0.0;
		float delta = 10*camera->nearPlane;
		switch( key ){
		case GLUT_KEY_UP    : dz = - delta; break;
		case GLUT_KEY_DOWN  : dz = + delta; break;
		case GLUT_KEY_LEFT  : dx = - delta; break;
		case GLUT_KEY_RIGHT : dx = + delta; break;
		}
		DaoxCamera_MoveByXYZ( camera, dx, dy, dz );
	}
	if( daox_current_canvas == NULL ) return;
	DaoCstruct_CallKeyboardMethod( (DaoCstruct*) daox_current_canvas, "OnKeyboard", key, x, y );
}
Beispiel #4
0
void DaoxWindow_KeyCallback( GLFWwindow *window, int key, int scode, int action, int mods )
{
	DaoxWindow *self = (DaoxWindow*) glfwGetWindowUserPointer( window );
	DaoxCanvas *canvas;
	DaoxScene *scene;

	if( self == NULL ) return;
	canvas = (DaoxCanvas*) DaoValue_CastCstruct( self->model, daox_type_canvas );
	scene = (DaoxScene*) DaoValue_CastCstruct( self->model, daox_type_scene );

	if( key == GLFW_KEY_ESCAPE && glfwGetKey( window, key ) == GLFW_RELEASE ){
		self->visible = 0;
		return;
	}
	if( canvas ){
		switch( key ){
		case GLFW_KEY_EQUAL :
			if( mods & GLFW_MOD_SHIFT ) DaoxCanvas_Zoom( canvas, 1 );
			break;
		case GLFW_KEY_MINUS :
			DaoxCanvas_Zoom( canvas, 0 );
			break;
		case GLFW_KEY_TAB :
			if( glfwGetKey( window, key ) == GLFW_PRESS ){
				self->painter->showMesh = ! self->painter->showMesh;
			}
			break;
		}
	}else if( scene && self->renderer->camera ){
		DaoxCamera *camera = self->renderer->camera;
		DaoxVector3D pos = DaoxCamera_GetPosition( camera );
		float dist = DaoxVector3D_Dist( & pos, & camera->viewTarget );
		float delta = dist / 8;
		float dx = 0.0;
		float dy = 0.0;
		float dz = 0.0;
		switch( key ){
		case GLFW_KEY_EQUAL :
			if( mods & GLFW_MOD_SHIFT ) DaoxCamera_Zoom( camera, 1 );
			break;
		case GLFW_KEY_MINUS :
			DaoxCamera_Zoom( camera, 0 );
			break;
		case GLFW_KEY_UP :
		case GLFW_KEY_DOWN :
		case GLFW_KEY_LEFT :
		case GLFW_KEY_RIGHT :
			switch( key ){
			case GLFW_KEY_UP    : dy = + delta; break;
			case GLFW_KEY_DOWN  : dy = - delta; break;
			case GLFW_KEY_LEFT  : dx = - delta; break;
			case GLFW_KEY_RIGHT : dx = + delta; break;
			}
			DaoxCamera_MoveByXYZ( camera, dx, dy, dz );
			break;
		case GLFW_KEY_TAB :
			if( glfwGetKey( window, key ) == GLFW_PRESS ){
				self->renderer->showMesh = ! self->renderer->showMesh;
				self->renderer->showAxis = ! self->renderer->showAxis;
			}
			break;
		}
	}
}