This commit is contained in:
Никита Круглицкий 2025-05-10 19:21:51 +06:00
parent a81aa450dc
commit 9f19c7d618
23 changed files with 310 additions and 334 deletions

5
koptilnya/.idea/.gitignore generated vendored
View File

@ -1,5 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/

View File

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/temp" />
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
<excludeFolder url="file://$MODULE_DIR$/tmp" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/koptilnya.iml" filepath="$PROJECT_DIR$/.idea/koptilnya.iml" />
</modules>
</component>
</project>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

View File

@ -1,8 +1,8 @@
--@shared
--@name Audi A6 2012
--@author Opti1337, DarkSupah
-- @include /koptilnya/mesh_loader/builder.txt
require("/koptilnya/mesh_loader/builder.txt")
--@include /libs/meshbuilder.txt
local MeshBuilder = require("/libs/meshbuilder.txt")
DEBUG_MODE = true
@ -193,10 +193,5 @@ if SERVER then
builder:build("DashDials", Vector(0), Angle(0), SCALE, Colors.DashDials, Materials.DashDials, this, this)
local result = builder:getResult()
else
PERMA.onPermissionsGained = function()
builder = MeshBuilder:new(LINK)
end
PERMA.build()
builder:apply()
end

View File

@ -1,15 +1,16 @@
--@shared
--@name BMW 850CSi 96
--@author Opti1337, DarkSupah
-- @include /koptilnya/mesh_loader/builder.txt
--@include /libs/meshbuilder.txt
--@include koptilnya/libs/flux.txt
local flux = require("koptilnya/libs/flux.txt")
require("/koptilnya/mesh_loader/builder.txt")
local MeshBuilder = require("/libs/meshbuilder.txt")
DEBUG_MODE = true
local LINK = "http://82.179.248.158/bmw_850csi_96.obj#baaz"
local LINK = "https://raw.githubusercontent.com/koptilnya/gmod-data/main/bmw_850csi_96.obj"
local SCALE = Vector(1)
local Materials =
@ -129,7 +130,7 @@ if SERVER then
builder:build("headlightl_black_plastic", Vector(0), Angle(0), SCALE, Colors.BlackPlastic, Materials.BlackPlastic, headlightL, this)
builder:build("headlightl_chrome", Vector(0), Angle(0), SCALE, Colors.Chrome, Materials.Chrome, headlightL, this)
local result = builder:getResult()
local result = builder:apply()
local headlightl = {
angle = 0
@ -140,8 +141,8 @@ if SERVER then
}
function openHeadlights()
flux.to(headlightl, 1, { angle = 28 }):delay(0.3):ease("quartout")
flux.to(headlightr, 1, { angle = 28 }):ease("quartout")
flux.to(headlightl, 1, { angle = 2 }):delay(0.3):ease("quartout")
flux.to(headlightr, 1, { angle = -2 }):ease("quartout")
end
function closeHeadlights()
@ -165,9 +166,4 @@ if SERVER then
closeHeadlights()
end
end)
else
PERMA.onPermissionsGained = function()
builder = MeshBuilder:new(LINK)
end
PERMA.build()
end

View File

@ -1,8 +1,8 @@
--@shared
--@name BMW M4 G82 Competition
--@author Koptilnya1337
-- @include /koptilnya/mesh_loader/builder.txt
require("/koptilnya/mesh_loader/builder.txt")
--@include /libs/meshbuilder.txt
local MeshBuilder = require("/libs/meshbuilder.txt")
DEBUG_MODE = true
@ -36,10 +36,5 @@ if SERVER then
builder:build("Trunk", Vector(0), Angle(0), SCALE, Colors.Body, Materials.Body, this, this)
builder:build("Roof", Vector(0), Angle(0), SCALE, Colors.Carbon, Materials.Carbon, this, this)
local result = builder:getResult()
else
PERMA.onPermissionsGained = function()
builder = MeshBuilder:new(LINK)
end
PERMA.build()
builder:apply()
end

