当前位置: 首页>>代码示例>>C++>>正文


C++ vec3::GetLength方法代码示例

本文整理汇总了C++中vec3::GetLength方法的典型用法代码示例。如果您正苦于以下问题:C++ vec3::GetLength方法的具体用法?C++ vec3::GetLength怎么用?C++ vec3::GetLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在vec3的用法示例。


在下文中一共展示了vec3::GetLength方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CreateExplosion

void ParticleRenderer::CreateExplosion(const vec3& position, float strength, const vec3& velocity, float falloff, float time, const vec3& start_fire_color, const vec3& fire_color,
	const vec3& start_smoke_color, const vec3& smoke_color, const vec3& sharpnel_color, int fires, int smokes, int sparks, int shrapnels) {
	ScopeLock lock(lock_);

	const float random_xy_end_speed = 1.0f;
	const float strength2 = (strength>1)? ::sqrt(strength) : strength*strength;
	const float particle_size = strength2*0.5f;
	const float speed = velocity.GetLength() * 0.01f;
	CreateBillboards(position,  7*strength2+ 1*speed,      velocity, Math::Lerp(velocity,gravity_*-0.2f,falloff), random_xy_end_speed, 5.3f/time, particle_size,      start_fire_color, fire_color, fires_, fires);
	CreateBillboards(position,  8*strength2+ 1*speed,      velocity, Math::Lerp(velocity,gravity_*+0.2f,falloff), random_xy_end_speed,    3/time, particle_size*2,    start_smoke_color, smoke_color, smokes_, smokes);
	CreateBillboards(position, 20*strength2+20*speed, 1.2f*velocity, Math::Lerp(velocity,gravity_*+0.8f,falloff), random_xy_end_speed, 4.5f/time, particle_size*0.4f, vec3(), vec3(), sparks_, sparks);
	CreateBillboards(position,  9*strength2+10*speed, 1.1f*velocity, Math::Lerp(velocity,gravity_*+1.1f,falloff), random_xy_end_speed, 1.1f/time, particle_size*0.5f, sharpnel_color, sharpnel_color, shrapnels_, shrapnels);

	const float min_spark_velocity2 = strength2*100;
	const vec3 cam_plane = renderer_->GetCameraTransformation().GetOrientation() * vec3(0,1,0);
	BillboardArray::reverse_iterator x = sparks_.rbegin();
	for (int y = 0; y < sparks; ++y, ++x) {
		x->velocity_ = x->velocity_.ProjectOntoPlane(cam_plane);
		float speed2 = x->velocity_.GetLengthSquared();
		if (speed2 < min_spark_velocity2) {
			x->velocity_.Mul(::sqrt(min_spark_velocity2/speed2));
		}
	}

	if (fires > 0) {
		const Billboard& fire = fires_.back();
		CreateTempLight(fire_color, strength, fire.position_, fire.velocity_, fire.target_velocity_, fire.time_factor_);
	}
}
开发者ID:highfestiva,项目名称:life,代码行数:29,代码来源:uiparticlerenderer.cpp

示例2: OnCollision

void Game::OnCollision(const vec3& force, const vec3& torque, const vec3& position,
	cure::ContextObject* object1, cure::ContextObject* object2,
	tbc::PhysicsManager::BodyID body1_id, tbc::PhysicsManager::BodyID body2_id) {
	(void)body2_id;
	collision_sound_manager_->OnCollision(force, torque, position, object1, object2, body1_id, 2000, false);

	const float _force = force.GetLength();
	if (object1 == ball_ && _force > 1.0f) {
		score_ += ::sqrt(_force) * 34;
	}
}
开发者ID:highfestiva,项目名称:life,代码行数:11,代码来源:game.cpp

示例3: OnForceApplied

