(五)flax Engine 游戏引擎——载具

news/2024/11/7 6:33:42/

2021SC@SDUSC        

上次我们讲述了flax Engine游戏引擎中的最基本的组成结构刚体和其源代码的分析。本次我将讲述flax Engine游戏引擎中的WheeledVehicle(载具)的相应的源代码的分析。 

        按照惯例本次我将针对flaxEngine 游戏引擎中的WheeledVehicle(载具)中的WheeledVehicle.h文件进行源代码的分析工作。

API_CLASS() class FLAXENGINE_API WheeledVehicle : public RigidBody

        首先WheeledVehicle 载具简而言之就汽车,这个WheeledVehicle是提供了汽车的一个模板提供给游戏的编制者,编制者用模板来制造属于自己的汽车。其基本思想是使用刚体制作其基本形状用碰撞器代表其地盘形状和车轮以此来模拟相应的碰撞情况。WheeledVehicle类的定义如上,继承了刚体的相应内容。

 API_ENUM() enum class DriveTypes{// Four-wheel drive. Any additional wheels are non-drivable. Optimized for 4-wheel cars.Drive4W,// N-wheel drive. Up to 20 drivable wheels. Suits generic wheels configurations.DriveNW,// Non-drivable vehicle.NoDrive,};
  API_ENUM() enum class DifferentialTypes{// Limited slip differential for car with 4 driven wheels.LimitedSlip4W,// Limited slip differential for car with front-wheel drive.LimitedSlipFrontDrive,// Limited slip differential for car with rear-wheel drive.LimitedSlipRearDrive,// Open differential for car with 4 driven wheels.Open4W,// Open differential for car with front-wheel drive.OpenFrontDrive,// Open differential for car with rear-wheel drive.OpenRearDrive,};

这个代码代表了编制者可能用到的载具的类型 

1:Drive4W:代表四轮驱动,并且针对四轮车进行优化。

2:N-wheel:针对不同一般车轮,最大可以使用20轮驱动。

3:NoDrive:不动车,也就是观赏车,针对游戏中场景车(不用其内部细节,简化编程)。

4:前轮驱动汽车的限滑差速器。

5:后轮驱动汽车的限滑差速器。

6:4个驱动轮汽车的开式差速器。

7:前轮驱动汽车的开式差速器。

8:后轮驱动汽车的开式差速器

  API_STRUCT() struct EngineSettings : ISerializable{DECLARE_SCRIPTING_TYPE_MINIMAL(EngineSettings);API_AUTO_SERIALIZATION();/// <summary>/// Moment of inertia of the engine around the axis of rotation. Specified in kilograms metres-squared (kg m^2)./// </summary>API_FIELD() float MOI = 1.0f;/// <summary>/// Maximum torque available to apply to the engine when the accelerator pedal is at maximum. Specified in kilograms metres-squared per second-squared (kg m^2 s^-2)./// </summary>API_FIELD() float MaxTorque = 500.0f;/// <summary>/// Maximum rotation speed of the engine (Revolutions Per Minute is the number of turns in one minute)./// </summary>API_FIELD() float MaxRotationSpeed = 6000.0f;};

        上面的代码段是针对汽车引擎的中“引擎”的源代码。

1:定义了发动机绕旋转轴的惯性矩。规定单位为千克平方米

2:定义了当油门踏板处于最大位置时,可应用于发动机的最大扭矩。规定单位为千克米平方/秒平方

3:定义了发动机的最大转速(每分钟转数是一分钟的转数)

 API_STRUCT() struct DifferentialSettings : ISerializable{DECLARE_SCRIPTING_TYPE_MINIMAL(DifferentialSettings);API_AUTO_SERIALIZATION();/// <summary>/// Type of differential./// </summary>API_FIELD() DifferentialTypes Type = DifferentialTypes::LimitedSlip4W;/// <summary>/// Ratio of torque split between front and rear (higher then 0.5 means more to front, smaller than 0.5 means more to rear). Only applied to LimitedSlip4W and Open4W./// </summary>API_FIELD(Attributes="Limit(0, 1)") float FrontRearSplit = 0.45f;/// <summary>/// Ratio of torque split between front-left and front-right (higher then 0.5 means more to front-left, smaller than 0.5 means more to front-right). Only applied to LimitedSlip4W and Open4W and LimitedSlipFrontDrive./// </summary>API_FIELD(Attributes="Limit(0, 1)") float FrontLeftRightSplit = 0.5f;/// <summary>/// Ratio of torque split between rear-left and rear-right (higher then 0.5 means more to rear-left, smaller than 0.5 means more to rear-right). Only applied to LimitedSlip4W and Open4W and LimitedSlipRearDrive./// </summary>API_FIELD(Attributes="Limit(0, 1)") float RearLeftRightSplit = 0.5f;/// <summary>/// Maximum allowed ratio of average front wheel rotation speed and rear wheel rotation speeds. The differential will divert more torque to the slower wheels when the bias is exceeded. Only applied to LimitedSlip4W./// </summary>API_FIELD(Attributes="Limit(1)") float CentreBias = 1.3f;/// <summary>/// Maximum allowed ratio of front-left and front-right wheel rotation speeds. The differential will divert more torque to the slower wheel when the bias is exceeded. Only applied to LimitedSlip4W and LimitedSlipFrontDrive./// </summary>API_FIELD(Attributes="Limit(1)") float FrontBias = 1.3f;/// <summary>/// Maximum allowed ratio of rear-left and rear-right wheel rotation speeds. The differential will divert more torque to the slower wheel when the bias is exceeded. Only applied to LimitedSlip4W and LimitedSlipRearDrive./// </summary>API_FIELD(Attributes="Limit(1)") float RearBias = 1.3f;};

上述代码代表车辆差速器设置

1:差速器的类型

2:前后扭矩分配比(大于0.5表示前向扭矩更大,小于0.5表示后向扭矩更大)。

3:左前和右前之间的扭矩分配比(大于0.5表示左前更大,小于0.5表示右前更大)。

4:左后和右后之间的扭矩分配比(大于0.5表示左后更大,小于0.5表示右后更大)。

5: 左前轮和右前轮转速的最大允许比率。当超过偏差时,差速器会将更多扭矩转移到较慢的车轮上。仅适用于受限SLIP4W和受限SLIPFRONT驱动器。

6:左后轮和右后轮转速的最大允许比率。当超过偏差时,差速器会将更多扭矩转移到较慢的车轮上。

 API_STRUCT() struct GearboxSettings : ISerializable{DECLARE_SCRIPTING_TYPE_MINIMAL(GearboxSettings);API_AUTO_SERIALIZATION();/// <summary>/// If enabled the vehicle gears will be changes automatically, otherwise it's fully manual./// </summary>API_FIELD() bool AutoGear = true;/// <summary>/// Time it takes to switch gear. Specified in seconds (s)./// </summary>API_FIELD(Attributes="Limit(0)") float SwitchTime = 0.5f;/// <summary>/// Strength of clutch. A stronger clutch more strongly couples the engine to the wheels, while a clutch of strength zero completely decouples the engine from the wheels./// Stronger clutches more quickly bring the wheels and engine into equilibrium, while weaker clutches take longer, resulting in periods of clutch slip and delays in power transmission from the engine to the wheels./// Specified in kilograms metres-squared per second (kg m^2 s^-1)./// </summary>API_FIELD(Attributes="Limit(0)") float ClutchStrength = 10.0f;};

上述代码是车辆变速器装置。

1:如果启用,车辆档位将自动改变,否则完全手动

2:切换档位所需的时间。以秒为单位指定

3:离合器的强度。更强的离合器更能将发动机与车轮紧密耦合,而强度为零的离合器则能将发动机与车轮完全分离。更强的离合器可以更快地使车轮和发动机达到平衡,而较弱的离合器需要更长的时间,从而导致离合器打滑以及发动机到车轮的动力传输延迟。

  API_ENUM() enum class WheelTypes{// Left wheel of the front axle.FrontLeft,// Right wheel of the front axle.FrontRight,// Left wheel of the rear axle.RearLeft,// Right wheel of the rear axle.RearRight,// Non-drivable wheel.NoDrive,};

上述代码是车轮类型:

分别代表 前桥的左轮,前桥的右车轮。后桥的左轮。后桥的右车轮。不可驱动车轮。

 API_STRUCT() struct Wheel : ISerializable{DECLARE_SCRIPTING_TYPE_MINIMAL(Wheel);API_AUTO_SERIALIZATION();/// <summary>/// Wheel placement type./// </summary>API_FIELD(Attributes="EditorOrder(0)") WheelTypes Type = WheelTypes::FrontLeft;/// <summary>/// Combined mass of the wheel and the tire in kg. Typically, a wheel has mass between 20Kg and 80Kg but can be lower and higher depending on the vehicle./// </summary>API_FIELD(Attributes="EditorOrder(1)") float Mass = 20.0f;/// <summary>

上述是轮胎类型代码:

在此我举例说明:首先是车轮和轮胎的组合质量(kg)。通常,一个车轮的质量介于20千克和80千克之间,但根据车辆的不同,可以更低或更高。其次是车轮中心和轮胎外缘之间的距离(米)

 API_STRUCT() struct WheelState{DECLARE_SCRIPTING_TYPE_MINIMAL(WheelState);/// <summary>/// True if suspension travel limits forbid the wheel from touching the drivable surface./// </summary>API_FIELD() bool IsInAir = false;/// <summary>/// The wheel is not in the air then it's set to the collider of the driving surface under the corresponding vehicle wheel./// </summary>API_FIELD() PhysicsColliderActor* TireContactCollider = nullptr;

上述代码车辆车轮动态模拟状态容器

1:如果悬架行程限制禁止车轮接触可行驶表面,则为真

2:车轮不在空中,然后将其设置到相应车轮下驾驶表面的碰撞器

3:车轮不在空中,然后将其设置为轮胎撞击的可行驶表面上的点

4:车轮不在空气中,然后在轮胎撞击的可驾驶表面上设置为正常

5:计算后轮胎类型和表面类型组合的轮胎所经历的摩擦力

6:关于“向上”矢量的车轮转向角(以度为单位),考虑输入转向和前束,以及阿克曼转向校正

7:指定车轮围绕滚动轴的旋转角度

本次分析的是flaxEngine游戏引擎中WheeledVehicle.h文件,下次我将分析WheeledVehicle.c文件。


http://www.ppmy.cn/news/569990.html

相关文章

什么是引擎

什么是引擎 前言 引擎这个词在编程中出现越来越多&#xff0c;比如游戏引擎&#xff0c;爬虫引擎&#xff0c;规则引擎。引擎这个最初在汽车里面代表发动机的词&#xff0c;到底是指什么意思&#xff0c;而引擎在不同编程的语境中具体又代表了什么&#xff0c;本文就是为了解…

游戏引擎Flax Engine源码分析(十一)渲染

2021SCSDUSC 一、概述 这篇博客继续分析2D渲染的后续内容。 二、分析 函数DrawBezier&#xff08;&#xff09;绘制贝塞尔曲线。参数&#xff1a;p1起点、p2第一个控制点、p3第二个控制点、终点、color线条颜色、thickness线条粗细。 static void DrawBezier(const Vector2&a…

Unreal Engine虚幻引擎 5

ref:http://next.poppur.com/Stylish/10596.html https://www.unrealengine.com/en-US/blog/a-first-look-at-unreal-engine-5 Author:Alex 发表时间2020-05-14 12:09:33 2012 年&#xff0c;Epic Games 首度展示了游戏引擎 Unreal Engine 4 的实机视频&#xff0c;该引擎强…

Rendering Engine 主流的浏览器内核(排版引擎、渲染引擎、解释引擎)有哪几种,分别的特点...

一、A web browser engine A rendering engine is software that draws text and images on the screen. The engine draws structured text from a document (often HTML), and formats it properly based on the given style declarations (often given in CSS). Examples of…

高层游戏引擎——基于OGRE所实现的高层游戏引擎框架

这是意念自己的毕业论文&#xff0c;在一个具体的实践之中&#xff0c;意念主要负责的是物件和GUI之外的其他游戏系统。意念才学疏陋&#xff0c;望众位前辈不吝赐教。由于代码质量不高、环境很难于配置、资源包过大等问题&#xff0c;意念暂先不提供代码和程序&#xff0c;未来…

著名游戏引擎及其开发游戏

著名游戏引擎及其开发游戏 Unreal 虚幻引擎&#xff08;Unreal Engine&#xff09;是一款由Epic Games开发的游戏引擎&#xff0c;多用于开发第一人称射击游戏&#xff0c;最新版本为虚幻引擎3。虚幻3引擎&#xff08;Unreal Engine 3&#xff09;又称虚幻引擎3&#xff0c;是…

虚幻引擎(1)-角色跳跃

文章目录 前言其他介绍下一篇笔记动态预览图蓝图预览 一、创建操作映射(绑定跳跃按键)[1]. 打开操作映射界面[2]. 添加操作映射 二、蓝图节点介绍[1]. 触发事件[2]. 跳跃[3]. 停止跳跃 三 、角色蓝图[1]. 创建角色蓝图类[2]. 角色蓝图类的编辑[3]. 添加组件[4]. 调整相机视角[5…

游戏引擎Flax Engine分析(八)渲染

2021SCSDUSC 一、简述 我们继续之前的博客分析2D渲染服务后续的内容。边学习边分析渲染流程。 二、分析 接下来一些服务主要提供对于变换矩阵、颜色等熟悉的操作&#xff0c;诸如入栈、弹出等&#xff0c;这里不再赘述。 我们先看一下在之前分析的结束渲染时进行的批处理元素的…