MCPcopy Create free account
hub / github.com/crownengine/crown / compile_hinge_joint

Function compile_hinge_joint

src/resource/physics_resource.cpp:445–480  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

443 }
444
445 s32 compile_hinge_joint(Buffer &output, UnitCompiler &compiler, FlatJsonObject &obj, CompileOptions &opts)
446 {
447 HingeJoint hinge = {};
448 hinge.axis = VECTOR3_ZAXIS;
449 hinge.lower_limit = -PI_FOURTH;
450 hinge.upper_limit = PI_FOURTH;
451 JointDesc jd;
452 s32 err = joint_common_parse(jd, JointType::HINGE, compiler, obj, opts);
453 ENSURE_OR_RETURN(PHYSICS_RESOURCE, err == 0, opts);
454
455 hinge.axis = RETURN_IF_ERROR(sjson::parse_vector3(flat_json_object::get(obj, "data.axis")));
456
457 const bool use_motor = RETURN_IF_ERROR(sjson::parse_bool(flat_json_object::get(obj, "data.use_motor")));
458 jd.type_and_flags |= use_motor ? (u32)JointFlags::HINGE_USE_MOTOR : 0u;
459 hinge.target_velocity = RETURN_IF_ERROR(sjson::parse_float(flat_json_object::get(obj, "data.target_velocity")));
460 hinge.max_motor_impulse = RETURN_IF_ERROR(sjson::parse_float(flat_json_object::get(obj, "data.max_motor_impulse")));
461
462 const bool use_limits = RETURN_IF_ERROR(sjson::parse_bool(flat_json_object::get(obj, "data.use_limits")));
463 jd.type_and_flags |= use_limits ? (u32)JointFlags::HINGE_USE_LIMITS : 0u;
464 hinge.lower_limit = RETURN_IF_ERROR(sjson::parse_float(flat_json_object::get(obj, "data.lower_limit")));
465 hinge.upper_limit = RETURN_IF_ERROR(sjson::parse_float(flat_json_object::get(obj, "data.upper_limit")));
466 hinge.bounciness = RETURN_IF_ERROR(sjson::parse_float(flat_json_object::get(obj, "data.bounciness")));
467
468 FileBuffer fb(output);
469 err = joint_common_write(fb, jd);
470 ENSURE_OR_RETURN(PHYSICS_RESOURCE, err == 0, opts);
471
472 BinaryWriter bw(fb);
473 bw.write(hinge.axis);
474 bw.write(hinge.target_velocity);
475 bw.write(hinge.max_motor_impulse);
476 bw.write(hinge.lower_limit);
477 bw.write(hinge.upper_limit);
478 bw.write(hinge.bounciness);
479 return 0;
480 }
481
482 s32 compile_spherical_joint(Buffer &output, UnitCompiler &compiler, FlatJsonObject &obj, CompileOptions &opts)
483 {

Callers

nothing calls this directly

Calls 7

joint_common_parseFunction · 0.85
parse_vector3Function · 0.85
getFunction · 0.85
joint_common_writeFunction · 0.85
parse_boolFunction · 0.50
parse_floatFunction · 0.50
writeMethod · 0.45

Tested by

no test coverage detected