Esempio n. 1
0
void Node2D::move_y(float p_delta,bool p_scaled){

	Matrix32 t = get_transform();
	Vector2 m = t[1];
	if (!p_scaled)
		m.normalize();
	set_pos(t[2]+m*p_delta);
}
Esempio n. 2
0
Matrix32 CanvasItem::get_global_transform() const {


	if (global_invalid) {

		const CanvasItem *pi = get_parent_item();
		if (pi)
			global_transform = pi->get_global_transform() * get_transform();
		else
			global_transform = get_transform();

		global_invalid=false;
	}

	return global_transform;

}
Esempio n. 3
0
synfig::Rect
Warp::get_full_bounding_rect(Context context)const
{
//	return Rect::full_plane();

	Point src_tl=param_src_tl.get(Point());
	Point src_br=param_src_br.get(Point());
	bool clip=param_clip.get(bool());

	Rect under(context.get_full_bounding_rect());

	if(clip)
	{
		under&=Rect(src_tl,src_br);
	}

	return get_transform()->perform(under);

	/*
	Rect under(context.get_full_bounding_rect());
	Rect ret(Rect::zero());

	if(under.area()==HUGE_VAL)
		return Rect::full_plane();

	ret.expand(
		transform_backward(
			under.get_min()
		)
	);
	ret.expand(
		transform_backward(
			under.get_max()
		)
	);
	ret.expand(
		transform_backward(
			Vector(
				under.get_min()[0],
				under.get_max()[1]
			)
		)
	);
	ret.expand(
		transform_backward(
			Vector(
				under.get_max()[0],
				under.get_min()[1]
			)
		)
	);

	if(ret.area()==HUGE_VAL)
		return Rect::full_plane();

	return ret;
	*/
}
Esempio n. 4
0
void CollisionShape2D::_add_to_collision_object(Object *p_obj) {

	CollisionObject2D *co = p_obj->cast_to<CollisionObject2D>();
	ERR_FAIL_COND(!co);
	co->add_shape(shape,get_transform());
	if (trigger)
		co->set_shape_as_trigger(co->get_shape_count()-1,true);

}
Esempio n. 5
0
File: path.cpp Progetto: 3miu/godot
void PathFollow::_update_transform() {


	if (!path)
		return;

	Ref<Curve3D> c =path->get_curve();
	if (!c.is_valid())
		return;


	float o = offset;
	if (loop)
		o=Math::fposmod(o,c->get_baked_length());

	Vector3 pos = c->interpolate_baked(o,cubic);
	Transform t=get_transform();


	if (rotation_mode!=ROTATION_NONE) {

		Vector3 n = (c->interpolate_baked(o+lookahead,cubic)-pos).normalized();

		if (rotation_mode==ROTATION_Y) {

			n.y=0;
			n.normalize();
		}

		if (n.length()<CMP_EPSILON) {//nothing, use previous
			n=-t.get_basis().get_axis(2).normalized();
		}


		Vector3 up = Vector3(0,1,0);

		if (rotation_mode==ROTATION_XYZ) {

			float tilt = c->interpolate_baked_tilt(o);
			if (tilt!=0) {

				Matrix3 rot(-n,tilt); //remember.. lookat will be znegative.. znegative!! we abide by opengl clan.
				up=rot.xform(up);
			}
		}

		t.set_look_at(pos,pos+n,up);

	} else {

		t.origin=pos;
	}

	t.origin+=t.basis.get_axis(0)*h_offset + t.basis.get_axis(1)*v_offset;
	set_transform(t);

}
Esempio n. 6
0
static float blender_camera_focal_distance(BL::RenderEngine& b_engine,
                                           BL::Object& b_ob,
                                           BL::Camera& b_camera)
{
	BL::Object b_dof_object = b_camera.dof_object();

	if(!b_dof_object)
		return b_camera.dof_distance();
	
	/* for dof object, return distance along camera Z direction */
	BL::Array<float, 16> b_ob_matrix;
	b_engine.camera_model_matrix(b_ob, b_ob_matrix);
	Transform obmat = get_transform(b_ob_matrix);
	Transform dofmat = get_transform(b_dof_object.matrix_world());
	float3 view_dir = normalize(transform_get_column(&obmat, 2));
	float3 dof_dir = transform_get_column(&obmat, 3) - transform_get_column(&dofmat, 3);
	return fabsf(dot(view_dir, dof_dir));
}
Esempio n. 7
0
bool GeometryNode::is_picked(Viewer *viewer)
{
  viewer->pushMatrix();
  viewer->multMatrix(get_transform());
  toggle_selected(viewer->picker());
  viewer->popMatrix();

  return m_selected;
}
Esempio n. 8
0
void RemoteTransform::_update_remote() {

	if (!is_inside_tree())
		return;

	if (!cache)
		return;

	Spatial *n = Object::cast_to<Spatial>(ObjectDB::get_instance(cache));
	if (!n)
		return;

	if (!n->is_inside_tree())
		return;

	//todo make faster
	if (use_global_coordinates) {

		if (update_remote_position && update_remote_rotation && update_remote_scale) {
			n->set_global_transform(get_global_transform());
		} else {
			Transform n_trans = n->get_global_transform();
			Transform our_trans = get_global_transform();

			if (!update_remote_position)
				our_trans.set_origin(n_trans.get_origin());

			n->set_global_transform(our_trans);

			if (!update_remote_rotation)
				n->set_rotation(n_trans.basis.get_rotation());

			if (!update_remote_scale)
				n->set_scale(n_trans.basis.get_scale());
		}

	} else {
		if (update_remote_position && update_remote_rotation && update_remote_scale) {
			n->set_global_transform(get_global_transform());
		} else {
			Transform n_trans = n->get_transform();
			Transform our_trans = get_transform();

			if (!update_remote_position)
				our_trans.set_origin(n_trans.get_origin());

			n->set_transform(our_trans);

			if (!update_remote_rotation)
				n->set_rotation(n_trans.basis.get_rotation());

			if (!update_remote_scale)
				n->set_scale(n_trans.basis.get_scale());
		}
	}
}
Esempio n. 9
0
void CollisionShape::_notification(int p_what) {

	switch(p_what) {

		case NOTIFICATION_ENTER_TREE: {
			unparenting=false;
			can_update_body=get_tree()->is_editor_hint();
			set_notify_local_transform(!can_update_body);

			if (get_tree()->is_debugging_collisions_hint()) {
				_create_debug_shape();
			}

			//indicator_instance = VisualServer::get_singleton()->instance_create2(indicator,get_world()->get_scenario());
		} break;
		case NOTIFICATION_TRANSFORM_CHANGED: {
		//	VisualServer::get_singleton()->instance_set_transform(indicator_instance,get_global_transform());
			if (can_update_body && updating_body) {
				_update_body();
			}
		} break;
		case NOTIFICATION_EXIT_TREE: {
		/*	if (indicator_instance.is_valid()) {
				VisualServer::get_singleton()->free(indicator_instance);
				indicator_instance=RID();
			}*/
			can_update_body=false;
			set_notify_local_transform(false);
			if (debug_shape) {
				debug_shape->queue_delete();
				debug_shape=NULL;
			}
		} break;
		case NOTIFICATION_UNPARENTED: {
			unparenting=true;
			if (can_update_body && updating_body)
				_update_body();
		} break;
		case NOTIFICATION_PARENTED: {
			if (can_update_body && updating_body)
				_update_body();
		} break;
		case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {

			if (!can_update_body && update_shape_index>=0) {

				CollisionObject *co = get_parent()->cast_to<CollisionObject>();
				if (co) {
					co->set_shape_transform(update_shape_index,get_transform());
				}
			}

		} break;

	}
}
Esempio n. 10
0
static void blender_camera_from_view(BlenderCamera *bcam, BL::Scene b_scene, BL::SpaceView3D b_v3d, BL::RegionView3D b_rv3d, int width, int height, bool skip_panorama = false)
{
	/* 3d view parameters */
	bcam->nearclip = b_v3d.clip_start();
	bcam->farclip = b_v3d.clip_end();
	bcam->lens = b_v3d.lens();
	bcam->shuttertime = b_scene.render().motion_blur_shutter();

	if(b_rv3d.view_perspective() == BL::RegionView3D::view_perspective_CAMERA) {
		/* camera view */
		BL::Object b_ob = (b_v3d.lock_camera_and_layers())? b_scene.camera(): b_v3d.camera();

		if(b_ob) {
			blender_camera_from_object(bcam, b_ob, skip_panorama);

			if(!skip_panorama && bcam->type == CAMERA_PANORAMA) {
				/* in panorama camera view, we map viewplane to camera border */
				BoundBox2D view_box, cam_box;

				blender_camera_view_subset(b_scene, b_ob, b_v3d, b_rv3d, width, height,
					&view_box, &cam_box);

				bcam->pano_viewplane = view_box.make_relative_to(cam_box);
			}
			else {
				/* magic zoom formula */
				bcam->zoom = (float)b_rv3d.view_camera_zoom();
				bcam->zoom = (1.41421f + bcam->zoom/50.0f);
				bcam->zoom *= bcam->zoom;
				bcam->zoom = 2.0f/bcam->zoom;

				/* offset */
				bcam->offset = get_float2(b_rv3d.view_camera_offset());
			}
		}
	}
	else if(b_rv3d.view_perspective() == BL::RegionView3D::view_perspective_ORTHO) {
		/* orthographic view */
		bcam->farclip *= 0.5f;
		bcam->nearclip = -bcam->farclip;

		float sensor_size;
		if(bcam->sensor_fit == BlenderCamera::VERTICAL)
			sensor_size = bcam->sensor_height;
		else
			sensor_size = bcam->sensor_width;

		bcam->type = CAMERA_ORTHOGRAPHIC;
		bcam->ortho_scale = b_rv3d.view_distance() * sensor_size / b_v3d.lens();
	}

	bcam->zoom *= 2.0f;

	/* 3d view transform */
	bcam->matrix = transform_inverse(get_transform(b_rv3d.view_matrix()));
}
Esempio n. 11
0
static void
lower_load_sample_pos(lower_wpos_ytransform_state *state,
                      nir_intrinsic_instr *intr)
{
    nir_builder *b = &state->b;
    b->cursor = nir_after_instr(&intr->instr);

    nir_ssa_def *pos = &intr->dest.ssa;
    nir_ssa_def *scale = nir_channel(b, get_transform(state), 0);
    nir_ssa_def *neg_scale = nir_channel(b, get_transform(state), 2);
    /* Either y or 1-y for scale equal to 1 or -1 respectively. */
    nir_ssa_def *flipped_y =
        nir_fadd(b, nir_fmax(b, neg_scale, nir_imm_float(b, 0.0)),
                 nir_fmul(b, nir_channel(b, pos, 1), scale));
    nir_ssa_def *flipped_pos = nir_vec2(b, nir_channel(b, pos, 0), flipped_y);

    nir_ssa_def_rewrite_uses_after(&intr->dest.ssa, nir_src_for_ssa(flipped_pos),
                                   flipped_pos->parent_instr);
}
Esempio n. 12
0
void SceneNode::rotate(char axis, double angle)
{
  QMatrix4x4 m;

  if(axis == 'x') m.rotate(angle, 1.0, 0.0, 0.0);
  else if(axis == 'y') m.rotate(angle, 0.0, 1.0, 0.0); 
  else if(axis == 'z') m.rotate(angle, 0.0, 0.0, 1.0);

  set_transform(get_transform() * m);
}
Esempio n. 13
0
void SceneNode::walk_gl(Viewer* viewer, bool picking)
{
  // Push the transform on the matrix stack and walk the children
  viewer->pushMatrix();
  viewer->multMatrix(get_transform());
  for(auto child : m_children) {
    child->walk_gl(viewer, picking);
  }
  viewer->popMatrix();
}
void CameraController::update_camera_transform()
{
    if (Camera* camera = m_project.get_uncached_active_camera())
    {
        // Moving the camera kills camera motion blur.
        camera->transform_sequence().clear();

        // Set the scene camera orientation and position based on the controller.
        camera->transform_sequence().set_transform(0.0f, get_transform());
    }
}
Esempio n. 15
0
void BlenderSync::sync_camera(BL::RenderSettings& b_render,
                              BL::Object& b_override,
                              int width, int height,
                              const char *viewname)
{
	BlenderCamera bcam;
	blender_camera_init(&bcam, b_render);

	/* pixel aspect */
	bcam.pixelaspect.x = b_render.pixel_aspect_x();
	bcam.pixelaspect.y = b_render.pixel_aspect_y();
	bcam.shuttertime = b_render.motion_blur_shutter();

	BL::CurveMapping b_shutter_curve(b_render.motion_blur_shutter_curve());
	curvemapping_to_array(b_shutter_curve, bcam.shutter_curve, RAMP_TABLE_SIZE);

	PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
	bcam.motion_position =
	        (Camera::MotionPosition)get_enum(cscene,
	                                         "motion_blur_position",
	                                         Camera::MOTION_NUM_POSITIONS,
	                                         Camera::MOTION_POSITION_CENTER);
	bcam.rolling_shutter_type =
		(Camera::RollingShutterType)get_enum(cscene,
		                                     "rolling_shutter_type",
		                                     Camera::ROLLING_SHUTTER_NUM_TYPES,
		                                     Camera::ROLLING_SHUTTER_NONE);
	bcam.rolling_shutter_duration = RNA_float_get(&cscene, "rolling_shutter_duration");

	/* border */
	if(b_render.use_border()) {
		bcam.border.left = b_render.border_min_x();
		bcam.border.right = b_render.border_max_x();
		bcam.border.bottom = b_render.border_min_y();
		bcam.border.top = b_render.border_max_y();
	}

	/* camera object */
	BL::Object b_ob = b_scene.camera();

	if(b_override)
		b_ob = b_override;

	if(b_ob) {
		BL::Array<float, 16> b_ob_matrix;
		blender_camera_from_object(&bcam, b_engine, b_ob);
		b_engine.camera_model_matrix(b_ob, bcam.use_spherical_stereo, b_ob_matrix);
		bcam.matrix = get_transform(b_ob_matrix);
	}

	/* sync */
	Camera *cam = scene->camera;
	blender_camera_sync(cam, &bcam, width, height, viewname);
}
Esempio n. 16
0
void Body2DSW::_compute_area_gravity(const Area2DSW *p_area) {

	if (p_area->is_gravity_point()) {

		gravity += (p_area->get_transform().xform(p_area->get_gravity_vector()) - get_transform().get_origin()).normalized() * p_area->get_gravity();

	} else {
		gravity += p_area->get_gravity_vector() * p_area->get_gravity();
	}

}
Esempio n. 17
0
void Canvas::fill_ellipse(const Pointf &center, float radius_x, float radius_y, const Gradient &gradient)
{
	float max_radius = max(radius_x, radius_y);
	if (max_radius == 0)
		return;

	const Mat4f original_transform = get_transform();
	mult_transform(Mat4f::translate(center.x, center.y, 0));
	mult_transform(Mat4f::scale(radius_x / max_radius, radius_y / max_radius, 1.0f));
	fill_circle(Pointf(0, 0), max_radius, gradient);
	set_transform(original_transform);
}
Esempio n. 18
0
SkeletalPose& SkeletalPose::operator+=(SkeletalPose const& pose2) {
  for_each(pose2.transforms.cbegin(),
           pose2.transforms.cend(),
           [this](std::pair<std::string, BonePose> const & p) {
    if (contains(p.first)) {
      set_transform(p.first, get_transform(p.first) + p.second);
    } else {
      set_transform(p.first, p.second);
    }
  });
  return *this;
}
Esempio n. 19
0
	void Label::render(Compositor* compositor,
						Renderer* renderer,
						gui::render::CommandList& render_commands)
	{
		render_commands.add_rectangle(
			geometry[0],
			geometry[1],
			geometry[2],
			geometry[3],
			render::WhiteTexture,
			background_color
		);

		if (text.empty())
			return;

		const int32_t upper_bound = (LABEL_TOP_MARGIN - font_height);
		const int32_t lower_bound = (LABEL_TOP_MARGIN + size.height + font_height);

		// draw cache items
		float item_offset = 0.0f;
		for (const font_cache_entry& item : font_cache)
		{
			Rect current_rect;
			current_rect.origin = item.origin - scroll_offset;
			current_rect.size = size;

			// Don't draw text above the panel. This shouldn't overlap
			// by more than a single line -- clipping will take care of it.
			if (current_rect.origin.y < upper_bound)
				continue;

			// Don't draw text below the panel. This shouldn't overlap
			// by more than a single line -- clipping will take care of it.
			if ((current_rect.origin.y+item.height) > (lower_bound + item.height))
				break;

			current_rect.origin = transform_point(get_transform(0), current_rect.origin);

			render_commands.add_font(font_handle, &text[item.start], item.length, current_rect, foreground_color);
		}

		//const bool content_larger_than_bounds = content_bounds.height() > size.height;
		//if (content_larger_than_bounds)
		//{
		//	Point start(origin.x, origin.y + content_bounds.height());
		//	Point end(origin.x + size.width, origin.y + content_bounds.height());
		//	render_commands.add_line(start, end, gemini::Color::from_rgba(0, 255, 0, 255));
		//}

		render_children(compositor, renderer, render_commands);
	}
