コード例 #1
0
static int render_view3d_disprect(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D *rv3d, rcti *disprect)
{
	/* copied code from view3d_draw.c */
	rctf viewborder;
	int draw_border;
	
	if (rv3d->persp == RV3D_CAMOB)
		draw_border = (scene->r.mode & R_BORDER) != 0;
	else
		draw_border = (v3d->flag2 & V3D_RENDER_BORDER) != 0;

	if (draw_border) {
		if (rv3d->persp == RV3D_CAMOB) {
			ED_view3d_calc_camera_border(scene, ar, v3d, rv3d, &viewborder, false);
			
			disprect->xmin = viewborder.xmin + scene->r.border.xmin * BLI_rctf_size_x(&viewborder);
			disprect->ymin = viewborder.ymin + scene->r.border.ymin * BLI_rctf_size_y(&viewborder);
			disprect->xmax = viewborder.xmin + scene->r.border.xmax * BLI_rctf_size_x(&viewborder);
			disprect->ymax = viewborder.ymin + scene->r.border.ymax * BLI_rctf_size_y(&viewborder);
		}
		else {
			disprect->xmin = v3d->render_border.xmin * ar->winx;
			disprect->xmax = v3d->render_border.xmax * ar->winx;
			disprect->ymin = v3d->render_border.ymin * ar->winy;
			disprect->ymax = v3d->render_border.ymax * ar->winy;
		}
		
		return 1;
	}
	
	BLI_rcti_init(disprect, 0, 0, 0, 0);
	return 0;
}
コード例 #2
0
ファイル: gpencil_utils.c プロジェクト: Brachi/blender
/* Init handling for space-conversion function (from passed-in parameters) */
void gp_point_conversion_init(bContext *C, GP_SpaceConversion *r_gsc)
{
	ScrArea *sa = CTX_wm_area(C);
	ARegion *ar = CTX_wm_region(C);
	
	/* zero out the storage (just in case) */
	memset(r_gsc, 0, sizeof(GP_SpaceConversion));
	unit_m4(r_gsc->mat);
	
	/* store settings */
	r_gsc->sa = sa;
	r_gsc->ar = ar;
	r_gsc->v2d = &ar->v2d;
	
	/* init region-specific stuff */
	if (sa->spacetype == SPACE_VIEW3D) {
		wmWindow *win = CTX_wm_window(C);
		Scene *scene = CTX_data_scene(C);
		View3D *v3d = (View3D *)CTX_wm_space_data(C);
		RegionView3D *rv3d = ar->regiondata;
		
		/* init 3d depth buffers */
		view3d_operator_needs_opengl(C);
		
		view3d_region_operator_needs_opengl(win, ar);
		ED_view3d_autodist_init(scene, ar, v3d, 0);
		
		/* for camera view set the subrect */
		if (rv3d->persp == RV3D_CAMOB) {
			ED_view3d_calc_camera_border(scene, ar, v3d, rv3d, &r_gsc->subrect_data, true); /* no shift */
			r_gsc->subrect = &r_gsc->subrect_data;
		}
	}
}
コード例 #3
0
void draw_gpencil_view3d (Scene *scene, View3D *v3d, ARegion *ar, short only3d)
{
    bGPdata *gpd;
    int dflag = 0;
    rcti rect;
    RegionView3D *rv3d= ar->regiondata;

    /* check that we have grease-pencil stuff to draw */
    gpd= gpencil_data_get_active_v3d(scene); // XXX
    if (gpd == NULL) return;

    /* when rendering to the offscreen buffer we don't want to
     * deal with the camera border, otherwise map the coords to the camera border. */
    if ((rv3d->persp == RV3D_CAMOB) && !(G.f & G_RENDER_OGL)) {
        rctf rectf;
        ED_view3d_calc_camera_border(scene, ar, v3d, rv3d, &rectf, TRUE); /* no shift */
        BLI_copy_rcti_rctf(&rect, &rectf);
    }
    else {
        rect.xmin = 0;
        rect.ymin = 0;
        rect.xmax = ar->winx;
        rect.ymax = ar->winy;
    }

    /* draw it! */
    if (only3d) dflag |= (GP_DRAWDATA_ONLY3D|GP_DRAWDATA_NOSTATUS);

    gp_draw_data(gpd, rect.xmin, rect.ymin, rect.xmax, rect.ymax, CFRA, dflag);
}
コード例 #4
0
ファイル: view3d_fly.c プロジェクト: Ichthyostega/blender
static void drawFlyPixel(const struct bContext *UNUSED(C), ARegion *UNUSED(ar), void *arg)
{
	FlyInfo *fly = arg;
	rctf viewborder;
	int xoff, yoff;
	float x1, x2, y1, y2;

	if (fly->scene->camera) {
		ED_view3d_calc_camera_border(fly->scene, fly->ar, fly->v3d, fly->rv3d, &viewborder, false);
		xoff = viewborder.xmin;
		yoff = viewborder.ymin;
	}
	else {
		xoff = 0;
		yoff = 0;
	}

	/* draws 4 edge brackets that frame the safe area where the
	 * mouse can move during fly mode without spinning the view */

	x1 = xoff + 0.45f * fly->width;
	y1 = yoff + 0.45f * fly->height;
	x2 = xoff + 0.55f * fly->width;
	y2 = yoff + 0.55f * fly->height;

	UI_ThemeColor(TH_VIEW_OVERLAY);
	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();
}
コード例 #5
0
ファイル: drawgpencil.c プロジェクト: ChunHungLiu/blender
/* draw grease-pencil sketches to specified 3d-view assuming that matrices are already set correctly
 * Note: this gets called twice - first time with only3d=1 to draw 3d-strokes,
 * second time with only3d=0 for screen-aligned strokes */