void ServerMine::OnForceApplied(cure::ContextObject* other_object,
	tbc::PhysicsManager::BodyID own_body_id, tbc::PhysicsManager::BodyID other_body_id,
	const vec3& force, const vec3& torque,
	const vec3& position, const vec3& relative_velocity) {
	(void)other_object;
	(void)own_body_id;
	(void)other_body_id;
	(void)torque;
	(void)position;
	(void)relative_velocity;

	float _force = force.GetLength()/GetMass() * 0.002f;
	if (ticks_til_fully_activated_ == 0 ||
		(other_object->GetPhysics()->GetPhysicsType() == tbc::ChunkyPhysics::kDynamic &&
		!dynamic_cast<ServerMine*>(other_object))) {
		_force *= 10;
	}
	if (_force > 1) {
		cure::Health::Add(this, _force * -0.045f, true);
	}
}
开发者ID:highfestiva,项目名称:life,代码行数:21,代码来源:servermine.cpp

示例4: MoveRacket

bool Game::MoveRacket() {
	if (GetRacket() && GetRacket()->IsLoaded() &&
		GetBall() && GetBall()->IsLoaded()) {
		xform racket_transform;
		GameTicker::GetPhysicsManager(IsThreadSafe())->GetBodyTransform(
			GetRacket()->GetPhysics()->GetBoneGeometry(0)->GetBodyId(),
			racket_transform);
		vec3 racket_linear_velocity;
		GameTicker::GetPhysicsManager(IsThreadSafe())->GetBodyVelocity(
			GetRacket()->GetPhysics()->GetBoneGeometry(0)->GetBodyId(),
			racket_linear_velocity);
		vec3 racket_angular_velocity;
		GameTicker::GetPhysicsManager(IsThreadSafe())->GetBodyAngularVelocity(
			GetRacket()->GetPhysics()->GetBoneGeometry(0)->GetBodyId(),
			racket_angular_velocity);

		// Calculate where ball will be as it passes z = racket z.
		vec3 ball_position =
			GameTicker::GetPhysicsManager(IsThreadSafe())->GetBodyPosition(GetBall()->GetPhysics()->GetBoneGeometry(0)->GetBodyId());
		vec3 ball_velocity;
		GameTicker::GetPhysicsManager(IsThreadSafe())->GetBodyVelocity(
			GetBall()->GetPhysics()->GetBoneGeometry(0)->GetBodyId(),
			ball_velocity);
		if (ball_position.z < -2) {
			ball_position.Set(0, 0, 0.4f);
			GameTicker::GetPhysicsManager(IsThreadSafe())->SetBodyTransform(GetBall()->GetPhysics()->GetBoneGeometry(0)->GetBodyId(), xform(quat(), ball_position));
			ball_velocity.Set(0, 0, 2.0f);
			GameTicker::GetPhysicsManager(IsThreadSafe())->SetBodyVelocity(GetBall()->GetPhysics()->GetBoneGeometry(0)->GetBodyId(), ball_velocity);
			GameTicker::GetPhysicsManager(IsThreadSafe())->SetBodyAngularVelocity(GetBall()->GetPhysics()->GetBoneGeometry(0)->GetBodyId(), vec3());
			racket_transform.SetIdentity();
			GameTicker::GetPhysicsManager(IsThreadSafe())->SetBodyTransform(GetRacket()->GetPhysics()->GetBoneGeometry(0)->GetBodyId(), racket_transform);
			racket_linear_velocity.Set(0, 0, 0);
			GameTicker::GetPhysicsManager(IsThreadSafe())->SetBodyVelocity(GetRacket()->GetPhysics()->GetBoneGeometry(0)->GetBodyId(), racket_linear_velocity);
			racket_angular_velocity.Set(0, 0, 0);
			GameTicker::GetPhysicsManager(IsThreadSafe())->SetBodyAngularVelocity(GetRacket()->GetPhysics()->GetBoneGeometry(0)->GetBodyId(), racket_angular_velocity);
			return false;
		}
		vec3 home;
		const float h = ball_position.z - racket_transform.GetPosition().z;
		if (h > -0.5f) {
			home.Set(ball_position.x*0.8f, ball_position.y*0.8f, 0);
		}
		const float vup = ball_velocity.z;
		const float a = +9.82f / 2;
		const float b = -vup;
		const float c = +h;
		const float b2 = b*b;
		const float _4ac = 4*a*c;
		if (b2 < _4ac || _4ac < 0) {
			// Does not compute.
		} else {
			const float t = (-b + sqrt(b2 - _4ac)) / (2*a);
			if (t > 0) {
				home.x += ball_velocity.x * t;
				home.y += ball_velocity.y * t;
			}
		}
		// Set linear force.
		const vec3 direction_home = home - racket_transform.GetPosition();
		float f = direction_home.GetLength();
		f *= 50;
		f *= f;
		vec3 _force = direction_home * f;
		_force -= racket_linear_velocity * 10;
		float user_force_factor = ::fabs(racket_lift_factor_) * 1.7f;
		user_force_factor = std::min(1.0f, user_force_factor);
		const float racket_acceleration = 100.0f * racket_lift_factor_;
		const float zForce = Math::Lerp(_force.z, racket_acceleration, user_force_factor);
		_force.z = zForce;
		f = _force.GetLength();
		if (f > 100) {
			_force *= 100 / f;
		}
		//mLog.Infof("force = (%f, %f, %f"), lForce.x, lForce.y, lForce.z);
		GameTicker::GetPhysicsManager(IsThreadSafe())->AddForce(
			GetRacket()->GetPhysics()->GetBoneGeometry(0)->GetBodyId(),
			_force);

		// Set torque. Note that racket is "flat" along the XY-plane.
		//const float lTiltAngleFactor = 1.2f;
		//const float dx = direction_home.x * lTiltAngleFactor;
		//const float dy = direction_home.y * lTiltAngleFactor;
		//const float dx = -racket_transform.GetPosition().x * lTiltAngleFactor;
		//const float dy = -racket_transform.GetPosition().y * lTiltAngleFactor;
		racket_down_direction_.Normalize();
		const vec3 home_torque = vec3(::acos(racket_down_direction_.y), ::acos(racket_down_direction_.x), 0);
		vec3 racket_torque = racket_transform.GetOrientation() * vec3(0,0,1);
		racket_torque = vec3(::acos(racket_torque.y), ::acos(racket_torque.x), 0);
		vec3 angle_home = home_torque - racket_torque;
		angle_home.y = -angle_home.y;
		angle_home.z = 0;
		f = Math::Clamp(-ball_velocity.z, 0.0f, 4.0f) / 4.0f;
		f = Math::Lerp(0.8f, 0.3f, f);
		f = angle_home.GetLength() * f;
		f *= f;
		f = 1;
		vec3 _torque = angle_home * f;
		_torque -= racket_angular_velocity * 0.2f;
		//mLog.Infof("torque = (%f, %f, %f"), lTorque.x, lTorque.y, lTorque.z);
		GameTicker::GetPhysicsManager(IsThreadSafe())->AddTorque(
//.........这里部分代码省略.........
开发者ID:highfestiva,项目名称:life,代码行数:101,代码来源:game.cpp

示例5: EmitFromTag


//.........这里部分代码省略.........
		kFvDirectionX,
		kFvDirectionY,
		kFvDirectionZ,
		kFvDensity,
		kFvOpacity,
		kFvOvershootOpacity,
		kFvOvershootCutoffDot,
		kFvOvershootDistanceUpscale,
		kFvOvershootEngineFactorBase,
		kFvCount
	};
	if (tag.float_value_list_.size() != kFvCount ||
		tag.string_value_list_.size() != 0 ||
		tag.body_index_list_.size() != 0 ||
		tag.engine_index_list_.size() != 1 ||
		tag.mesh_index_list_.size() < 1) {
		log_.Errorf("The fire tag '%s' has the wrong # of parameters.", tag.tag_name_.c_str());
		deb_assert(false);
		return;
	}
	const int engine_index = tag.engine_index_list_[0];
	if (engine_index >= object->GetPhysics()->GetEngineCount()) {
		return;
	}
	const tbc::PhysicsEngine* engine = object->GetPhysics()->GetEngine(engine_index);
	const float throttle_up_speed = Math::GetIterateLerpTime(tag.float_value_list_[kFvOvershootEngineFactorBase]*0.5f, frame_time);
	const float throttle_down_speed = Math::GetIterateLerpTime(tag.float_value_list_[kFvOvershootEngineFactorBase], frame_time);
	const float engine_throttle = engine->GetLerpThrottle(throttle_up_speed, throttle_down_speed, true);
	const quat orientation = object->GetOrientation();
	vec3 _radius(tag.float_value_list_[kFvRadiusX], tag.float_value_list_[kFvRadiusY], tag.float_value_list_[kFvRadiusZ]);
	_radius.x *= Math::Lerp(1.0f, tag.float_value_list_[kFvScaleX], engine_throttle);
	_radius.y *= Math::Lerp(1.0f, tag.float_value_list_[kFvScaleY], engine_throttle);
	_radius.z *= Math::Lerp(1.0f, tag.float_value_list_[kFvScaleZ], engine_throttle);
	vec3 _position(tag.float_value_list_[kFvX], tag.float_value_list_[kFvY], tag.float_value_list_[kFvZ]);
	_position = orientation * _position;
	const vec3 _color(tag.float_value_list_[kFvEndR], tag.float_value_list_[kFvEndB], tag.float_value_list_[kFvEndB]);

	bool create_particle = false;
	const float density = tag.float_value_list_[kFvDensity];
	float exhaust_intensity;
	v_get(exhaust_intensity, =(float), UiCure::GetSettings(), kRtvarUi3DExhaustintensity, 1.0);
	interleave_timeout_ -= Math::Lerp(0.3f, 1.0f, engine_throttle) * exhaust_intensity * frame_time;
	if (interleave_timeout_ <= 0) {	// Release particle this frame?
		create_particle = true;
		interleave_timeout_ = 0.05f / density;
	} else {
		create_particle = false;
	}

	const float dx = tag.float_value_list_[kFvRadiusX];
	const float dy = tag.float_value_list_[kFvRadiusY];
	const float dz = tag.float_value_list_[kFvRadiusZ];
	const vec3 start_color(tag.float_value_list_[kFvStartR], tag.float_value_list_[kFvStartB], tag.float_value_list_[kFvStartB]);
	const float _opacity = tag.float_value_list_[kFvOpacity];
	const vec3 direction = orientation * vec3(tag.float_value_list_[kFvDirectionX], tag.float_value_list_[kFvDirectionY], tag.float_value_list_[kFvDirectionZ]);
	const vec3 velocity = direction + object->GetVelocity();
	uitbc::ParticleRenderer* particle_renderer = (uitbc::ParticleRenderer*)ui_manager_->GetRenderer()->GetDynamicRenderer("particle");
	const float particle_time = density;
	float particle_size;	// Pick second size.
	if (dx > dy && dy > dz) {
		particle_size = dy;
	} else if (dy > dx && dx > dz) {
		particle_size = dx;
	} else {
		particle_size = dz;
	}
	particle_size *= 0.2f;

	const float _distance_scale_factor = tag.float_value_list_[kFvOvershootDistanceUpscale];
	for (size_t y = 0; y < tag.mesh_index_list_.size(); ++y) {
		tbc::GeometryBase* mesh = object->GetMesh(tag.mesh_index_list_[y]);
		if (mesh) {
			int phys_index = -1;
			str mesh_name;
			xform transform;
			float mesh_scale;
			((uitbc::ChunkyClass*)object->GetClass())->GetMesh(tag.mesh_index_list_[y], phys_index, mesh_name, transform, mesh_scale);
			transform = mesh->GetBaseTransformation() * transform;
			vec3 mesh_pos = transform.GetPosition() + _position;

			const vec3 cam_distance = mesh_pos - ui_manager_->GetRenderer()->GetCameraTransformation().GetPosition();
			const float distance = cam_distance.GetLength();
			const vec3 cam_direction(cam_distance / distance);
			float overshoot_factor = -(cam_direction*direction);
			if (overshoot_factor > tag.float_value_list_[kFvOvershootCutoffDot]) {
				overshoot_factor = Math::Lerp(overshoot_factor*0.5f, overshoot_factor, engine_throttle);
				const float opacity = (overshoot_factor+0.6f) * tag.float_value_list_[kFvOvershootOpacity];
				DrawOvershoot(mesh_pos, _distance_scale_factor*distance, _radius, _color, opacity, cam_direction);
			}

			if (create_particle) {
				const float sx = Random::Normal(0.0f, dx*0.5f, -dx, +dx);
				const float sy = Random::Normal(0.0f, dy*0.5f, -dy, +dy);
				const float sz = Random::Normal(0.0f, dz*0.5f, -dz, +dz);
				mesh_pos += orientation * vec3(sx, sy, sz);
				particle_renderer->CreateGlow(particle_time, particle_size, start_color, _color, _opacity, mesh_pos, velocity);
			}
		}
	}
}
开发者ID:highfestiva,项目名称:life,代码行数:101,代码来源:uijetengineemitter.cpp

示例6: OnTick


//.........这里部分代码省略.........
			for (x = relevant_paths.begin(); x != relevant_paths.end(); ++x) {
				const float next_likeliness = total_likeliness + x->likeliness_;
				if (picked_likeliness >= total_likeliness && picked_likeliness <= next_likeliness) {
					active_path_ = x->path_index_;
					break;
				}
				total_likeliness = next_likeliness;
			}
			if (active_path_ < 0) {
				active_path_ = relevant_paths[Random::GetRandomNumber() % relevant_paths.size()].path_index_;
			}
			Spline* _path = game_->GetLevel()->QueryPath()->GetPath(active_path_);
			const float wanted_distance = aim_distance;
			float step = wanted_distance * _path->GetDistanceNormal();
			if (step + _path->GetCurrentInterpolationTime() > 1) {
				step = 1 - _path->GetCurrentInterpolationTime();
			}
			_path->StepInterpolation(step);
			// Fetch ending position.
			const float t = _path->GetCurrentInterpolationTime();
			_path->GotoAbsoluteTime(END_PATH_TIME);
			elevator_get_on_position_ = _path->GetValue();
			_path->GotoAbsoluteTime(t);

			log_.Headlinef("Picked path %i (%i pickable."), active_path_, relevant_paths.size());
			if (mode_ == kModeFindPathOffElevator) {
				SetMode(kModeGetOffElevator);
			} else {
				SetMode(kModeHeadingBackOnTrack);
			}
		} break;
		case kModeHeadingBackOnTrack: {
			if (mode_run_delta_frame_count%5 == 2) {
				const float velocity_scale_factor = std::min(1.0f, _velocity.GetLength() / 2.5f);
				Spline* _path = game_->GetLevel()->QueryPath()->GetPath(active_path_);
				const float current_time = _path->GetCurrentInterpolationTime();
				const float nearest_path_distance = GetClosestPathDistance(_position, active_path_, 0, 1);
				if (nearest_path_distance > 3.0f) {
					// First verify that we haven't ended up under path somehow. We do that by checking
					// steepness, since pure Z-distance may be big when going over ditches.
					const vec3 path_position = _path->GetValue();
					const float steepness = (path_position.z - _position.z) / nearest_path_distance;
					//log_.Infof("Checking steepness, nearest path distance is %.3f, steepness is %.3f.", nearest_path_distance, steepness);
					if (steepness > 0.6f) {
						log_.Infof("Searching for new, better path, we seem to have ended up under the path. Beneath a bridge perhaps? Nearest path is %.2f, steepness is %.2f.", nearest_path_distance, steepness);
						SetMode(kModeFindBestPath);
						return;
					}
				}
				_path->GotoAbsoluteTime(current_time);
				if (nearest_path_distance < SCALE_FACTOR * OFF_COURSE_DISTANCE * velocity_scale_factor) {
					// We were able to return to normal, keep on running.
					SetMode(kModeNormal);
					return;
				}
				/*else if (nearest_path_distance > SCALE_FACTOR * OFF_COURSE_DISTANCE * velocity_scale_factor * 5) {
					// We're far off, perhaps we fell down from a plateu.
					active_path_ = -1;
					SetMode(kModeFindBestPath);
					return;
				}*/
				else if (mode_run_time > 7.0f) {
					SetMode(kModeFindBestPath);
					return;
				}
			}
开发者ID:highfestiva,项目名称:life,代码行数:67,代码来源:vehicleai.cpp


注:本文中的vec3::GetLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。