View File

@ -1,10 +1,8 @@
--@shared
--@name Ford Mustang GT 2015
--@author Opti1337, DarkSupah
-- @include /koptilnya/mesh_loader/builder.txt
-- @include /koptilnya/car_systems/lights_controller.txt
require("/koptilnya/mesh_loader/builder.txt")
require("/koptilnya/car_systems/lights_controller.txt")
--@include /libs/meshbuilder.txt
local MeshBuilder = require("/libs/meshbuilder.txt")
DEBUG_MODE = true
@ -50,8 +48,10 @@ local COLORS = {
local builder = {}
local lightsController = {}
if SERVER then
builder = MeshBuilder:new(LINK)
if SERVER then
builder.onObjectParsed = function(builder, objectsNames)
printTable(objectsNames)
end
@ -91,52 +91,5 @@ if SERVER then
local HighBeamLights = builder:build("HighBeamLights_body1_model0.017", Vector(0), Angle(0), SCALE, COLORS.LightsBase, MATERIALS.LightsBase, chip(), chip())
local FogLights = builder:build("FogLights_body1_model0.018", Vector(0), Angle(0), SCALE, COLORS.LightsBase, MATERIALS.LightsBase, chip(), chip())
local result = builder:getResult()
local lights = {
StopLights = {Entities = {LeftStopLight1, LeftStopLight2, LeftStopLight3, RightStopLight1, RightStopLight2, RightStopLight3}, LerpSpeed = 0.2, Colors = {On = Color(250, 0, 0), Off = Color(30, 0, 0), Active = Color(90, 0, 0)}},
ReverseLights = {Entities = {ReverseLights}, LerpSpeed = 0.1, Colors = {On = Color(255, 255, 255), Off = Color(20, 20, 20)}},
LowBeamLights = {Entities = {LowBeamLights}, LerpSpeed = 0.1, Colors = {On = Color(255, 255, 255), Off = Color(20, 20, 20)}},
HighBeamLights = {Entities = {HighBeamLights}, LerpSpeed = 0.1, Colors = {On = Color(255, 255, 255), Off = Color(20, 20, 20)}},
FogLights = {Entities = {FogLights}, LerpSpeed = 0.1, Colors = {On = Color(255, 255, 255), Off = Color(20, 20, 20)}}
TurnLights = {LeftEntities = {LeftStopLight1, LeftStopLight2, LeftStopLight3}, RightEntities = {RightStopLight1, RightStopLight2, RightStopLight3}, LerpSpeed = 0.2, Colors = {On = Color(250, 120, 0), Off = Color(30, 0, 0)}}
}
-- local lightsEntities = {StopLights = {StopLights}, ReverseLights = {ReverseLights}, LowBeamLights = {LowBeamLights}, HighBeamLights = {HighBeamLights}}
-- local lightColors = {StopLights = {On = Color(250, 0, 0), Off = Color(30, 0, 0), Active = Color(90, 0, 0)}, ReverseLights = {On = Color(255, 255, 255), Off = Color(20, 20, 20), Active = Color(20, 20, 20)}}
-- local lights = {Lights = lightsEntities, Colors = lightColors}
lightsController = LightsController:new(lights)
wire.adjustPorts({LightInputs = "table"}, {})
hook.add("think", "lights", function()
lightsController:useStopLights(wire.ports.LightInputs.Stop)
lightsController:useReverseLights(wire.ports.LightInputs.Reverse)
lightsController:useLowBeam(wire.ports.LightInputs.LowBeam)
lightsController:useHighBeam(wire.ports.LightInputs.HighBeam)
lightsController:setActive(wire.ports.LightInputs.LowBeam == 1)
lightsController:update()
end
)
else
function init()
builder = MeshBuilder:new(LINK)
end
if hasPermission("http.get") and hasPermission("mesh") and hasPermission("entities.setRenderProperty", chip()) then
init()
else
setupPermissionRequest({"http.get", "mesh", "entities.setRenderProperty"}, "", true)
hook.add("permissionrequest", "_permissionrequest", function()
if permissionRequestSatisfied() then
init()
end
end
)
end
builder:apply()
end

View File

@ -1,8 +1,8 @@
--@shared
--@name Ford F-150 Raptor
--@author Opti1337, .hemp
-- @include /koptilnya/mesh_loader/builder.txt
require("/koptilnya/mesh_loader/builder.txt")
--@include /libs/meshbuilder.txt
local MeshBuilder = require("/libs/meshbuilder.txt")
DEBUG_MODE = true
@ -50,10 +50,5 @@ if SERVER then
builder:build("Railing", Vector(0), Angle(0), SCALE, Color(255, 255, 255), "sprops/trans/wheels/wheel_d_rim1", chip(), chip())
local result = builder:getResult()
else
PERMA.onPermissionsGained = function()
builder = MeshBuilder:new(LINK)
end
PERMA.build()
builder:apply()
end

View File

@ -1,9 +1,8 @@
--@shared
--@name JDM Wheels
--@author Opti1337, .hemp
-- @include /koptilnya/mesh_loader/builder.txt
require("/koptilnya/mesh_loader/builder.txt")
--@include /libs/meshbuilder.txt
local MeshBuilder = require("/libs/meshbuilder.txt")
local LINK = "https://raw.githubusercontent.com/koptilnya/gmod-data/main/jdmwheel1.obj?d=1"
local SCALE = Vector(0.6)
@ -63,12 +62,7 @@ if SERVER then
}, wheel, wheel)
end
builder:getResult()
builder:apply()
end
end)
else
PERMA.onPermissionsGained = function()
builder = MeshBuilder:new(LINK)
end
PERMA.build()
end