void ED_gpencil_draw_view3d(wmWindowManager *wm, Scene *scene, View3D *v3d, ARegion *ar, bool only3d)
{
	bGPdata *gpd;
	int dflag = 0;
	RegionView3D *rv3d = ar->regiondata;
	int offsx,  offsy,  winx,  winy;
	
	/* check that we have grease-pencil stuff to draw */
	gpd = ED_gpencil_data_get_active_v3d(scene, v3d);
	if (gpd == NULL) return;
	
	/* when rendering to the offscreen buffer we don't want to
	 * deal with the camera border, otherwise map the coords to the camera border. */
	if ((rv3d->persp == RV3D_CAMOB) && !(G.f & G_RENDER_OGL)) {
		rctf rectf;
		ED_view3d_calc_camera_border(scene, ar, v3d, rv3d, &rectf, true); /* no shift */
		
		offsx = iroundf(rectf.xmin);
		offsy = iroundf(rectf.ymin);
		winx  = iroundf(rectf.xmax - rectf.xmin);
		winy  = iroundf(rectf.ymax - rectf.ymin);
	}
	else {
		offsx = 0;
		offsy = 0;
		winx  = ar->winx;
		winy  = ar->winy;
	}
	
	/* set flags */
	if (only3d) {
		/* 3D strokes/3D space:
		 * - only 3D space points
		 * - don't status text either (as it's the wrong space)
		 */
		dflag |= (GP_DRAWDATA_ONLY3D | GP_DRAWDATA_NOSTATUS);
	}
	
	if (v3d->flag2 & V3D_RENDER_OVERRIDE) {
		/* don't draw status text when "only render" flag is set */
		dflag |= GP_DRAWDATA_NOSTATUS;
	}
	
	if ((wm == NULL) || ED_screen_animation_playing(wm)) {
		/* don't show onionskins during animation playback/scrub (i.e. it obscures the poses)
		 * OpenGL Renders (i.e. final output), or depth buffer (i.e. not real strokes)
		 */
		dflag |= GP_DRAWDATA_NO_ONIONS;
	}
	
	/* draw it! */
	gp_draw_data_all(scene, gpd, offsx, offsy, winx, winy, CFRA, dflag, v3d->spacetype);
}
コード例 #6
0
ファイル: view3d_walk.c プロジェクト: dfelinto/blender
static void drawWalkPixel(const struct bContext *UNUSED(C), ARegion *ar, void *arg)
{
  /* draws an aim/cross in the center */
  WalkInfo *walk = arg;

  const int outter_length = 24;
  const int inner_length = 14;
  int xoff, yoff;
  rctf viewborder;

  if (ED_view3d_cameracontrol_object_get(walk->v3d_camera_control)) {
    ED_view3d_calc_camera_border(
        walk->scene, walk->depsgraph, ar, walk->v3d, walk->rv3d, &viewborder, false);
    xoff = viewborder.xmin + BLI_rctf_size_x(&viewborder) * 0.5f;
    yoff = viewborder.ymin + BLI_rctf_size_y(&viewborder) * 0.5f;
  }
  else {
    xoff = walk->ar->winx / 2;
    yoff = walk->ar->winy / 2;
  }

  GPUVertFormat *format = immVertexFormat();
  uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT);

  immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);

  immUniformThemeColor(TH_VIEW_OVERLAY);

  immBegin(GPU_PRIM_LINES, 8);

  /* North */
  immVertex2i(pos, xoff, yoff + inner_length);
  immVertex2i(pos, xoff, yoff + outter_length);

  /* East */
  immVertex2i(pos, xoff + inner_length, yoff);
  immVertex2i(pos, xoff + outter_length, yoff);

  /* South */
  immVertex2i(pos, xoff, yoff - inner_length);
  immVertex2i(pos, xoff, yoff - outter_length);

  /* West */
  immVertex2i(pos, xoff - inner_length, yoff);
  immVertex2i(pos, xoff - outter_length, yoff);

  immEnd();
  immUnbindProgram();
}
コード例 #7
0
static int gp_camera_view_subrect(bContext *C, rctf *subrect)
{
	View3D *v3d = CTX_wm_view3d(C);
	ARegion *ar = CTX_wm_region(C);
	
	if (v3d) {
		RegionView3D *rv3d = ar->regiondata;
		
		/* for camera view set the subrect */
		if (rv3d->persp == RV3D_CAMOB) {
			Scene *scene = CTX_data_scene(C);
			ED_view3d_calc_camera_border(scene, ar, v3d, rv3d, subrect, true); /* no shift */
			return 1;
		}
	}
	
	return 0;
}
コード例 #8
0
static void drawWalkPixel(const struct bContext *UNUSED(C), ARegion *ar, void *arg)
{
	/* draws an aim/cross in the center */
	WalkInfo *walk = arg;

	const int outter_length = 24;
	const int inner_length = 14;
	int xoff, yoff;
	rctf viewborder;

	if (walk->scene->camera) {
		ED_view3d_calc_camera_border(walk->scene, ar, walk->v3d, walk->rv3d, &viewborder, false);
		xoff = viewborder.xmin + BLI_rctf_size_x(&viewborder) * 0.5f;
		yoff = viewborder.ymin + BLI_rctf_size_y(&viewborder) * 0.5f;
	}
	else {
		xoff = walk->ar->winx / 2;
		yoff = walk->ar->winy / 2;
	}

	cpack(0);

	glBegin(GL_LINES);
	/* North */
	glVertex2i(xoff, yoff + inner_length);
	glVertex2i(xoff, yoff + outter_length);

	/* East */
	glVertex2i(xoff + inner_length, yoff);
	glVertex2i(xoff + outter_length, yoff);

	/* South */
	glVertex2i(xoff, yoff - inner_length);
	glVertex2i(xoff, yoff - outter_length);

	/* West */
	glVertex2i(xoff - inner_length, yoff);
	glVertex2i(xoff - outter_length, yoff);
	glEnd();
}
コード例 #9
0
ファイル: view3d_draw_legacy.c プロジェクト: dfelinto/blender
/* reads full rect, converts indices */
uint *ED_view3d_select_id_read(int xmin, int ymin, int xmax, int ymax, uint *r_buf_len)
{
  if (UNLIKELY((xmin > xmax) || (ymin > ymax))) {
    return NULL;
  }

  const rcti rect = {
      .xmin = xmin,
      .xmax = xmax + 1,
      .ymin = ymin,
      .ymax = ymax + 1,
  };

  uint buf_len;
  uint *buf = ED_view3d_select_id_read_rect(&rect, &buf_len);

  if (r_buf_len) {
    *r_buf_len = buf_len;
  }

  return buf;
}

