Skip to content

Commit

Permalink
Merge pull request #17 from harfang3d/keyboard_control_wheel_animated
Browse files Browse the repository at this point in the history
Keyboard control wheel animated
  • Loading branch information
disketflu authored Nov 23, 2022
2 parents ee1e008 + 4a9e4aa commit 44d71ff
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
11 changes: 7 additions & 4 deletions app/car.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def CarModelCreate(name, instance_node_name, scene, scene_physics, resources, st
o['steering_angle_max'] = 45
o['thrust_power'] = 400000 # Acceleration
o['brakes_power'] = 1000000
o['steering_speed'] = 150
o['steering_speed'] = 50
o['max_speed'] = 130

# Variables
Expand Down Expand Up @@ -97,10 +97,13 @@ def CarModelForceSteering(rccar, angle, steering_wheel):
steering_wheel.GetTransform().SetRot(hg.Deg3(steering_wheel_rot.x, 180 -
rccar['steering_angle'] * 3, steering_wheel_rot.z))

def CarModelIncreaseSteering(car_model, angle):
def CarModelIncreaseSteering(car_model, angle, steering_wheel):
car_model['steering_angle'] = max(min(car_model['steering_angle'] + angle, car_model['steering_angle_max']), -car_model['steering_angle_max'])
car_model['thrust'].GetTransform().SetRot(
hg.Deg3(0, car_model['steering_angle'], 0))
steering_wheel_rot = steering_wheel.GetTransform().GetRot()
steering_wheel.GetTransform().SetRot(hg.Deg3(steering_wheel_rot.x, 180 -
car_model['steering_angle'] * 3, steering_wheel_rot.z))


def CarModelApplyAcceleration(rccar, value, scene_physics):
Expand Down Expand Up @@ -245,9 +248,9 @@ def CarModelControl(rccar, scene_physics, kb, dts, steering_wheel, joystick, con

if control_keyboard:
if kb.Down(hg.K_Left):
CarModelIncreaseSteering(rccar, -rccar['steering_speed'] * dts)
CarModelIncreaseSteering(rccar, -rccar['steering_speed'] * dts, steering_wheel)
if kb.Down(hg.K_Right):
CarModelIncreaseSteering(rccar, rccar['steering_speed'] * dts)
CarModelIncreaseSteering(rccar, rccar['steering_speed'] * dts, steering_wheel)

else:
CarModelForceSteering(rccar, joystick.Axes(0), steering_wheel)
Expand Down
22 changes: 22 additions & 0 deletions app/car_spawner.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import harfang as hg
import json, os
from utils import *

def CreateNewCar(scene, res, pos):
Expand All @@ -12,3 +13,24 @@ def HandleCarMovement(carnode, physics):
car_pos.z += 0.65
carnode_transform.SetPos(car_pos)
# physics.NodeWake(carnode)

def GetBlockTracks():
file_dir_out = "out/"
path = os.getcwd() + "/../tools/path_converter/" + file_dir_out

files = []

for r, d, f in os.walk(path):
for file in f:
files.append(os.path.join(r, file))

final_data = {}

for f in files:
with open(f, 'r') as json_file:
file_name = os.path.basename(f).replace(".json", "")
node_name = file_name.replace("_tracks", "")
data = json.loads(json_file.read())
final_data[node_name] = data

return final_data
1 change: 1 addition & 0 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def CreateMaterial(ubc, orm):
physics_debug = False
car_debug = False
control_keyboard = False
track_data = GetBlockTracks()

scene_nodes = scene.GetNodes()
for node_idx in range(scene_nodes.size()):
Expand Down

0 comments on commit 44d71ff

Please sign in to comment.