View File

@ -1,8 +1,8 @@
--@shared
--@name Porsche 911 Turbo S 2017
--@author Opti1337, DarkSupah
-- @include /koptilnya/mesh_loader/builder.txt
require("/koptilnya/mesh_loader/builder.txt")
--@include /libs/meshbuilder.txt
local MeshBuilder = require("/libs/meshbuilder.txt")
DEBUG_MODE = true
@ -11,21 +11,80 @@ local SCALE = Vector(0.9)
local builder = {}
local objectNames = {"Gear_stick_handle",
"Locks",
"Left_door_panel",
"Seat_base",
"Torpedo",
"Front_bumper_details",
"Dashboard_interior",
"Right_door_body",
"Body",
"Seatbelts",
"Seatbelts_caps",
"Dials",
"Dashboard_panel",
"Lower_dashboard",
"Rear_mirror",
"Dials_base",
"Front_lights_glass",
"Rear_logo",
"Exhaust_pipes",
"Torpedo_panel",
"Seats",
"Dials_glass",
"Gear_stick_base",
"Bonnet",
"Rear_lights_base",
"Torpedo_buttons",
"Seat_controls",
"Carpets",
"Steering_wheel",
"Interior_base",
"Front_bumper",
"Front_lights_bulbs",
"Doors_rubbers",
"Bottom",
"Seatbelts_caps_plastic",
"Windows_lines",
"Exterior_plastic",
"Front_lights_strips",
"Gear_stick_details",
"Exhaust_collector",
"Left_door_mirror",
"Dashboard_vents",
"Dashboard_plastic",
"Seatbelts_locks",
"Right_door_panel",
"Left_door_body",
"Right_door_mirror",
"Rear_lights_glass",
"Stitches",
"Right_front_turn",
"Timer",
"Front_lights_borders",
"Front_indicators_glass",
"Door_frames",
"Front_lights_base",
"Left_front_turn",
"Rear_details",
"Rear_spoiler_glass",
"Clothes_hooks",
"Exhaust_bumper",
"Left_side_indicator",
"Dashboard",
"Door_plastic",
"Rear_bumper",
"Seats_plastic",
"Right_side_indicator",
"Steering_wheel_details"}
if SERVER then
builder = MeshBuilder:new(LINK)
builder.onObjectParsed = function(builder, objectsNames)
timer.simple(3, function()
for k, v in pairs(objectsNames) do
for k, v in pairs(objectNames) do
builder:build(v, Vector(0), Angle(0), SCALE, Color(360 / #objectsNames * k, 1, 1):hsvToRGB(), "models/debug/debugwhite", chip(), chip())
builder:build(v, Vector(0), Angle(0), SCALE, Color(360 / #objectNames * k, 1, 1):hsvToRGB(), "models/debug/debugwhite", chip(), chip())
end
local result = builder:getResult()
end)
end
else
PERMA.onPermissionsGained = function()
builder = MeshBuilder:new(LINK)
end
PERMA.build()
builder:apply()
end

View File

@ -1,18 +1,18 @@
--@shared
--@name Toyota Altezza
--@author Opti1337, .hemp
-- @include /koptilnya/mesh_loader/builder.txt
require("/koptilnya/mesh_loader/builder.txt")
--@include /libs/meshbuilder.txt
local MeshBuilder = require("/libs/meshbuilder.txt")
DEBUG_MODE = true
local LINK = "https://www.dropbox.com/s/0vnd3nir8cyolz5/is300_3.obj?dl=1"
local SCALE = Vector(0.8, 0.79, 0.8)
local builder = {}
local builder = MeshBuilder:new(LINK)
if SERVER then
builder = MeshBuilder:new(LINK)
builder:build("body_Mesh_0", Vector(0), Angle(0), SCALE, Color(40, 40, 40), "models/debug/debugwhite", chip(), chip())
builder:build("chrome_Mesh_1", Vector(0), Angle(0), SCALE, Color(255, 255, 255), "sprops/textures/sprops_chrome", chip(), chip())
@ -24,33 +24,5 @@ if SERVER then
builder:build("Reshetka_Mesh_7", Vector(0), Angle(0), SCALE, Color(225, 255, 255, 255), "models/props_interiors/metalfence007a", chip(), chip())
builder:build("w_plastic_Mesh_8", Vector(0), Angle(0), SCALE, Color(225, 255, 255, 255), "models/combine_scanner/scanner_eye", chip(), chip())
builder:getResult()
else
function init()
builder = MeshBuilder:new(LINK)
builder.onHologramsReceived = function(builder, objects)
local mat = material.create("VertexLitGeneric")
mat:setTextureURL("$basetexture", "https://i.imgur.com/gw4kfYv.jpg",
function(m, url, w, h, layout)
layout(0, 0, 2048, 2048)
end,
function(m, url)
objects[1].holo:setMaterial("")
objects[1].holo:setMeshMaterial(m)
end
)
end
end
if hasPermission("http.get") and hasPermission("mesh") and hasPermission("entities.setRenderProperty", chip()) then
init()
else
setupPermissionRequest({"http.get", "mesh", "entities.setRenderProperty"}, "", true)
hook.add("permissionrequest", "_permissionrequest", function()
if permissionRequestSatisfied() then
init()
end
end)
end
builder:apply()
end

View File

@ -8,13 +8,12 @@ local Vehicle, POWERTRAIN_COMPONENT = unpack(require('/koptilnya/engine_remaster
local Differential = require('/koptilnya/engine_remastered/powertrain/differential.txt')
local WheelConfig = {
BrakePower = 800,
CustomWheel = {},
Model = 'models/sprops/trans/wheel_d/t_wheel25.mdl',
RotationAxle = Angle(1, 0, 0)
BrakePower = 1200,
CustomWheel = { Mass = 80 },
Model = 'models/sprops/trans/wheel_d/t_wheel25.mdl'
}
local FrontWheelsConfig = table.merge(table.copy(WheelConfig), { SteerLock = 35 })
local RearWheelsConfig = table.merge(table.copy(WheelConfig), { HandbrakePower = 2000 })
local FrontWheelsConfig = table.merge(table.copy(WheelConfig), { SteerLock = 33, CustomWheel = { Mass = 80, CasterAngle = 7 } })
local RearWheelsConfig = table.merge(table.copy(WheelConfig), { HandbrakePower = 2200 })
Vehicle:new({
{
@ -58,12 +57,31 @@ Vehicle:new({
Reverse = 3.437
}
},
{
Name = 'AxleFront',
Type = POWERTRAIN_COMPONENT.Differential,
Config = {
SteerLock = 50
}
},
{
Name = 'WheelFL',
Type = POWERTRAIN_COMPONENT.Wheel,
Input = 'AxleFront',
Config = table.merge(table.copy(FrontWheelsConfig), { Offset = 0 })
},
{
Name = 'WheelFR',
Type = POWERTRAIN_COMPONENT.Wheel,
Input = 'AxleFront',
Config = table.merge(table.copy(FrontWheelsConfig), { Offset = 180 })
},
{
Name = 'Axle1',
Input = 'Gearbox',
Type = POWERTRAIN_COMPONENT.Differential,
Config = {
Type = Differential.TYPES.HLSD,
Type = Differential.TYPES.Open,
FinalDrive = 3.392,
Inertia = 0.01,
BiasAB = 0.5,
@ -73,25 +91,15 @@ Vehicle:new({
SlipTorque = 1000
}
},
{
Name = 'WheelFL',
Input = 'Axle1',
Type = POWERTRAIN_COMPONENT.Wheel,
Config = table.merge(table.copy(FrontWheelsConfig), { Offset = 0 })
},
{
Name = 'WheelFR',
Input = 'Axle1',
Type = POWERTRAIN_COMPONENT.Wheel,
Config = table.merge(table.copy(FrontWheelsConfig), { Offset = 180 })
},
{
Name = 'WheelRL',
Input = 'Axle1',
Type = POWERTRAIN_COMPONENT.Wheel,
Config = table.merge(table.copy(RearWheelsConfig), { Offset = 0 })
},
{
Name = 'WheelRR',
Input = 'Axle1',
Type = POWERTRAIN_COMPONENT.Wheel,
Config = table.merge(table.copy(RearWheelsConfig), { Offset = 180 })
}

View File

@ -1,7 +1,6 @@
--@include /koptilnya/libs/constants.txt
--@include ./powertrain_component.txt
local PowertrainComponent = require('./powertrain_component.txt')
local WheelComponent = require('./wheel.txt')
@ -29,6 +28,9 @@ function Differential:initialize(vehicle, name, config)
self.stiffness = config.Stiffness or 0.1
self.slipTorque = config.SlipTorque or 1000
self.splitStrategy = Differential.getSplitStrategy(config.Type or Differential.TYPES.Open)
self.steerLock = config.SteerLock or 0
self.steerAngle = 0
end
function Differential:linkComponent(component)
@ -107,6 +109,40 @@ function Differential:forwardStep(torque, inertia)
tqA = self.outputA:forwardStep(tqA, inertia * 0.5 * math.pow(self.finalDrive, 2) + aI) / self.finalDrive
tqB = self.outputB:forwardStep(tqB, inertia * 0.5 * math.pow(self.finalDrive, 2) + bI) / self.finalDrive
-- // REFACTOR
if self.steerLock ~= 0 then
local steerInertia = (aI + bI) / 2
local inputForce = 228.0
local maxSteerSpeed = math.rad(1337)
local inputTorque = self.vehicle.steer * inputForce
local avgSteerAngle = (self.outputA.customWheel.steerAngle + self.outputB.customWheel.steerAngle) / 2
local mz = self.outputA.customWheel.mz + self.outputB.customWheel.mz
local avgMz = (self.outputA.customWheel.mz + self.outputB.customWheel.mz) / 2
local maxMz = math.max(self.outputA.customWheel.mz + self.outputB.customWheel.mz)
local steerTorque = mz * -1 + inputTorque
local steerAngularAccel = steerTorque / steerInertia
self.steerAngle = math.clamp(
self.steerAngle + steerAngularAccel * TICK_INTERVAL,
-self.steerLock,
self.steerLock
)
-- Аккерман
local wheelbase = 2.05
local trackWidth = 1.124
local radius = wheelbase / math.tan(math.rad(self.steerAngle))
local innerAngle = math.deg(math.atan(wheelbase / (radius - (trackWidth / 2))))
local outerAngle = math.deg(math.atan(wheelbase / (radius + (trackWidth / 2))))
self.outputA.customWheel.steerAngle = outerAngle
self.outputB.customWheel.steerAngle = innerAngle
end
return (tqA + tqB) / self.finalDrive
end

View File

@ -55,10 +55,24 @@ function Wheel:initialize(vehicle, name, config)
end
end)
local right = self.entity:getRight()
local right = self.entity:getRight():getRotated(Angle(0, 90, 0))
local offsetRight = self.entity:getRight():rotateAroundAxis(self.entity:getUp(), self.offset)
self.dir = right:dot(offsetRight)
self.debugHolo1 = holograms.create(
Vector(),
Angle(),
'models/sprops/geometry/sphere_3.mdl'
)
self.debugHolo2 = holograms.create(
Vector(),
Angle(),
'models/sprops/geometry/sphere_3.mdl'
)
self.steerVelocity = 0
end
function Wheel:getEntityRadius()
@ -79,8 +93,10 @@ function Wheel:createHolo(entity)
entity:getAngles() + Angle(0, self.offset, 0),
self.CONFIG.Model or ''
)
holo:setParent(entity)
-- holo:setColor(Color(255,255,255,110))
entity:setColor(Color(0,0,0,0))
return holo
@ -105,7 +121,7 @@ function Wheel:forwardStep(torque, inertia)
return 0
end
self.customWheel.steerAngle = self.vehicle.steer * self.steerLock
-- self.customWheel.steerAngle = self.vehicle.steer * self.steerLock
--self.customWheel.inertia = inertia
--self.customWheel:setInertia(inertia)
self.customWheel.motorTorque = torque
@ -115,19 +131,39 @@ function Wheel:forwardStep(torque, inertia)
self.angularVelocity = self.customWheel.angularVelocity
self.debugHolo1:setPos(self.entity:localToWorld(Vector(0, 0, -self.entity:getModelRadius())))
if self.customWheel.hasHit and isValid(self.vehicle.basePhysObject) then
local surfaceForceVector = self.customWheel.right * self.customWheel.sideFriction.force + self.customWheel.forward * self.customWheel.forwardFriction.force
self.vehicle.basePhysObject:applyForceOffset(surfaceForceVector, self.entity:getPos() - Vector(0, 0, self.customWheel.radius))
self.vehicle.basePhysObject:applyForceOffset(surfaceForceVector, self.entity:localToWorld(Vector(0, 0, -self.entity:getModelRadius())))
end
if isValid(self.holo) then
self.rot = self.rot + math.deg(self.angularVelocity) * TICK_INTERVAL * self.dir
local steerAngle = self.entity:localToWorldAngles(Angle(0, self.offset - self.customWheel.steerAngle, 0) + self.rotationAxle * self.rot)
local angle = steerAngle
local spinAxis = self.customWheel.up:cross(self.customWheel.forward):getNormalized()
self.holo:setAngles(angle)
self.debugHolo2:setPos(self.entity:localToWorld(self.customWheel.up * math.sin(timer.curtime()) * 20))
local rotatedForwardAngle = self.customWheel.forward:getAngle() + Angle(0, 90, 0)
-- self.holo:setAngles(rotatedForwardAngle)
-- local ang = up:getAngle()
-- self.holo:setAngles(self.customWheel.forward:getAngle())
-- self.holo:setAngles(self.holo:getAngles():rotateAroundAxis(self.customWheel.right, 0))
-- self.holo:setAngles(self.holo:getAngles():rotateAroundAxis(self.customWheel.right, nil, self.angularVelocity * TICK_INTERVAL))
self.holo:setAngles(self.holo:getAngles():rotateAroundAxis(self.customWheel.right, nil, self.angularVelocity * TICK_INTERVAL))
-- local steerAngle = self.entity:localToWorldAngles(Angle(0, self.offset - self.customWheel.steerAngle, 0) + self.rotationAxle * self.rot)
-- local angle = steerAngle
-- self.holo:setAngles(angle)
end
return self.customWheel.counterTorque

View File

@ -63,7 +63,7 @@ function Vehicle:linkComponents()
for _, componentConfig in pairs(self.config) do
local component = self:getComponentByName(componentConfig.Name)
if componentConfig.Type == POWERTRAIN_COMPONENT.Wheel and componentConfig.Input == nil then
if componentConfig.Input == nil && component ~= self:getRootComponent() then
table.insert(self.independentComponents, component)
else
local inputComponent = self:getComponentByName(componentConfig.Input)

View File

@ -14,9 +14,10 @@ function Wheel:initialize(config)
self.mass = config.Mass or 20
self.radius = config.Radius or 0.27
self.rollingResistance = config.RollingResistance or 40
self.rollingResistance = config.RollingResistance or 20
self.squat = config.Squat or 0.1
self.slipCircleShape = config.SlipCircleShape or 1.05
self.casterAngle = math.rad(config.CasterAngle or 0)
self.forwardFriction = Friction:new(config.ForwardFriction)
self.sideFriction = Friction:new(config.SideFriction)
@ -35,6 +36,7 @@ function Wheel:initialize(config)
self.forward = Vector(0)
self.right = Vector(0)
self.up = Vector(0)
self.entity = NULL_ENTITY
self.physObj = nil
self.baseInertia = 0.5 * self.mass * math.pow(self.radius, 2)
@ -168,73 +170,26 @@ function Wheel:slipCircle(Sx, Sy, Fx, Fy, slipCircleShape)
return Sx, Sy, Fx, Fy
end
function Wheel:selfAligningTorque(Vx, Vy, Lc)
local VxAbs = math.abs(Vx)
local Sy = 0
if VxAbs > 0.3 then
Sy = math.deg(math.atan(Vy / VxAbs))
else
Sy = Vy * (0.003 / TICK_INTERVAL)
end
Sy = math.clamp(Sy, -90, 90)
--local phi = (1 - self.E) * Sy + (self.E / self.B) * math.atan(self.B * Sy)
--local Mz = -slipSign * self.satFrictionPreset:evaluate(math.abs(phi), self.B, C, self.D, 0) * Lc
return self.satFrictionPreset:evaluate(math.abs(Sy)) * -math.sign(Sy)
end
function Wheel:selfAligningTorque2(Vx, Vy, Fz)
if Fz == 0 then
function Wheel:selfAligningTorque(Sy, load)
if math.abs(Sy) < 0.001 or load < 0.001 then
return 0
end
local VxAbs = math.abs(Vx)
local Sy = 0
local B = self.satFrictionPreset.B
local C = self.satFrictionPreset.C
local D = self.satFrictionPreset.D
local E = self.satFrictionPreset.E
if VxAbs > 0.3 then
Sy = math.deg(math.atan(Vy / VxAbs))
else
Sy = Vy * (0.003 / TICK_INTERVAL)
end
local loadScale = load * 1000
local mechanicalTrail = 0.15
local casterEffect = math.tan(self.casterAngle)
local effectiveTrail = mechanicalTrail + casterEffect * self.radius
local D_scaled = D * loadScale * effectiveTrail
Sy = math.clamp(Sy, -1, 1)
local term = B * Sy - E * (B * Sy - math.atan(B * Sy))
local Mz = D_scaled * math.sin(C * math.atan(term))
local a = {
-2.72,
-2.28,
-1.86,
-2.73,
0.110,
-0.070,
0.643,
-4.04,
0.015,
-0.066,
0.945,
0.030,
0.070
}
local FzSqr = math.pow(Fz, 2)
local C = 2.4
local D = a[1] * FzSqr + a[2] * Fz
local BCD = (a[3] * FzSqr + a[4] * Fz) / math.pow(math.exp(1), a[5] * Fz)
local B = BCD / (C * D)
local E = a[6] * FzSqr + a[7] * Fz + a[8]
local phi = (1 - E) * Sy + (E / B) * math.atan(B * Sy)
self.phi = phi
return D * math.sin(C * math.atan(B * phi))
end
function Wheel:selfAligningTorque3(Mx, My, Sx, Sy)
local M = Mx * math.cos(Sy) + My * math.cos(Sx)
return self.radius * M
return Mz
end
function Wheel:update()
@ -251,10 +206,27 @@ function Wheel:update()
self.longitudinalLoadCoefficient = self:getLongitudinalLoadCoefficient(self.load * 1000)
self.lateralLoadCoefficient = self:getLateralLoadCoefficient(self.load * 1000)
--self.steerAngle = self.steerAngle + self.mz / self.inertia
local baseForward = self.entity:getForward()
local baseUp = self.entity:getUp()
local baseRight = self.entity:getRight()
self.forward = self.entity:getForward():rotateAroundAxis(self.entity:getUp(), -self.steerAngle)
self.right = self.entity:getRight():rotateAroundAxis(self.entity:getUp(), -self.steerAngle)
local steerRotatedForward = baseForward:rotateAroundAxis(baseUp, -self.steerAngle)
local finalForward = steerRotatedForward:rotateAroundAxis(baseRight, nil, self.casterAngle)
self.forward = finalForward:getNormalized()
self.right = baseUp:cross(self.forward):getNormalized()
self.up = self.forward:cross(self.right):getNormalized()
-- local steerRotated = self.entity:getForward():rotateAroundAxis(self.entity:getUp(), -self.steerAngle)
-- self.forward = steerRotated:rotateAroundAxis(self.entity:getRight(), self.casterAngle)
-- local steerRotatedRight = self.entity:getRight():rotateAroundAxis(self.entity:getUp(), -self.steerAngle)
-- self.right = steerRotatedRight:rotateAroundAxis(self.entity:getRight(), self.casterAngle)
-- self.forward = self.entity:getForward():rotateAroundAxis(self.entity:getUp(), -self.steerAngle)
-- self.right = self.entity:getRight():rotateAroundAxis(self.entity:getUp(), -self.steerAngle)
local forwardSpeed = 0
local sideSpeed = 0
@ -272,16 +244,16 @@ function Wheel:update()
self.longitudinalLoadCoefficient,
self.radius,
self.inertia,
0.95, -- Force coeff
0.9 -- Slip coeff
0.95,
0.9
)
local Sy, Fy = self:stepLateral(
forwardSpeed,
sideSpeed,
self.lateralLoadCoefficient,
0.95, -- Force coeff
0.9 -- Slip coeff
0.95,
0.9
)
@ -290,15 +262,10 @@ function Wheel:update()
Sy,
Fx,
Fy,
1.05 -- Shape of the slip circle / ellipse.
1.05
)
--local Mx = Fy * (math.cos(Sx) - 1) + Fx * math.sin(Sx)
--local My = Fx * (math.cos(Sy) - 1) + Fy * math.sin(Sy)
--local Mz = self:selfAligningTorque3(Mx, My, Sx, Sy)
local Mz = self:selfAligningTorque2(forwardSpeed, sideSpeed, self.load)
self.mz = Mz
self.mz = self:selfAligningTorque(Sy, self.load)
self.angularVelocity = W
self.counterTorque = CounterTq

View File

@ -2,6 +2,7 @@
--@include sv_builder.txt
--@include cl_builder.txt
--@include /koptilnya/libs/perma.txt
--@shared
require("/koptilnya/libs/perma.txt")