/* ************************************************************* */

static void view3d_stereo_bgpic_setup(Scene *scene, View3D *v3d, Image *ima, ImageUser *iuser)
{
  if (BKE_image_is_stereo(ima)) {
    iuser->flag |= IMA_SHOW_STEREO;

    if ((scene->r.scemode & R_MULTIVIEW) == 0) {
      iuser->multiview_eye = STEREO_LEFT_ID;
    }
    else if (v3d->stereo3d_camera != STEREO_3D_ID) {
      /* show only left or right camera */
      iuser->multiview_eye = v3d->stereo3d_camera;
    }

    BKE_image_multiview_index(ima, iuser);
  }
  else {
    iuser->flag &= ~IMA_SHOW_STEREO;
  }
}

static void view3d_draw_bgpic(Scene *scene,
                              Depsgraph *depsgraph,
                              ARegion *ar,
                              View3D *v3d,
                              const bool do_foreground,
                              const bool do_camera_frame)
{
  RegionView3D *rv3d = ar->regiondata;
  int fg_flag = do_foreground ? CAM_BGIMG_FLAG_FOREGROUND : 0;
  if (v3d->camera == NULL || v3d->camera->type != OB_CAMERA) {
    return;
  }
  Camera *cam = v3d->camera->data;

  for (CameraBGImage *bgpic = cam->bg_images.first; bgpic; bgpic = bgpic->next) {
    if ((bgpic->flag & CAM_BGIMG_FLAG_FOREGROUND) != fg_flag) {
      continue;
    }

    {
      float image_aspect[2];
      float x1, y1, x2, y2, centx, centy;

      void *lock;

      Image *ima = NULL;

      /* disable individual images */
      if ((bgpic->flag & CAM_BGIMG_FLAG_DISABLED)) {
        continue;
      }

      ImBuf *ibuf = NULL;
      ImBuf *freeibuf = NULL;
      ImBuf *releaseibuf = NULL;
      if (bgpic->source == CAM_BGIMG_SOURCE_IMAGE) {
        ima = bgpic->ima;
        if (ima == NULL) {
          continue;
        }

        ImageUser iuser = bgpic->iuser;
        iuser.scene = scene; /* Needed for render results. */
        BKE_image_user_frame_calc(&iuser, (int)DEG_get_ctime(depsgraph));
        if (ima->source == IMA_SRC_SEQUENCE && !(iuser.flag & IMA_USER_FRAME_IN_RANGE)) {
          ibuf = NULL; /* frame is out of range, dont show */
        }
        else {
          view3d_stereo_bgpic_setup(scene, v3d, ima, &iuser);
          ibuf = BKE_image_acquire_ibuf(ima, &iuser, &lock);
          releaseibuf = ibuf;
        }

        image_aspect[0] = ima->aspx;
        image_aspect[1] = ima->aspy;
      }
      else if (bgpic->source == CAM_BGIMG_SOURCE_MOVIE) {
        /* TODO: skip drawing when out of frame range (as image sequences do above) */
        MovieClip *clip = NULL;

        if (bgpic->flag & CAM_BGIMG_FLAG_CAMERACLIP) {
          if (scene->camera) {
            clip = BKE_object_movieclip_get(scene, scene->camera, true);
          }
        }
        else {
          clip = bgpic->clip;
        }

        if (clip == NULL) {
          continue;
        }

        BKE_movieclip_user_set_frame(&bgpic->cuser, (int)DEG_get_ctime(depsgraph));
        ibuf = BKE_movieclip_get_ibuf(clip, &bgpic->cuser);

        image_aspect[0] = clip->aspx;
        image_aspect[1] = clip->aspy;

        /* working with ibuf from image and clip has got different workflow now.
         * ibuf acquired from clip is referenced by cache system and should
         * be dereferenced after usage. */
        freeibuf = ibuf;
      }
      else {
        /* perhaps when loading future files... */
        BLI_assert(0);
        copy_v2_fl(image_aspect, 1.0f);
      }

      if (ibuf == NULL) {
        continue;
      }

      if ((ibuf->rect == NULL && ibuf->rect_float == NULL) || ibuf->channels != 4) {
        /* invalid image format */
        if (freeibuf) {
          IMB_freeImBuf(freeibuf);
        }
        if (releaseibuf) {
          BKE_image_release_ibuf(ima, releaseibuf, lock);
        }

        continue;
      }

      if (ibuf->rect == NULL) {
        IMB_rect_from_float(ibuf);
      }

      BLI_assert(rv3d->persp == RV3D_CAMOB);
      {
        if (do_camera_frame) {
          rctf vb;
          ED_view3d_calc_camera_border(scene, depsgraph, ar, v3d, rv3d, &vb, false);
          x1 = vb.xmin;
          y1 = vb.ymin;
          x2 = vb.xmax;
          y2 = vb.ymax;
        }
        else {
          x1 = ar->winrct.xmin;
          y1 = ar->winrct.ymin;
          x2 = ar->winrct.xmax;
          y2 = ar->winrct.ymax;
        }

        /* apply offset last - camera offset is different to offset in blender units */
        /* so this has some sane way of working - this matches camera's shift _exactly_ */
        {
          const float max_dim = max_ff(x2 - x1, y2 - y1);
          const float xof_scale = bgpic->offset[0] * max_dim;
          const float yof_scale = bgpic->offset[1] * max_dim;

          x1 += xof_scale;
          y1 += yof_scale;
          x2 += xof_scale;
          y2 += yof_scale;
        }

        centx = (x1 + x2) * 0.5f;
        centy = (y1 + y2) * 0.5f;

        /* aspect correction */
        if (bgpic->flag & CAM_BGIMG_FLAG_CAMERA_ASPECT) {
          /* apply aspect from clip */
          const float w_src = ibuf->x * image_aspect[0];
          const float h_src = ibuf->y * image_aspect[1];

          /* destination aspect is already applied from the camera frame */
          const float w_dst = x1 - x2;
          const float h_dst = y1 - y2;

          const float asp_src = w_src / h_src;
          const float asp_dst = w_dst / h_dst;

          if (fabsf(asp_src - asp_dst) >= FLT_EPSILON) {
            if ((asp_src > asp_dst) == ((bgpic->flag & CAM_BGIMG_FLAG_CAMERA_CROP) != 0)) {
              /* fit X */
              const float div = asp_src / asp_dst;
              x1 = ((x1 - centx) * div) + centx;
              x2 = ((x2 - centx) * div) + centx;
            }
            else {
              /* fit Y */
              const float div = asp_dst / asp_src;
              y1 = ((y1 - centy) * div) + centy;
              y2 = ((y2 - centy) * div) + centy;
            }
          }
        }
      }

      /* complete clip? */
      rctf clip_rect;
      BLI_rctf_init(&clip_rect, x1, x2, y1, y2);
      if (bgpic->rotation) {
        BLI_rctf_rotate_expand(&clip_rect, &clip_rect, bgpic->rotation);
      }

      if (clip_rect.xmax < 0 || clip_rect.ymax < 0 || clip_rect.xmin > ar->winx ||
          clip_rect.ymin > ar->winy) {
        if (freeibuf) {
          IMB_freeImBuf(freeibuf);
        }
        if (releaseibuf) {
          BKE_image_release_ibuf(ima, releaseibuf, lock);
        }

        continue;
      }

      float zoomx = (x2 - x1) / ibuf->x;
      float zoomy = (y2 - y1) / ibuf->y;

      /* For some reason; zoom-levels down refuses to use GL_ALPHA_SCALE. */
      if (zoomx < 1.0f || zoomy < 1.0f) {
        float tzoom = min_ff(zoomx, zoomy);
        int mip = 0;

        if ((ibuf->userflags & IB_MIPMAP_INVALID) != 0) {
          IMB_remakemipmap(ibuf, 0);
          ibuf->userflags &= ~IB_MIPMAP_INVALID;
        }
        else if (ibuf->mipmap[0] == NULL) {
          IMB_makemipmap(ibuf, 0);
        }

        while (tzoom < 1.0f && mip < 8 && ibuf->mipmap[mip]) {
          tzoom *= 2.0f;
          zoomx *= 2.0f;
          zoomy *= 2.0f;
          mip++;
        }
        if (mip > 0) {
          ibuf = ibuf->mipmap[mip - 1];
        }
      }

      GPU_depth_test(!do_foreground);
      glDepthMask(GL_FALSE);

      GPU_blend(true);
      GPU_blend_set_func_separate(
          GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);

      GPU_matrix_push_projection();
      GPU_matrix_push();
      ED_region_pixelspace(ar);

      GPU_matrix_translate_2f(centx, centy);
      GPU_matrix_scale_1f(bgpic->scale);
      GPU_matrix_rotate_2d(RAD2DEGF(-bgpic->rotation));

      if (bgpic->flag & CAM_BGIMG_FLAG_FLIP_X) {
        zoomx *= -1.0f;
        x1 = x2;
      }
      if (bgpic->flag & CAM_BGIMG_FLAG_FLIP_Y) {
        zoomy *= -1.0f;
        y1 = y2;
      }

      float col[4] = {1.0f, 1.0f, 1.0f, bgpic->alpha};
      IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
      immDrawPixelsTex(&state,
                       x1 - centx,
                       y1 - centy,
                       ibuf->x,
                       ibuf->y,
                       GL_RGBA,
                       GL_UNSIGNED_BYTE,
                       GL_LINEAR,
                       ibuf->rect,
                       zoomx,
                       zoomy,
                       col);

      GPU_matrix_pop_projection();
      GPU_matrix_pop();

      GPU_blend(false);

      glDepthMask(GL_TRUE);
      GPU_depth_test(true);

      if (freeibuf) {
        IMB_freeImBuf(freeibuf);
      }
      if (releaseibuf) {
        BKE_image_release_ibuf(ima, releaseibuf, lock);
      }
    }
  }
}
コード例 #10
0
ファイル: view3d_view.c プロジェクト: greg100795/blender-git
static int game_engine_exec(bContext *C, wmOperator *op)
{
#ifdef WITH_GAMEENGINE
	Scene *startscene = CTX_data_scene(C);
	Main *bmain = CTX_data_main(C);
	ScrArea /* *sa, */ /* UNUSED */ *prevsa = CTX_wm_area(C);
	ARegion *ar, *prevar = CTX_wm_region(C);
	wmWindow *prevwin = CTX_wm_window(C);
	RegionView3D *rv3d;
	rcti cam_frame;

	(void)op; /* unused */
	
	/* bad context switch .. */
	if (!ED_view3d_context_activate(C))
		return OPERATOR_CANCELLED;
	
	/* redraw to hide any menus/popups, we don't go back to
	 * the window manager until after this operator exits */
	WM_redraw_windows(C);

	BLI_callback_exec(bmain, &startscene->id, BLI_CB_EVT_GAME_PRE);

	rv3d = CTX_wm_region_view3d(C);
	/* sa = CTX_wm_area(C); */ /* UNUSED */
	ar = CTX_wm_region(C);

	view3d_operator_needs_opengl(C);
	
	game_set_commmandline_options(&startscene->gm);

	if ((rv3d->persp == RV3D_CAMOB) &&
	    (startscene->gm.framing.type == SCE_GAMEFRAMING_BARS) &&
	    (startscene->gm.stereoflag != STEREO_DOME))
	{
		/* Letterbox */
		rctf cam_framef;
		ED_view3d_calc_camera_border(startscene, ar, CTX_wm_view3d(C), rv3d, &cam_framef, false);
		cam_frame.xmin = cam_framef.xmin + ar->winrct.xmin;
		cam_frame.xmax = cam_framef.xmax + ar->winrct.xmin;
		cam_frame.ymin = cam_framef.ymin + ar->winrct.ymin;
		cam_frame.ymax = cam_framef.ymax + ar->winrct.ymin;
		BLI_rcti_isect(&ar->winrct, &cam_frame, &cam_frame);
	}
	else {
		cam_frame.xmin = ar->winrct.xmin;
		cam_frame.xmax = ar->winrct.xmax;
		cam_frame.ymin = ar->winrct.ymin;
		cam_frame.ymax = ar->winrct.ymax;
	}


	SaveState(C, prevwin);

	StartKetsjiShell(C, ar, &cam_frame, 1);

	/* window wasnt closed while the BGE was running */
	if (BLI_findindex(&CTX_wm_manager(C)->windows, prevwin) == -1) {
		prevwin = NULL;
		CTX_wm_window_set(C, NULL);
	}
	
	ED_area_tag_redraw(CTX_wm_area(C));

	if (prevwin) {
		/* restore context, in case it changed in the meantime, for
		 * example by working in another window or closing it */
		CTX_wm_region_set(C, prevar);
		CTX_wm_window_set(C, prevwin);
		CTX_wm_area_set(C, prevsa);
	}

	RestoreState(C, prevwin);

	//XXX restore_all_scene_cfra(scene_cfra_store);
	BKE_scene_set_background(CTX_data_main(C), startscene);
	//XXX BKE_scene_update_for_newframe(bmain->eval_ctx, bmain, scene, scene->lay);

	BLI_callback_exec(bmain, &startscene->id, BLI_CB_EVT_GAME_POST);

	return OPERATOR_FINISHED;
#else
	(void)C; /* unused */
	BKE_report(op->reports, RPT_ERROR, "Game engine is disabled in this build");
	return OPERATOR_CANCELLED;
#endif
}
コード例 #11
0
ファイル: view3d_fly.c プロジェクト: Ichthyostega/blender
static bool initFlyInfo(bContext *C, FlyInfo *fly, wmOperator *op, const wmEvent *event)
{
	wmWindow *win = CTX_wm_window(C);
	rctf viewborder;

	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);