Esempio n. 20
0
void BlenderSync::sync_camera_motion(BL::RenderSettings& b_render,
                                     BL::Object& b_ob,
                                     int width, int height,
                                     float motion_time)
{
	if(!b_ob)
		return;

	Camera *cam = scene->camera;
	BL::Array<float, 16> b_ob_matrix;
	b_engine.camera_model_matrix(b_ob, b_ob_matrix);
	Transform tfm = get_transform(b_ob_matrix);
	tfm = blender_camera_matrix(tfm, cam->type, cam->panorama_type);

	if(tfm != cam->matrix) {
		VLOG(1) << "Camera " << b_ob.name() << " motion detected.";
		if(motion_time == -1.0f) {
			cam->motion.pre = tfm;
			cam->use_motion = true;
		}
		else if(motion_time == 1.0f) {
			cam->motion.post = tfm;
			cam->use_motion = true;
		}
	}

	if(cam->type == CAMERA_PERSPECTIVE) {
		BlenderCamera bcam;
		float aspectratio, sensor_size;
		blender_camera_init(&bcam, b_render);

		blender_camera_from_object(&bcam, b_engine, b_ob);
		blender_camera_viewplane(&bcam,
		                         width, height,
		                         NULL,
		                         &aspectratio,
		                         &sensor_size);
		/* TODO(sergey): De-duplicate calculation with camera sync. */
		float fov = 2.0f * atanf((0.5f * sensor_size) / bcam.lens / aspectratio);
		if(fov != cam->fov) {
			VLOG(1) << "Camera " << b_ob.name() << " FOV change detected.";
			if(motion_time == -1.0f) {
				cam->fov_pre = fov;
				cam->use_perspective_motion = true;
			}
			else if(motion_time == 1.0f) {
				cam->fov_post = fov;
				cam->use_perspective_motion = true;
			}
		}
	}
}
Esempio n. 21
0
void SkeletalPose::blend(SkeletalPose const& pose2, float blendFactor) {
  for_each(pose2.transforms.cbegin(),
           pose2.transforms.cend(),
           [this, &blendFactor](std::pair<std::string, BonePose> const & p) {
    if (contains(p.first)) {
      set_transform(p.first,
                    get_transform(p.first).blend(p.second, blendFactor));
    } else {
      set_transform(p.first, p.second);
    }
  });
  // *this = *this * (1 - blendFactor) + pose2 * blendFactor;
}
Esempio n. 22
0
static void create_subd_mesh(Scene *scene,
                             Mesh *mesh,
                             BL::Object& b_ob,
                             BL::Mesh& b_mesh,
                             const vector<Shader*>& used_shaders,
                             float dicing_rate,
                             int max_subdivisions)
{
	BL::SubsurfModifier subsurf_mod(b_ob.modifiers[b_ob.modifiers.length()-1]);
	bool subdivide_uvs = subsurf_mod.use_subsurf_uv();

	create_mesh(scene, mesh, b_mesh, used_shaders, true, subdivide_uvs);

	/* export creases */
	size_t num_creases = 0;
	BL::Mesh::edges_iterator e;

	for(b_mesh.edges.begin(e); e != b_mesh.edges.end(); ++e) {
		if(e->crease() != 0.0f) {
			num_creases++;
		}
	}

	mesh->subd_creases.resize(num_creases);

	Mesh::SubdEdgeCrease* crease = mesh->subd_creases.data();
	for(b_mesh.edges.begin(e); e != b_mesh.edges.end(); ++e) {
		if(e->crease() != 0.0f) {
			crease->v[0] = e->vertices()[0];
			crease->v[1] = e->vertices()[1];
			crease->crease = e->crease();

			crease++;
		}
	}

	/* set subd params */
	if(!mesh->subd_params) {
		mesh->subd_params = new SubdParams(mesh);
	}
	SubdParams& sdparams = *mesh->subd_params;

	PointerRNA cobj = RNA_pointer_get(&b_ob.ptr, "cycles");

	sdparams.dicing_rate = max(0.1f, RNA_float_get(&cobj, "dicing_rate") * dicing_rate);
	sdparams.max_level = max_subdivisions;

	scene->camera->update();
	sdparams.camera = scene->camera;
	sdparams.objecttoworld = get_transform(b_ob.matrix_world());
}
Esempio n. 23
0
void InterpolatedCamera::_notification(int p_what) {

	switch(p_what) {
		case NOTIFICATION_ENTER_SCENE: {

			if (get_scene()->is_editor_hint() && enabled)
				set_fixed_process(false);

		} break;
		case NOTIFICATION_PROCESS: {

			if (!enabled)
				break;
			if (has_node(target)) {

				Spatial *node = get_node(target)->cast_to<Spatial>();
				if (!node)
					break;

				float delta = speed*get_process_delta_time();
				Transform target_xform = node->get_global_transform();
				Transform local_transform = get_transform();
				local_transform = local_transform.interpolate_with(target_xform,delta);
				set_global_transform(local_transform);

				if (node->cast_to<Camera>()) {
					Camera *cam = node->cast_to<Camera>();
					if (cam->get_projection()==get_projection())  {

						float new_near = Math::lerp(get_znear(),cam->get_znear(),delta);
						float new_far = Math::lerp(get_zfar(),cam->get_zfar(),delta);

						if (cam->get_projection()==PROJECTION_ORTHOGONAL) {

							float size = Math::lerp(get_size(),cam->get_size(),delta);
							set_orthogonal(size,new_near,new_far);
						} else {

							float fov = Math::lerp(get_fov(),cam->get_fov(),delta);
							set_perspective(fov,new_near,new_far);
						}
					}
				}


			}

		} break;
	}
}
Esempio n. 24
0
/*

void CollisionShape::_update_indicator() {

	while (VisualServer::get_singleton()->mesh_get_surface_count(indicator))
		VisualServer::get_singleton()->mesh_remove_surface(indicator,0);

	if (shape.is_null())
		return;

	DVector<Vector3> points;
	DVector<Vector3> normals;

	VS::PrimitiveType pt = VS::PRIMITIVE_TRIANGLES;

	if (shape->cast_to<RayShape>()) {

		RayShape *rs = shape->cast_to<RayShape>();
		points.push_back(Vector3());
		points.push_back(Vector3(0,0,rs->get_length()));
		pt = VS::PRIMITIVE_LINES;
	} else if (shape->cast_to<SphereShape>()) {

//		VisualServer *vs=VisualServer::get_singleton();
		SphereShape *shapeptr=shape->cast_to<SphereShape>();


		Color col(0.4,1.0,1.0,0.5);

		int lats=6;
		int lons=12;
		float size=shapeptr->get_radius();


		for(int i = 1; i <= lats; i++) {
			double lat0 = Math_PI * (-0.5 + (double) (i - 1) / lats);
			double z0  = Math::sin(lat0);
			double zr0 =  Math::cos(lat0);

			double lat1 = Math_PI * (-0.5 + (double) i / lats);
			double z1 = Math::sin(lat1);
			double zr1 = Math::cos(lat1);

			for(int j = lons; j >= 1; j--) {

				double lng0 = 2 * Math_PI * (double) (j - 1) / lons;
				double x0 = Math::cos(lng0);
				double y0 = Math::sin(lng0);

				double lng1 = 2 * Math_PI * (double) (j) / lons;
				double x1 = Math::cos(lng1);
				double y1 = Math::sin(lng1);

				Vector3 v4=Vector3(x0 * zr0, z0, y0 *zr0)*size;
				Vector3 v3=Vector3(x0 * zr1, z1, y0 *zr1)*size;
				Vector3 v2=Vector3(x1 * zr1, z1, y1 *zr1)*size;
				Vector3 v1=Vector3(x1 * zr0, z0, y1 *zr0)*size;

				Vector<Vector3> line;
				line.push_back(v1);
				line.push_back(v2);
				line.push_back(v3);
				line.push_back(v4);


				points.push_back(v1);
				points.push_back(v2);
				points.push_back(v3);

				points.push_back(v1);
				points.push_back(v3);
				points.push_back(v4);

				normals.push_back(v1.normalized());
				normals.push_back(v2.normalized());
				normals.push_back(v3.normalized());

				normals.push_back(v1.normalized());
				normals.push_back(v3.normalized());
				normals.push_back(v4.normalized());

			}
		}
	} else if (shape->cast_to<BoxShape>()) {

		BoxShape *shapeptr=shape->cast_to<BoxShape>();

		for (int i=0;i<6;i++) {


			Vector3 face_points[4];


			for (int j=0;j<4;j++) {

				float v[3];
				v[0]=1.0;
				v[1]=1-2*((j>>1)&1);
				v[2]=v[1]*(1-2*(j&1));

				for (int k=0;k<3;k++) {

					if (i<3)
						face_points[j][(i+k)%3]=v[k]*(i>=3?-1:1);
					else
						face_points[3-j][(i+k)%3]=v[k]*(i>=3?-1:1);
				}
			}
			Vector3 normal;
			normal[i%3]=(i>=3?-1:1);

			for(int j=0;j<4;j++)
				face_points[j]*=shapeptr->get_extents();

			points.push_back(face_points[0]);
			points.push_back(face_points[1]);
			points.push_back(face_points[2]);

			points.push_back(face_points[0]);
			points.push_back(face_points[2]);
			points.push_back(face_points[3]);

			for(int n=0;n<6;n++)
				normals.push_back(normal);

		}

	} else if (shape->cast_to<ConvexPolygonShape>()) {

		ConvexPolygonShape *shapeptr=shape->cast_to<ConvexPolygonShape>();

		Geometry::MeshData md;
		QuickHull::build(Variant(shapeptr->get_points()),md);

		for(int i=0;i<md.faces.size();i++) {

			for(int j=2;j<md.faces[i].indices.size();j++) {
				points.push_back(md.vertices[md.faces[i].indices[0]]);
				points.push_back(md.vertices[md.faces[i].indices[j-1]]);
				points.push_back(md.vertices[md.faces[i].indices[j]]);
				normals.push_back(md.faces[i].plane.normal);
				normals.push_back(md.faces[i].plane.normal);
				normals.push_back(md.faces[i].plane.normal);
			}
		}
	} else if (shape->cast_to<ConcavePolygonShape>()) {

		ConcavePolygonShape *shapeptr=shape->cast_to<ConcavePolygonShape>();

		points = shapeptr->get_faces();
		for(int i=0;i<points.size()/3;i++) {

			Vector3 n = Plane( points[i*3+0],points[i*3+1],points[i*3+2] ).normal;
			normals.push_back(n);
			normals.push_back(n);
			normals.push_back(n);
		}

	} else if (shape->cast_to<CapsuleShape>()) {

		CapsuleShape *shapeptr=shape->cast_to<CapsuleShape>();

		DVector<Plane> planes = Geometry::build_capsule_planes(shapeptr->get_radius(), shapeptr->get_height()/2.0, 12, Vector3::AXIS_Z);
		Geometry::MeshData md = Geometry::build_convex_mesh(planes);

		for(int i=0;i<md.faces.size();i++) {

			for(int j=2;j<md.faces[i].indices.size();j++) {
				points.push_back(md.vertices[md.faces[i].indices[0]]);
				points.push_back(md.vertices[md.faces[i].indices[j-1]]);
				points.push_back(md.vertices[md.faces[i].indices[j]]);
				normals.push_back(md.faces[i].plane.normal);
				normals.push_back(md.faces[i].plane.normal);
				normals.push_back(md.faces[i].plane.normal);

			}
		}

	} else if (shape->cast_to<PlaneShape>()) {

		PlaneShape *shapeptr=shape->cast_to<PlaneShape>();

		Plane p = shapeptr->get_plane();
		Vector3 n1 = p.get_any_perpendicular_normal();
		Vector3 n2 = p.normal.cross(n1).normalized();

		Vector3 pface[4]={
			p.normal*p.d+n1*100.0+n2*100.0,
			p.normal*p.d+n1*100.0+n2*-100.0,
			p.normal*p.d+n1*-100.0+n2*-100.0,
			p.normal*p.d+n1*-100.0+n2*100.0,
		};

		points.push_back(pface[0]);
		points.push_back(pface[1]);
		points.push_back(pface[2]);

		points.push_back(pface[0]);
		points.push_back(pface[2]);
		points.push_back(pface[3]);

		normals.push_back(p.normal);
		normals.push_back(p.normal);
		normals.push_back(p.normal);
		normals.push_back(p.normal);
		normals.push_back(p.normal);
		normals.push_back(p.normal);

	}

	if (!points.size())
		return;
	RID material = VisualServer::get_singleton()->fixed_material_create();
	VisualServer::get_singleton()->fixed_material_set_param(material,VS::FIXED_MATERIAL_PARAM_DIFFUSE,Color(0,0.6,0.7,0.3));
	VisualServer::get_singleton()->fixed_material_set_param(material,VS::FIXED_MATERIAL_PARAM_EMISSION,0.7);
	if (normals.size()==0)
		VisualServer::get_singleton()->material_set_flag(material,VS::MATERIAL_FLAG_UNSHADED,true);
	VisualServer::get_singleton()->material_set_flag(material,VS::MATERIAL_FLAG_DOUBLE_SIDED,true);
	Array d;
	d.resize(VS::ARRAY_MAX);
	d[VS::ARRAY_VERTEX]=points;
	if (normals.size())
		d[VS::ARRAY_NORMAL]=normals;
	VisualServer::get_singleton()->mesh_add_surface(indicator,pt,d);
	VisualServer::get_singleton()->mesh_surface_set_material(indicator,0,material,true);

}

*/
void CollisionShape::_add_to_collision_object(Object* p_cshape) {

	if (unparenting)
		return;

	CollisionObject *co=p_cshape->cast_to<CollisionObject>();
	ERR_FAIL_COND(!co);

	if (shape.is_valid()) {

		co->add_shape(shape,get_transform());
        if (trigger)
            co->set_shape_as_trigger( co->get_shape_count() -1, true );
    }
}
Esempio n. 25
0
HitInfo SceneNode::intersects(Point3D origin, Vector3D dir) const {
  HitInfo info;
  origin = get_inverse() * origin;
  dir = get_inverse() * dir;
  for (ChildList::const_iterator it = m_children.begin(); it != m_children.end(); ++it) {
	HitInfo h = (*it)->intersects(origin, dir);
	for (unsigned int i = 0; i < h.hits.size(); i++) {
	  h.hits.at(i).intersection = get_transform() * h.hits.at(i).intersection;
	  h.hits.at(i).normal = get_inverse().transpose() * h.hits.at(i).normal;
	}
	for (unsigned int i = 0; i < h.lines.size(); i++) {
	  h.lines.at(i).first.intersection = get_transform() * 
	  	h.lines.at(i).first.intersection;
	  h.lines.at(i).second.intersection = get_transform() * 
	  	h.lines.at(i).second.intersection;	
	  h.lines.at(i).first.normal = get_inverse().transpose() * 
	  	h.lines.at(i).first.normal;
	  h.lines.at(i).second.normal = get_inverse().transpose() * 
	  	h.lines.at(i).second.normal;
	}
    info = HitInfo::merge_info(info, h);
  }
  return info;
}
Esempio n. 26
0
void VehicleWheel::_notification(int p_what) {

	if (p_what == NOTIFICATION_ENTER_TREE) {

		VehicleBody *cb = Object::cast_to<VehicleBody>(get_parent());
		if (!cb)
			return;
		body = cb;
		local_xform = get_transform();
		cb->wheels.push_back(this);

		m_chassisConnectionPointCS = get_transform().origin;
		m_wheelDirectionCS = -get_transform().basis.get_axis(Vector3::AXIS_Y).normalized();
		m_wheelAxleCS = get_transform().basis.get_axis(Vector3::AXIS_X).normalized();
	}
	if (p_what == NOTIFICATION_EXIT_TREE) {

		VehicleBody *cb = Object::cast_to<VehicleBody>(get_parent());
		if (!cb)
			return;
		cb->wheels.erase(this);
		body = NULL;
	}
}
Esempio n. 27
0
void BlenderSync::sync_camera_motion(BL::Object b_ob, int motion)
{
	Camera *cam = scene->camera;

	Transform tfm = get_transform(b_ob.matrix_world());
	tfm = blender_camera_matrix(tfm, cam->type);

	if(tfm != cam->matrix) {
		if(motion == -1)
			cam->motion.pre = tfm;
		else
			cam->motion.post = tfm;

		cam->use_motion = true;
	}
}
Esempio n. 28
0
/* Multiply interp_var_at_offset's offset by transform.x to flip it. */
static void
lower_interp_var_at_offset(lower_wpos_ytransform_state *state,
                           nir_intrinsic_instr *interp)
{
    nir_builder *b = &state->b;
    nir_ssa_def *offset;
    nir_ssa_def *flip_y;

    b->cursor = nir_before_instr(&interp->instr);

    offset = nir_ssa_for_src(b, interp->src[0], 2);
    flip_y = nir_fmul(b, nir_channel(b, offset, 1),
                      nir_channel(b, get_transform(state), 0));
    nir_instr_rewrite_src(&interp->instr, &interp->src[0],
                          nir_src_for_ssa(nir_vec2(b, nir_channel(b, offset, 0),
                                          flip_y)));
}
Esempio n. 29
0
Variant RigidBodyBullet::get_state(PhysicsServer::BodyState p_state) const {
	switch (p_state) {
		case PhysicsServer::BODY_STATE_TRANSFORM:
			return get_transform();
		case PhysicsServer::BODY_STATE_LINEAR_VELOCITY:
			return get_linear_velocity();
		case PhysicsServer::BODY_STATE_ANGULAR_VELOCITY:
			return get_angular_velocity();
		case PhysicsServer::BODY_STATE_SLEEPING:
			return !is_active();
		case PhysicsServer::BODY_STATE_CAN_SLEEP:
			return can_sleep;
		default:
			WARN_PRINTS("This state " + itos(p_state) + " is not supported by Bullet");
			return Variant();
	}
}
Esempio n. 30
0
/* turns 'fddy(p)' into 'fddy(fmul(p, transform.x))' */
static void
lower_fddy(lower_wpos_ytransform_state *state, nir_alu_instr *fddy)
{
    nir_builder *b = &state->b;
    nir_ssa_def *p, *pt, *trans;

    b->cursor = nir_before_instr(&fddy->instr);

    p = nir_ssa_for_alu_src(b, fddy, 0);
    trans = get_transform(state);
    pt = nir_fmul(b, p, nir_channel(b, trans, 0));

    nir_instr_rewrite_src(&fddy->instr,
                          &fddy->src[0].src,
                          nir_src_for_ssa(pt));

    for (unsigned i = 0; i < 4; i++)
        fddy->src[0].swizzle[i] = MIN2(i, pt->num_components - 1);
}