[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [32692] trunk/blender/source/blender/ editors/space_view3d/view3d_fly.c: missed adding the file when moving fly mode.

Campbell Barton ideasman42 at gmail.com
Mon Oct 25 09:09:38 CEST 2010


Revision: 32692
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=32692
Author:   campbellbarton
Date:     2010-10-25 09:09:38 +0200 (Mon, 25 Oct 2010)

Log Message:
-----------
missed adding the file when moving fly mode.

Added Paths:
-----------
    trunk/blender/source/blender/editors/space_view3d/view3d_fly.c

Added: trunk/blender/source/blender/editors/space_view3d/view3d_fly.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_fly.c	                        (rev 0)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_fly.c	2010-10-25 07:09:38 UTC (rev 32692)
@@ -0,0 +1,941 @@
+/**
+ * $Id: view3d_view.c 32630 2010-10-21 09:02:21Z campbellbarton $
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. 
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * 
+ * Contributor(s): Campbell Barton
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/* defines VIEW3D_OT_fly modal operator */
+
+#include "DNA_anim_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_object_types.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_math.h"
+#include "BLI_blenlib.h"
+
+#include "BKE_context.h"
+#include "BKE_object.h"
+#include "BKE_report.h"
+
+#include "BKE_depsgraph.h" /* for fly mode updating */
+
+#include "BIF_gl.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "ED_keyframing.h"
+#include "ED_screen.h"
+#include "ED_space_api.h"
+
+#include "PIL_time.h" /* smoothview */
+
+#include "view3d_intern.h"	// own include
+
+/* NOTE: these defines are saved in keymap files, do not change values but just add new ones */
+#define FLY_MODAL_CANCEL			1
+#define FLY_MODAL_CONFIRM			2
+#define FLY_MODAL_ACCELERATE 		3
+#define FLY_MODAL_DECELERATE		4
+#define FLY_MODAL_PAN_ENABLE		5
+#define FLY_MODAL_PAN_DISABLE		6
+#define FLY_MODAL_DIR_FORWARD		7
+#define FLY_MODAL_DIR_BACKWARD		8
+#define FLY_MODAL_DIR_LEFT			9
+#define FLY_MODAL_DIR_RIGHT			10
+#define FLY_MODAL_DIR_UP			11
+#define FLY_MODAL_DIR_DOWN			12
+#define FLY_MODAL_AXIS_LOCK_X		13
+#define FLY_MODAL_AXIS_LOCK_Z		14
+#define FLY_MODAL_PRECISION_ENABLE	15
+#define FLY_MODAL_PRECISION_DISABLE	16
+
+/* called in transform_ops.c, on each regeneration of keymaps  */
+void fly_modal_keymap(wmKeyConfig *keyconf)
+{
+	static EnumPropertyItem modal_items[] = {
+	{FLY_MODAL_CANCEL,	"CANCEL", 0, "Cancel", ""},
+	{FLY_MODAL_CONFIRM,	"CONFIRM", 0, "Confirm", ""},
+	{FLY_MODAL_ACCELERATE, "ACCELERATE", 0, "Accelerate", ""},
+	{FLY_MODAL_DECELERATE, "DECELERATE", 0, "Decelerate", ""},
+
+	{FLY_MODAL_PAN_ENABLE,	"PAN_ENABLE", 0, "Pan Enable", ""},
+	{FLY_MODAL_PAN_DISABLE,	"PAN_DISABLE", 0, "Pan Disable", ""},
+
+	{FLY_MODAL_DIR_FORWARD,	"FORWARD", 0, "Fly Forward", ""},
+	{FLY_MODAL_DIR_BACKWARD,"BACKWARD", 0, "Fly Backward", ""},
+	{FLY_MODAL_DIR_LEFT,	"LEFT", 0, "Fly Left", ""},
+	{FLY_MODAL_DIR_RIGHT,	"RIGHT", 0, "Fly Right", ""},
+	{FLY_MODAL_DIR_UP,		"UP", 0, "Fly Up", ""},
+	{FLY_MODAL_DIR_DOWN,	"DOWN", 0, "Fly Down", ""},
+
+	{FLY_MODAL_AXIS_LOCK_X,	"AXIS_LOCK_X", 0, "X Axis Correction", "X axis correction (toggle)"},
+	{FLY_MODAL_AXIS_LOCK_Z,	"AXIS_LOCK_Z", 0, "X Axis Correction", "Z axis correction (toggle)"},
+
+	{FLY_MODAL_PRECISION_ENABLE,	"PRECISION_ENABLE", 0, "Precision Enable", ""},
+	{FLY_MODAL_PRECISION_DISABLE,	"PRECISION_DISABLE", 0, "Precision Disable", ""},
+
+	{0, NULL, 0, NULL, NULL}};
+
+	wmKeyMap *keymap= WM_modalkeymap_get(keyconf, "View3D Fly Modal");
+
+	/* this function is called for each spacetype, only needs to add map once */
+	if(keymap) return;
+
+	keymap= WM_modalkeymap_add(keyconf, "View3D Fly Modal", modal_items);
+
+	/* items for modal map */
+	WM_modalkeymap_add_item(keymap, ESCKEY,    KM_PRESS, KM_ANY, 0, FLY_MODAL_CANCEL);
+	WM_modalkeymap_add_item(keymap, RIGHTMOUSE, KM_ANY, KM_ANY, 0, FLY_MODAL_CANCEL);
+
+	WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_ANY, KM_ANY, 0, FLY_MODAL_CONFIRM);
+	WM_modalkeymap_add_item(keymap, RETKEY, KM_PRESS, KM_ANY, 0, FLY_MODAL_CONFIRM);
+	WM_modalkeymap_add_item(keymap, SPACEKEY, KM_PRESS, KM_ANY, 0, FLY_MODAL_CONFIRM);
+	WM_modalkeymap_add_item(keymap, PADENTER, KM_PRESS, KM_ANY, 0, FLY_MODAL_CONFIRM);
+
+	WM_modalkeymap_add_item(keymap, PADPLUSKEY, KM_PRESS, 0, 0, FLY_MODAL_ACCELERATE);
+	WM_modalkeymap_add_item(keymap, PADMINUS, KM_PRESS, 0, 0, FLY_MODAL_DECELERATE);
+	WM_modalkeymap_add_item(keymap, WHEELUPMOUSE, KM_PRESS, 0, 0, FLY_MODAL_ACCELERATE);
+	WM_modalkeymap_add_item(keymap, WHEELDOWNMOUSE, KM_PRESS, 0, 0, FLY_MODAL_DECELERATE);
+
+	WM_modalkeymap_add_item(keymap, MIDDLEMOUSE, KM_PRESS, KM_ANY, 0, FLY_MODAL_PAN_ENABLE);
+	WM_modalkeymap_add_item(keymap, MIDDLEMOUSE, KM_RELEASE, KM_ANY, 0, FLY_MODAL_PAN_DISABLE); /* XXX - Bug in the event system, middle mouse release doesnt work */
+
+	/* WASD */
+	WM_modalkeymap_add_item(keymap, WKEY, KM_PRESS, 0, 0, FLY_MODAL_DIR_FORWARD);
+	WM_modalkeymap_add_item(keymap, SKEY, KM_PRESS, 0, 0, FLY_MODAL_DIR_BACKWARD);
+	WM_modalkeymap_add_item(keymap, AKEY, KM_PRESS, 0, 0, FLY_MODAL_DIR_LEFT);
+	WM_modalkeymap_add_item(keymap, DKEY, KM_PRESS, 0, 0, FLY_MODAL_DIR_RIGHT);
+	WM_modalkeymap_add_item(keymap, RKEY, KM_PRESS, 0, 0, FLY_MODAL_DIR_UP);
+	WM_modalkeymap_add_item(keymap, FKEY, KM_PRESS, 0, 0, FLY_MODAL_DIR_DOWN);
+
+	WM_modalkeymap_add_item(keymap, XKEY, KM_PRESS, 0, 0, FLY_MODAL_AXIS_LOCK_X);
+	WM_modalkeymap_add_item(keymap, ZKEY, KM_PRESS, 0, 0, FLY_MODAL_AXIS_LOCK_Z);
+
+	WM_modalkeymap_add_item(keymap, LEFTSHIFTKEY, KM_PRESS, KM_ANY, 0, FLY_MODAL_PRECISION_ENABLE);
+	WM_modalkeymap_add_item(keymap, LEFTSHIFTKEY, KM_RELEASE, KM_ANY, 0, FLY_MODAL_PRECISION_DISABLE);
+
+	/* assign map to operators */
+	WM_modalkeymap_assign(keymap, "VIEW3D_OT_fly");
+
+}
+
+typedef struct FlyInfo {
+	/* context stuff */
+	RegionView3D *rv3d;
+	View3D *v3d;
+	ARegion *ar;
+	Scene *scene;
+
+	wmTimer *timer; /* needed for redraws */
+
+	short state;
+	short use_precision;
+	short redraw;
+	short mval[2];
+
+	/* fly state state */
+	float speed; /* the speed the view is moving per redraw */
+	short axis; /* Axis index to move allong by default Z to move allong the view */
+	short pan_view; /* when true, pan the view instead of rotating */
+
+	/* relative view axis locking - xlock, zlock
+	0; disabled
+	1; enabled but not checking because mouse hasnt moved outside the margin since locking was checked an not needed
+	   when the mouse moves, locking is set to 2 so checks are done.
+	2; mouse moved and checking needed, if no view altering is donem its changed back to 1 */
+	short xlock, zlock;
+	float xlock_momentum, zlock_momentum; /* nicer dynamics */
+	float grid; /* world scale 1.0 default */
+
+	/* root most parent */
+	Object *root_parent;
+
+	/* backup values */
+	float dist_backup; /* backup the views distance since we use a zero dist for fly mode */
+	float ofs_backup[3]; /* backup the views offset incase the user cancels flying in non camera mode */
+	float rot_backup[4]; /* backup the views quat incase the user cancels flying in non camera mode. (quat for view, eul for camera) */
+	short persp_backup; /* remember if were ortho or not, only used for restoring the view if it was a ortho view */
+
+	void *obtfm; /* backup the objects transform */
+
+	/* compare between last state */
+	double time_lastwheel; /* used to accelerate when using the mousewheel a lot */
+	double time_lastdraw; /* time between draws */
+
+	void *draw_handle_pixel;
+
+	/* use for some lag */
+	float dvec_prev[3]; /* old for some lag */
+
+} FlyInfo;
+
+static void drawFlyPixel(const struct bContext *UNUSED(C), struct ARegion *UNUSED(ar), void *arg)
+{
+	FlyInfo *fly = arg;
+
+	/* draws 4 edge brackets that frame the safe area where the
+	mouse can move during fly mode without spinning the view */
+	float x1, x2, y1, y2;
+	
+	x1= 0.45*(float)fly->ar->winx;
+	y1= 0.45*(float)fly->ar->winy;
+	x2= 0.55*(float)fly->ar->winx;
+	y2= 0.55*(float)fly->ar->winy;
+	cpack(0);
+	
+	
+	glBegin(GL_LINES);
+	/* bottom left */
+	glVertex2f(x1,y1); 
+	glVertex2f(x1,y1+5);
+	
+	glVertex2f(x1,y1); 
+	glVertex2f(x1+5,y1);
+	
+	/* top right */
+	glVertex2f(x2,y2); 
+	glVertex2f(x2,y2-5);
+	
+	glVertex2f(x2,y2); 
+	glVertex2f(x2-5,y2);
+	
+	/* top left */
+	glVertex2f(x1,y2); 
+	glVertex2f(x1,y2-5);
+	
+	glVertex2f(x1,y2); 
+	glVertex2f(x1+5,y2);
+	
+	/* bottom right */
+	glVertex2f(x2,y1); 
+	glVertex2f(x2,y1+5);
+	
+	glVertex2f(x2,y1); 
+	glVertex2f(x2-5,y1);
+	glEnd();
+}
+
+/* FlyInfo->state */
+#define FLY_RUNNING		0
+#define FLY_CANCEL		1
+#define FLY_CONFIRM		2
+
+static int initFlyInfo (bContext *C, FlyInfo *fly, wmOperator *op, wmEvent *event)
+{
+	float upvec[3]; // tmp
+	float mat[3][3];
+
+	fly->rv3d= CTX_wm_region_view3d(C);
+	fly->v3d = CTX_wm_view3d(C);
+	fly->ar = CTX_wm_region(C);
+	fly->scene= CTX_data_scene(C);
+
+	if(fly->rv3d->persp==RV3D_CAMOB && fly->v3d->camera->id.lib) {
+		BKE_report(op->reports, RPT_ERROR, "Cannot fly a camera from an external library");
+		return FALSE;
+	}
+
+	if(fly->v3d->ob_centre) {
+		BKE_report(op->reports, RPT_ERROR, "Cannot fly when the view is locked to an object");
+		return FALSE;
+	}
+
+	if(fly->rv3d->persp==RV3D_CAMOB && fly->v3d->camera->constraints.first) {
+		BKE_report(op->reports, RPT_ERROR, "Cannot fly an object with constraints");
+		return FALSE;
+	}
+
+	fly->state= FLY_RUNNING;
+	fly->speed= 0.0f;
+	fly->axis= 2;
+	fly->pan_view= FALSE;
+	fly->xlock= FALSE;
+	fly->zlock= FALSE;
+	fly->xlock_momentum=0.0f;
+	fly->zlock_momentum=0.0f;
+	fly->grid= 1.0f;
+	fly->use_precision= 0;
+
+	fly->dvec_prev[0]= fly->dvec_prev[1]= fly->dvec_prev[2]= 0.0f;
+
+	fly->timer= WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, 0.01f);
+
+	fly->mval[0] = event->x - fly->ar->winrct.xmin;
+	fly->mval[1] = event->y - fly->ar->winrct.ymin;
+
+
+	fly->time_lastdraw= fly->time_lastwheel= PIL_check_seconds_timer();
+
+	fly->draw_handle_pixel = ED_region_draw_cb_activate(fly->ar->type, drawFlyPixel, fly, REGION_DRAW_POST_PIXEL);
+
+	fly->rv3d->rflag |= RV3D_NAVIGATING; /* so we draw the corner margins */
+
+	/* detect weather to start with Z locking */
+	upvec[0]=1.0f; upvec[1]=0.0f; upvec[2]=0.0f;
+	copy_m3_m4(mat, fly->rv3d->viewinv);

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list