#ifdef NDOF_FLY_DEBUG
	puts("\n-- fly begin --");
#endif

	/* sanity check: for rare but possible case (if lib-linking the camera fails) */
	if ((fly->rv3d->persp == RV3D_CAMOB) && (fly->v3d->camera == NULL)) {
		fly->rv3d->persp = RV3D_PERSP;
	}

	if (fly->rv3d->persp == RV3D_CAMOB && ID_IS_LINKED(fly->v3d->camera)) {
		BKE_report(op->reports, RPT_ERROR, "Cannot fly a camera from an external library");
		return false;
	}

	if (ED_view3d_offset_lock_check(fly->v3d, fly->rv3d)) {
		BKE_report(op->reports, RPT_ERROR, "Cannot fly when the view offset is locked");
		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 = FLY_AXISLOCK_STATE_OFF;
	fly->zlock = FLY_AXISLOCK_STATE_OFF;
	fly->xlock_momentum = 0.0f;
	fly->zlock_momentum = 0.0f;
	fly->grid = 1.0f;
	fly->use_precision = false;
	fly->use_freelook = false;

#ifdef NDOF_FLY_DRAW_TOOMUCH
	fly->redraw = 1;
#endif
	zero_v3(fly->dvec_prev);

	fly->timer = WM_event_add_timer(CTX_wm_manager(C), win, TIMER, 0.01f);

	copy_v2_v2_int(fly->mval, event->mval);

#ifdef WITH_INPUT_NDOF
	fly->ndof = NULL;
#endif

	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;

	/* detect whether to start with Z locking */
	copy_v3_fl3(upvec, 1.0f, 0.0f, 0.0f);
	copy_m3_m4(mat, fly->rv3d->viewinv);
	mul_m3_v3(mat, upvec);
	if (fabsf(upvec[2]) < 0.1f) {
		fly->zlock = FLY_AXISLOCK_STATE_IDLE;
	}

	fly->v3d_camera_control = ED_view3d_cameracontrol_acquire(
	        fly->scene, fly->v3d, fly->rv3d,
	        (U.uiflag & USER_CAM_LOCK_NO_PARENT) == 0);

	/* calculate center */
	if (fly->scene->camera) {
		ED_view3d_calc_camera_border(fly->scene, fly->ar, fly->v3d, fly->rv3d, &viewborder, false);

		fly->width = BLI_rctf_size_x(&viewborder);
		fly->height = BLI_rctf_size_y(&viewborder);

		fly->center_mval[0] = viewborder.xmin + fly->width / 2;
		fly->center_mval[1] = viewborder.ymin + fly->height / 2;
	}
	else {
		fly->width = fly->ar->winx;
		fly->height = fly->ar->winy;

		fly->center_mval[0] = fly->width / 2;
		fly->center_mval[1] = fly->height / 2;
	}

	/* center the mouse, probably the UI mafia are against this but without its quite annoying */
	WM_cursor_warp(win, fly->ar->winrct.xmin + fly->center_mval[0], fly->ar->winrct.ymin + fly->center_mval[1]);

	fly_update_header(C, op, fly);
	return 1;
}
コード例 #12
0
static int game_engine_exec(bContext *C, wmOperator *op)
{
#ifdef WITH_GAMEENGINE
	Scene *startscene = CTX_data_scene(C);
	ScrArea *sa, *prevsa= CTX_wm_area(C);
	ARegion *ar, *prevar= CTX_wm_region(C);
	wmWindow *prevwin= CTX_wm_window(C);
	RegionView3D *rv3d;
	rcti cam_frame;

	(void)op; /* unused */
	
	// bad context switch ..
	if(!ED_view3d_context_activate(C))
		return OPERATOR_CANCELLED;
	
	rv3d= CTX_wm_region_view3d(C);
	sa= CTX_wm_area(C);
	ar= CTX_wm_region(C);

	view3d_operator_needs_opengl(C);
	
	game_set_commmandline_options(&startscene->gm);

	if(rv3d->persp==RV3D_CAMOB && startscene->gm.framing.type == SCE_GAMEFRAMING_BARS && startscene->gm.stereoflag != STEREO_DOME) { /* Letterbox */
		rctf cam_framef;
		ED_view3d_calc_camera_border(startscene, ar, CTX_wm_view3d(C), rv3d, &cam_framef, FALSE);
		cam_frame.xmin = cam_framef.xmin + ar->winrct.xmin;
		cam_frame.xmax = cam_framef.xmax + ar->winrct.xmin;
		cam_frame.ymin = cam_framef.ymin + ar->winrct.ymin;
		cam_frame.ymax = cam_framef.ymax + ar->winrct.ymin;
		BLI_isect_rcti(&ar->winrct, &cam_frame, &cam_frame);
	}
	else {
		cam_frame.xmin = ar->winrct.xmin;
		cam_frame.xmax = ar->winrct.xmax;
		cam_frame.ymin = ar->winrct.ymin;
		cam_frame.ymax = ar->winrct.ymax;
	}


	SaveState(C, prevwin);

	StartKetsjiShell(C, ar, &cam_frame, 1);

	/* window wasnt closed while the BGE was running */
	if(BLI_findindex(&CTX_wm_manager(C)->windows, prevwin) == -1) {
		prevwin= NULL;
		CTX_wm_window_set(C, NULL);
	}
	
	if(prevwin) {
		/* restore context, in case it changed in the meantime, for
		   example by working in another window or closing it */
		CTX_wm_region_set(C, prevar);
		CTX_wm_window_set(C, prevwin);
		CTX_wm_area_set(C, prevsa);
	}

	RestoreState(C, prevwin);

	//XXX restore_all_scene_cfra(scene_cfra_store);
	set_scene_bg(CTX_data_main(C), startscene);
	//XXX scene_update_for_newframe(bmain, scene, scene->lay);
	
	ED_area_tag_redraw(CTX_wm_area(C));

	return OPERATOR_FINISHED;
#else
	(void)C; /* unused */
	BKE_report(op->reports, RPT_ERROR, "Game engine is disabled in this build.");
	return OPERATOR_CANCELLED;
#endif
}