Version 2.1: documentation, public API headers, and sample programs.
PiperOrigin-RevId: 403900419
This commit is contained in:
Executable
+342
@@ -0,0 +1,342 @@
|
||||
// Copyright 2021 DeepMind Technologies Limited
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef MUJOCO_MJDATA_H_
|
||||
#define MUJOCO_MJDATA_H_
|
||||
|
||||
//---------------------------- primitive types (mjt) ------------------------------------
|
||||
|
||||
typedef enum _mjtWarning // warning types
|
||||
{
|
||||
mjWARN_INERTIA = 0, // (near) singular inertia matrix
|
||||
mjWARN_CONTACTFULL, // too many contacts in contact list
|
||||
mjWARN_CNSTRFULL, // too many constraints
|
||||
mjWARN_VGEOMFULL, // too many visual geoms
|
||||
mjWARN_BADQPOS, // bad number in qpos
|
||||
mjWARN_BADQVEL, // bad number in qvel
|
||||
mjWARN_BADQACC, // bad number in qacc
|
||||
mjWARN_BADCTRL, // bad number in ctrl
|
||||
|
||||
mjNWARNING // number of warnings
|
||||
} mjtWarning;
|
||||
|
||||
|
||||
typedef enum _mjtTimer
|
||||
{
|
||||
// main api
|
||||
mjTIMER_STEP = 0, // step
|
||||
mjTIMER_FORWARD, // forward
|
||||
mjTIMER_INVERSE, // inverse
|
||||
|
||||
// breakdown of step/forward
|
||||
mjTIMER_POSITION, // fwdPosition
|
||||
mjTIMER_VELOCITY, // fwdVelocity
|
||||
mjTIMER_ACTUATION, // fwdActuation
|
||||
mjTIMER_ACCELERATION, // fwdAcceleration
|
||||
mjTIMER_CONSTRAINT, // fwdConstraint
|
||||
|
||||
// breakdown of fwdPosition
|
||||
mjTIMER_POS_KINEMATICS, // kinematics, com, tendon, transmission
|
||||
mjTIMER_POS_INERTIA, // inertia computations
|
||||
mjTIMER_POS_COLLISION, // collision detection
|
||||
mjTIMER_POS_MAKE, // make constraints
|
||||
mjTIMER_POS_PROJECT, // project constraints
|
||||
|
||||
mjNTIMER // number of timers
|
||||
} mjtTimer;
|
||||
|
||||
|
||||
//------------------------------ mjContact ----------------------------------------------
|
||||
|
||||
struct _mjContact // result of collision detection functions
|
||||
{
|
||||
// contact parameters set by geom-specific collision detector
|
||||
mjtNum dist; // distance between nearest points; neg: penetration
|
||||
mjtNum pos[3]; // position of contact point: midpoint between geoms
|
||||
mjtNum frame[9]; // normal is in [0-2]
|
||||
|
||||
// contact parameters set by mj_collideGeoms
|
||||
mjtNum includemargin; // include if dist<includemargin=margin-gap
|
||||
mjtNum friction[5]; // tangent1, 2, spin, roll1, 2
|
||||
mjtNum solref[mjNREF]; // constraint solver reference
|
||||
mjtNum solimp[mjNIMP]; // constraint solver impedance
|
||||
|
||||
// internal storage used by solver
|
||||
mjtNum mu; // friction of regularized cone, set by mj_makeConstraint
|
||||
mjtNum H[36]; // cone Hessian, set by mj_updateConstraint
|
||||
|
||||
// contact descriptors set by mj_collideGeoms
|
||||
int dim; // contact space dimensionality: 1, 3, 4 or 6
|
||||
int geom1; // id of geom 1
|
||||
int geom2; // id of geom 2
|
||||
|
||||
// flag set by mj_fuseContact or mj_instantianteEquality
|
||||
int exclude; // 0: include, 1: in gap, 2: fused, 3: equality, 4: no dofs
|
||||
|
||||
// address computed by mj_instantiateContact
|
||||
int efc_address; // address in efc; -1: not included, -2-i: distance constraint i
|
||||
};
|
||||
typedef struct _mjContact mjContact;
|
||||
|
||||
|
||||
//------------------------------ diagnostics --------------------------------------------
|
||||
|
||||
struct _mjWarningStat // warning statistics
|
||||
{
|
||||
int lastinfo; // info from last warning
|
||||
int number; // how many times was warning raised
|
||||
};
|
||||
typedef struct _mjWarningStat mjWarningStat;
|
||||
|
||||
|
||||
struct _mjTimerStat // timer statistics
|
||||
{
|
||||
mjtNum duration; // cumulative duration
|
||||
int number; // how many times was timer called
|
||||
};
|
||||
typedef struct _mjTimerStat mjTimerStat;
|
||||
|
||||
|
||||
struct _mjSolverStat // per-iteration solver statistics
|
||||
{
|
||||
mjtNum improvement; // cost reduction, scaled by 1/trace(M(qpos0))
|
||||
mjtNum gradient; // gradient norm (primal only, scaled)
|
||||
mjtNum lineslope; // slope in linesearch
|
||||
int nactive; // number of active constraints
|
||||
int nchange; // number of constraint state changes
|
||||
int neval; // number of cost evaluations in line search
|
||||
int nupdate; // number of Cholesky updates in line search
|
||||
};
|
||||
typedef struct _mjSolverStat mjSolverStat;
|
||||
|
||||
|
||||
//---------------------------------- mjData ---------------------------------------------
|
||||
|
||||
struct _mjData
|
||||
{
|
||||
// constant sizes
|
||||
int nstack; // number of mjtNums that can fit in stack
|
||||
int nbuffer; // size of main buffer in bytes
|
||||
|
||||
// stack pointer
|
||||
int pstack; // first available mjtNum address in stack
|
||||
|
||||
// memory utilization stats
|
||||
int maxuse_stack; // maximum stack allocation
|
||||
int maxuse_con; // maximum number of contacts
|
||||
int maxuse_efc; // maximum number of scalar constraints
|
||||
|
||||
// diagnostics
|
||||
mjWarningStat warning[mjNWARNING]; // warning statistics
|
||||
mjTimerStat timer[mjNTIMER]; // timer statistics
|
||||
mjSolverStat solver[mjNSOLVER]; // solver statistics per iteration
|
||||
int solver_iter; // number of solver iterations
|
||||
int solver_nnz; // number of non-zeros in Hessian or efc_AR
|
||||
mjtNum solver_fwdinv[2]; // forward-inverse comparison: qfrc, efc
|
||||
|
||||
// variable sizes
|
||||
int ne; // number of equality constraints
|
||||
int nf; // number of friction constraints
|
||||
int nefc; // number of constraints
|
||||
int ncon; // number of detected contacts
|
||||
|
||||
// global properties
|
||||
mjtNum time; // simulation time
|
||||
mjtNum energy[2]; // potential, kinetic energy
|
||||
|
||||
//-------------------------------- end of info header
|
||||
|
||||
// buffers
|
||||
void* buffer; // main buffer; all pointers point in it (nbuffer bytes)
|
||||
mjtNum* stack; // stack buffer (nstack mjtNums)
|
||||
|
||||
//-------------------------------- main inputs and outputs of the computation
|
||||
|
||||
// state
|
||||
mjtNum* qpos; // position (nq x 1)
|
||||
mjtNum* qvel; // velocity (nv x 1)
|
||||
mjtNum* act; // actuator activation (na x 1)
|
||||
mjtNum* qacc_warmstart; // acceleration used for warmstart (nv x 1)
|
||||
|
||||
// control
|
||||
mjtNum* ctrl; // control (nu x 1)
|
||||
mjtNum* qfrc_applied; // applied generalized force (nv x 1)
|
||||
mjtNum* xfrc_applied; // applied Cartesian force/torque (nbody x 6)
|
||||
|
||||
// dynamics
|
||||
mjtNum* qacc; // acceleration (nv x 1)
|
||||
mjtNum* act_dot; // time-derivative of actuator activation (na x 1)
|
||||
|
||||
// mocap data
|
||||
mjtNum* mocap_pos; // positions of mocap bodies (nmocap x 3)
|
||||
mjtNum* mocap_quat; // orientations of mocap bodies (nmocap x 4)
|
||||
|
||||
// user data
|
||||
mjtNum* userdata; // user data, not touched by engine (nuserdata x 1)
|
||||
|
||||
// sensors
|
||||
mjtNum* sensordata; // sensor data array (nsensordata x 1)
|
||||
|
||||
//-------------------------------- POSITION dependent
|
||||
|
||||
// computed by mj_fwdPosition/mj_kinematics
|
||||
mjtNum* xpos; // Cartesian position of body frame (nbody x 3)
|
||||
mjtNum* xquat; // Cartesian orientation of body frame (nbody x 4)
|
||||
mjtNum* xmat; // Cartesian orientation of body frame (nbody x 9)
|
||||
mjtNum* xipos; // Cartesian position of body com (nbody x 3)
|
||||
mjtNum* ximat; // Cartesian orientation of body inertia (nbody x 9)
|
||||
mjtNum* xanchor; // Cartesian position of joint anchor (njnt x 3)
|
||||
mjtNum* xaxis; // Cartesian joint axis (njnt x 3)
|
||||
mjtNum* geom_xpos; // Cartesian geom position (ngeom x 3)
|
||||
mjtNum* geom_xmat; // Cartesian geom orientation (ngeom x 9)
|
||||
mjtNum* site_xpos; // Cartesian site position (nsite x 3)
|
||||
mjtNum* site_xmat; // Cartesian site orientation (nsite x 9)
|
||||
mjtNum* cam_xpos; // Cartesian camera position (ncam x 3)
|
||||
mjtNum* cam_xmat; // Cartesian camera orientation (ncam x 9)
|
||||
mjtNum* light_xpos; // Cartesian light position (nlight x 3)
|
||||
mjtNum* light_xdir; // Cartesian light direction (nlight x 3)
|
||||
|
||||
// computed by mj_fwdPosition/mj_comPos
|
||||
mjtNum* subtree_com; // center of mass of each subtree (nbody x 3)
|
||||
mjtNum* cdof; // com-based motion axis of each dof (nv x 6)
|
||||
mjtNum* cinert; // com-based body inertia and mass (nbody x 10)
|
||||
|
||||
// computed by mj_fwdPosition/mj_tendon
|
||||
int* ten_wrapadr; // start address of tendon's path (ntendon x 1)
|
||||
int* ten_wrapnum; // number of wrap points in path (ntendon x 1)
|
||||
int* ten_J_rownnz; // number of non-zeros in Jacobian row (ntendon x 1)
|
||||
int* ten_J_rowadr; // row start address in colind array (ntendon x 1)
|
||||
int* ten_J_colind; // column indices in sparse Jacobian (ntendon x nv)
|
||||
mjtNum* ten_length; // tendon lengths (ntendon x 1)
|
||||
mjtNum* ten_J; // tendon Jacobian (ntendon x nv)
|
||||
int* wrap_obj; // geom id; -1: site; -2: pulley (nwrap*2 x 1)
|
||||
mjtNum* wrap_xpos; // Cartesian 3D points in all path (nwrap*2 x 3)
|
||||
|
||||
// computed by mj_fwdPosition/mj_transmission
|
||||
mjtNum* actuator_length; // actuator lengths (nu x 1)
|
||||
mjtNum* actuator_moment; // actuator moments (nu x nv)
|
||||
|
||||
// computed by mj_fwdPosition/mj_crb
|
||||
mjtNum* crb; // com-based composite inertia and mass (nbody x 10)
|
||||
mjtNum* qM; // total inertia (nM x 1)
|
||||
|
||||
// computed by mj_fwdPosition/mj_factorM
|
||||
mjtNum* qLD; // L'*D*L factorization of M (nM x 1)
|
||||
mjtNum* qLDiagInv; // 1/diag(D) (nv x 1)
|
||||
mjtNum* qLDiagSqrtInv; // 1/sqrt(diag(D)) (nv x 1)
|
||||
|
||||
// computed by mj_fwdPosition/mj_collision
|
||||
mjContact* contact; // list of all detected contacts (nconmax x 1)
|
||||
|
||||
// computed by mj_fwdPosition/mj_makeConstraint
|
||||
int* efc_type; // constraint type (mjtConstraint) (njmax x 1)
|
||||
int* efc_id; // id of object of specified type (njmax x 1)
|
||||
int* efc_J_rownnz; // number of non-zeros in Jacobian row (njmax x 1)
|
||||
int* efc_J_rowadr; // row start address in colind array (njmax x 1)
|
||||
int* efc_J_rowsuper; // number of subsequent rows in supernode (njmax x 1)
|
||||
int* efc_J_colind; // column indices in Jacobian (njmax x nv)
|
||||
int* efc_JT_rownnz; // number of non-zeros in Jacobian row T (nv x 1)
|
||||
int* efc_JT_rowadr; // row start address in colind array T (nv x 1)
|
||||
int* efc_JT_rowsuper; // number of subsequent rows in supernode T (nv x 1)
|
||||
int* efc_JT_colind; // column indices in Jacobian T (nv x njmax)
|
||||
mjtNum* efc_J; // constraint Jacobian (njmax x nv)
|
||||
mjtNum* efc_JT; // constraint Jacobian transposed (nv x njmax)
|
||||
mjtNum* efc_pos; // constraint position (equality, contact) (njmax x 1)
|
||||
mjtNum* efc_margin; // inclusion margin (contact) (njmax x 1)
|
||||
mjtNum* efc_frictionloss; // frictionloss (friction) (njmax x 1)
|
||||
mjtNum* efc_diagApprox; // approximation to diagonal of A (njmax x 1)
|
||||
mjtNum* efc_KBIP; // stiffness, damping, impedance, imp' (njmax x 4)
|
||||
mjtNum* efc_D; // constraint mass (njmax x 1)
|
||||
mjtNum* efc_R; // inverse constraint mass (njmax x 1)
|
||||
|
||||
// computed by mj_fwdPosition/mj_projectConstraint
|
||||
int* efc_AR_rownnz; // number of non-zeros in AR (njmax x 1)
|
||||
int* efc_AR_rowadr; // row start address in colind array (njmax x 1)
|
||||
int* efc_AR_colind; // column indices in sparse AR (njmax x njmax)
|
||||
mjtNum* efc_AR; // J*inv(M)*J' + R (njmax x njmax)
|
||||
|
||||
//-------------------------------- POSITION, VELOCITY dependent
|
||||
|
||||
// computed by mj_fwdVelocity
|
||||
mjtNum* ten_velocity; // tendon velocities (ntendon x 1)
|
||||
mjtNum* actuator_velocity; // actuator velocities (nu x 1)
|
||||
|
||||
// computed by mj_fwdVelocity/mj_comVel
|
||||
mjtNum* cvel; // com-based velocity [3D rot; 3D tran] (nbody x 6)
|
||||
mjtNum* cdof_dot; // time-derivative of cdof (nv x 6)
|
||||
|
||||
// computed by mj_fwdVelocity/mj_rne (without acceleration)
|
||||
mjtNum* qfrc_bias; // C(qpos,qvel) (nv x 1)
|
||||
|
||||
// computed by mj_fwdVelocity/mj_passive
|
||||
mjtNum* qfrc_passive; // passive force (nv x 1)
|
||||
|
||||
// computed by mj_fwdVelocity/mj_referenceConstraint
|
||||
mjtNum* efc_vel; // velocity in constraint space: J*qvel (njmax x 1)
|
||||
mjtNum* efc_aref; // reference pseudo-acceleration (njmax x 1)
|
||||
|
||||
// computed by mj_sensorVel/mj_subtreeVel if needed
|
||||
mjtNum* subtree_linvel; // linear velocity of subtree com (nbody x 3)
|
||||
mjtNum* subtree_angmom; // angular momentum about subtree com (nbody x 3)
|
||||
|
||||
//-------------------------------- POSITION, VELOCITY, CONTROL/ACCELERATION dependent
|
||||
|
||||
// computed by mj_fwdActuation
|
||||
mjtNum* actuator_force; // actuator force in actuation space (nu x 1)
|
||||
mjtNum* qfrc_actuator; // actuator force (nv x 1)
|
||||
|
||||
// computed by mj_fwdAcceleration
|
||||
mjtNum* qfrc_unc; // net unconstrained force (nv x 1)
|
||||
mjtNum* qacc_unc; // unconstrained acceleration (nv x 1)
|
||||
|
||||
// computed by mj_fwdConstraint/mj_inverse
|
||||
mjtNum* efc_b; // linear cost term: J*qacc_unc - aref (njmax x 1)
|
||||
mjtNum* efc_force; // constraint force in constraint space (njmax x 1)
|
||||
int* efc_state; // constraint state (mjtConstraintState) (njmax x 1)
|
||||
mjtNum* qfrc_constraint; // constraint force (nv x 1)
|
||||
|
||||
// computed by mj_inverse
|
||||
mjtNum* qfrc_inverse; // net external force; should equal: (nv x 1)
|
||||
// qfrc_applied + J'*xfrc_applied + qfrc_actuator
|
||||
|
||||
// computed by mj_sensorAcc/mj_rnePostConstraint if needed; rotation:translation format
|
||||
mjtNum* cacc; // com-based acceleration (nbody x 6)
|
||||
mjtNum* cfrc_int; // com-based interaction force with parent (nbody x 6)
|
||||
mjtNum* cfrc_ext; // com-based external force on body (nbody x 6)
|
||||
};
|
||||
typedef struct _mjData mjData;
|
||||
|
||||
|
||||
//---------------------------------- callback function types ----------------------------
|
||||
|
||||
// generic MuJoCo function
|
||||
typedef void (*mjfGeneric)(const mjModel* m, mjData* d);
|
||||
|
||||
// contact filter: 1- discard, 0- collide
|
||||
typedef int (*mjfConFilt)(const mjModel* m, mjData* d, int geom1, int geom2);
|
||||
|
||||
// sensor simulation
|
||||
typedef void (*mjfSensor)(const mjModel* m, mjData* d, int stage);
|
||||
|
||||
// timer
|
||||
typedef mjtNum (*mjfTime)(void);
|
||||
|
||||
// actuator dynamics, gain, bias
|
||||
typedef mjtNum (*mjfAct)(const mjModel* m, const mjData* d, int id);
|
||||
|
||||
// collision detection
|
||||
typedef int (*mjfCollision)(const mjModel* m, const mjData* d,
|
||||
mjContact* con, int g1, int g2, mjtNum margin);
|
||||
|
||||
#endif // MUJOCO_MJDATA_H_
|
||||
Executable
+957
@@ -0,0 +1,957 @@
|
||||
// Copyright 2021 DeepMind Technologies Limited
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef MUJOCO_MJMODEL_H_
|
||||
#define MUJOCO_MJMODEL_H_
|
||||
|
||||
//---------------------------- floating-point definitions -------------------------------
|
||||
|
||||
// compile-time configuration options
|
||||
#define mjUSEDOUBLE // single or double precision for mjtNum
|
||||
#define mjUSEAVX // C or AVX intrinsics for custom BLAS
|
||||
|
||||
|
||||
// floating point data type and minval
|
||||
#ifdef mjUSEDOUBLE
|
||||
typedef double mjtNum;
|
||||
#define mjMINVAL 1E-15 // minimum value in any denominator
|
||||
#else
|
||||
typedef float mjtNum;
|
||||
#define mjMINVAL 1E-15f
|
||||
#endif
|
||||
|
||||
|
||||
// global constants
|
||||
#define mjPI 3.14159265358979323846
|
||||
#define mjMAXVAL 1E+10 // maximum value in qpos, qvel, qacc
|
||||
#define mjMINMU 1E-5 // minimum friction coefficient
|
||||
#define mjMINIMP 0.0001 // minimum constraint impedance
|
||||
#define mjMAXIMP 0.9999 // maximum constraint impedance
|
||||
#define mjMAXCONPAIR 50 // maximum number of contacts per geom pair
|
||||
#define mjMAXVFS 2000 // maximum number of files in virtual file system
|
||||
#define mjMAXVFSNAME 1000 // maximum filename size in virtual file system
|
||||
|
||||
|
||||
//---------------------------- sizes ----------------------------------------------------
|
||||
|
||||
#define mjNEQDATA 7 // number of eq_data fields
|
||||
#define mjNDYN 10 // number of actuator dynamics parameters
|
||||
#define mjNGAIN 10 // number of actuator gain parameters
|
||||
#define mjNBIAS 10 // number of actuator bias parameters
|
||||
#define mjNREF 2 // number of solver reference parameters
|
||||
#define mjNIMP 5 // number of solver impedance parameters
|
||||
#define mjNSOLVER 1000 // size of mjData.solver_XXX arrays
|
||||
|
||||
|
||||
//---------------------------- primitive types (mjt) ------------------------------------
|
||||
|
||||
typedef unsigned char mjtByte; // used for true/false
|
||||
|
||||
|
||||
typedef enum _mjtDisableBit // disable default feature bitflags
|
||||
{
|
||||
mjDSBL_CONSTRAINT = 1<<0, // entire constraint solver
|
||||
mjDSBL_EQUALITY = 1<<1, // equality constraints
|
||||
mjDSBL_FRICTIONLOSS = 1<<2, // joint and tendon frictionloss constraints
|
||||
mjDSBL_LIMIT = 1<<3, // joint and tendon limit constraints
|
||||
mjDSBL_CONTACT = 1<<4, // contact constraints
|
||||
mjDSBL_PASSIVE = 1<<5, // passive forces
|
||||
mjDSBL_GRAVITY = 1<<6, // gravitational forces
|
||||
mjDSBL_CLAMPCTRL = 1<<7, // clamp control to specified range
|
||||
mjDSBL_WARMSTART = 1<<8, // warmstart constraint solver
|
||||
mjDSBL_FILTERPARENT = 1<<9, // remove collisions with parent body
|
||||
mjDSBL_ACTUATION = 1<<10, // apply actuation forces
|
||||
mjDSBL_REFSAFE = 1<<11, // integrator safety: make ref[0]>=2*timestep
|
||||
|
||||
mjNDISABLE = 12 // number of disable flags
|
||||
} mjtDisableBit;
|
||||
|
||||
|
||||
typedef enum _mjtEnableBit // enable optional feature bitflags
|
||||
{
|
||||
mjENBL_OVERRIDE = 1<<0, // override contact parameters
|
||||
mjENBL_ENERGY = 1<<1, // energy computation
|
||||
mjENBL_FWDINV = 1<<2, // record solver statistics
|
||||
mjENBL_SENSORNOISE = 1<<3, // add noise to sensor data
|
||||
|
||||
mjNENABLE = 4 // number of enable flags
|
||||
} mjtEnableBit;
|
||||
|
||||
|
||||
typedef enum _mjtJoint // type of degree of freedom
|
||||
{
|
||||
mjJNT_FREE = 0, // global position and orientation (quat) (7)
|
||||
mjJNT_BALL, // orientation (quat) relative to parent (4)
|
||||
mjJNT_SLIDE, // sliding distance along body-fixed axis (1)
|
||||
mjJNT_HINGE // rotation angle (rad) around body-fixed axis (1)
|
||||
} mjtJoint;
|
||||
|
||||
|
||||
typedef enum _mjtGeom // type of geometric shape
|
||||
{
|
||||
// regular geom types
|
||||
mjGEOM_PLANE = 0, // plane
|
||||
mjGEOM_HFIELD, // height field
|
||||
mjGEOM_SPHERE, // sphere
|
||||
mjGEOM_CAPSULE, // capsule
|
||||
mjGEOM_ELLIPSOID, // ellipsoid
|
||||
mjGEOM_CYLINDER, // cylinder
|
||||
mjGEOM_BOX, // box
|
||||
mjGEOM_MESH, // mesh
|
||||
|
||||
mjNGEOMTYPES, // number of regular geom types
|
||||
|
||||
// rendering-only geom types: not used in mjModel, not counted in mjNGEOMTYPES
|
||||
mjGEOM_ARROW = 100, // arrow
|
||||
mjGEOM_ARROW1, // arrow without wedges
|
||||
mjGEOM_ARROW2, // arrow in both directions
|
||||
mjGEOM_LINE, // line
|
||||
mjGEOM_SKIN, // skin
|
||||
mjGEOM_LABEL, // text label
|
||||
|
||||
mjGEOM_NONE = 1001 // missing geom type
|
||||
} mjtGeom;
|
||||
|
||||
|
||||
typedef enum _mjtCamLight // tracking mode for camera and light
|
||||
{
|
||||
mjCAMLIGHT_FIXED = 0, // pos and rot fixed in body
|
||||
mjCAMLIGHT_TRACK, // pos tracks body, rot fixed in global
|
||||
mjCAMLIGHT_TRACKCOM, // pos tracks subtree com, rot fixed in body
|
||||
mjCAMLIGHT_TARGETBODY, // pos fixed in body, rot tracks target body
|
||||
mjCAMLIGHT_TARGETBODYCOM // pos fixed in body, rot tracks target subtree com
|
||||
} mjtCamLight;
|
||||
|
||||
|
||||
typedef enum _mjtTexture // type of texture
|
||||
{
|
||||
mjTEXTURE_2D = 0, // 2d texture, suitable for planes and hfields
|
||||
mjTEXTURE_CUBE, // cube texture, suitable for all other geom types
|
||||
mjTEXTURE_SKYBOX // cube texture used as skybox
|
||||
} mjtTexture;
|
||||
|
||||
|
||||
typedef enum _mjtIntegrator // integrator mode
|
||||
{
|
||||
mjINT_EULER = 0, // semi-implicit Euler
|
||||
mjINT_RK4 // 4th-order Runge Kutta
|
||||
} mjtIntegrator;
|
||||
|
||||
|
||||
typedef enum _mjtCollision // collision mode for selecting geom pairs
|
||||
{
|
||||
mjCOL_ALL = 0, // test precomputed and dynamic pairs
|
||||
mjCOL_PAIR, // test predefined pairs only
|
||||
mjCOL_DYNAMIC // test dynamic pairs only
|
||||
} mjtCollision;
|
||||
|
||||
|
||||
typedef enum _mjtCone // type of friction cone
|
||||
{
|
||||
mjCONE_PYRAMIDAL = 0, // pyramidal
|
||||
mjCONE_ELLIPTIC // elliptic
|
||||
} mjtCone;
|
||||
|
||||
|
||||
typedef enum _mjtJacobian // type of constraint Jacobian
|
||||
{
|
||||
mjJAC_DENSE = 0, // dense
|
||||
mjJAC_SPARSE, // sparse
|
||||
mjJAC_AUTO // dense if nv<60, sparse otherwise
|
||||
} mjtJacobian;
|
||||
|
||||
|
||||
typedef enum _mjtSolver // constraint solver algorithm
|
||||
{
|
||||
mjSOL_PGS = 0, // PGS (dual)
|
||||
mjSOL_CG, // CG (primal)
|
||||
mjSOL_NEWTON // Newton (primal)
|
||||
} mjtSolver;
|
||||
|
||||
|
||||
typedef enum _mjtEq // type of equality constraint
|
||||
{
|
||||
mjEQ_CONNECT = 0, // connect two bodies at a point (ball joint)
|
||||
mjEQ_WELD, // fix relative position and orientation of two bodies
|
||||
mjEQ_JOINT, // couple the values of two scalar joints with cubic
|
||||
mjEQ_TENDON, // couple the lengths of two tendons with cubic
|
||||
mjEQ_DISTANCE // fix the contact distance betweent two geoms
|
||||
} mjtEq;
|
||||
|
||||
|
||||
typedef enum _mjtWrap // type of tendon wrap object
|
||||
{
|
||||
mjWRAP_NONE = 0, // null object
|
||||
mjWRAP_JOINT, // constant moment arm
|
||||
mjWRAP_PULLEY, // pulley used to split tendon
|
||||
mjWRAP_SITE, // pass through site
|
||||
mjWRAP_SPHERE, // wrap around sphere
|
||||
mjWRAP_CYLINDER // wrap around (infinite) cylinder
|
||||
} mjtWrap;
|
||||
|
||||
|
||||
typedef enum _mjtTrn // type of actuator transmission
|
||||
{
|
||||
mjTRN_JOINT = 0, // force on joint
|
||||
mjTRN_JOINTINPARENT, // force on joint, expressed in parent frame
|
||||
mjTRN_SLIDERCRANK, // force via slider-crank linkage
|
||||
mjTRN_TENDON, // force on tendon
|
||||
mjTRN_SITE, // force on site
|
||||
|
||||
mjTRN_UNDEFINED = 1000 // undefined transmission type
|
||||
} mjtTrn;
|
||||
|
||||
|
||||
typedef enum _mjtDyn // type of actuator dynamics
|
||||
{
|
||||
mjDYN_NONE = 0, // no internal dynamics; ctrl specifies force
|
||||
mjDYN_INTEGRATOR, // integrator: da/dt = u
|
||||
mjDYN_FILTER, // linear filter: da/dt = (u-a) / tau
|
||||
mjDYN_MUSCLE, // piece-wise linear filter with two time constants
|
||||
mjDYN_USER // user-defined dynamics type
|
||||
} mjtDyn;
|
||||
|
||||
|
||||
typedef enum _mjtGain // type of actuator gain
|
||||
{
|
||||
mjGAIN_FIXED = 0, // fixed gain
|
||||
mjGAIN_MUSCLE, // muscle FLV curve computed by mju_muscleGain()
|
||||
mjGAIN_USER // user-defined gain type
|
||||
} mjtGain;
|
||||
|
||||
|
||||
typedef enum _mjtBias // type of actuator bias
|
||||
{
|
||||
mjBIAS_NONE = 0, // no bias
|
||||
mjBIAS_AFFINE, // const + kp*length + kv*velocity
|
||||
mjBIAS_MUSCLE, // muscle passive force computed by mju_muscleBias()
|
||||
mjBIAS_USER // user-defined bias type
|
||||
} mjtBias;
|
||||
|
||||
|
||||
typedef enum _mjtObj // type of MujoCo object
|
||||
{
|
||||
mjOBJ_UNKNOWN = 0, // unknown object type
|
||||
mjOBJ_BODY, // body
|
||||
mjOBJ_XBODY, // body, used to access regular frame instead of i-frame
|
||||
mjOBJ_JOINT, // joint
|
||||
mjOBJ_DOF, // dof
|
||||
mjOBJ_GEOM, // geom
|
||||
mjOBJ_SITE, // site
|
||||
mjOBJ_CAMERA, // camera
|
||||
mjOBJ_LIGHT, // light
|
||||
mjOBJ_MESH, // mesh
|
||||
mjOBJ_SKIN, // skin
|
||||
mjOBJ_HFIELD, // heightfield
|
||||
mjOBJ_TEXTURE, // texture
|
||||
mjOBJ_MATERIAL, // material for rendering
|
||||
mjOBJ_PAIR, // geom pair to include
|
||||
mjOBJ_EXCLUDE, // body pair to exclude
|
||||
mjOBJ_EQUALITY, // equality constraint
|
||||
mjOBJ_TENDON, // tendon
|
||||
mjOBJ_ACTUATOR, // actuator
|
||||
mjOBJ_SENSOR, // sensor
|
||||
mjOBJ_NUMERIC, // numeric
|
||||
mjOBJ_TEXT, // text
|
||||
mjOBJ_TUPLE, // tuple
|
||||
mjOBJ_KEY // keyframe
|
||||
} mjtObj;
|
||||
|
||||
|
||||
typedef enum _mjtConstraint // type of constraint
|
||||
{
|
||||
mjCNSTR_EQUALITY = 0, // equality constraint
|
||||
mjCNSTR_FRICTION_DOF, // dof friction
|
||||
mjCNSTR_FRICTION_TENDON, // tendon friction
|
||||
mjCNSTR_LIMIT_JOINT, // joint limit
|
||||
mjCNSTR_LIMIT_TENDON, // tendon limit
|
||||
mjCNSTR_CONTACT_FRICTIONLESS, // frictionless contact
|
||||
mjCNSTR_CONTACT_PYRAMIDAL, // frictional contact, pyramidal friction cone
|
||||
mjCNSTR_CONTACT_ELLIPTIC // frictional contact, elliptic friction cone
|
||||
} mjtConstraint;
|
||||
|
||||
|
||||
typedef enum _mjtConstraintState // constraint state
|
||||
{
|
||||
mjCNSTRSTATE_SATISFIED = 0, // constraint satisfied, zero cost (limit, contact)
|
||||
mjCNSTRSTATE_QUADRATIC, // quadratic cost (equality, friction, limit, contact)
|
||||
mjCNSTRSTATE_LINEARNEG, // linear cost, negative side (friction)
|
||||
mjCNSTRSTATE_LINEARPOS, // linear cost, positive side (friction)
|
||||
mjCNSTRSTATE_CONE // squared distance to cone cost (elliptic contact)
|
||||
} mjtConstraintState;
|
||||
|
||||
|
||||
typedef enum _mjtSensor // type of sensor
|
||||
{
|
||||
// common robotic sensors, attached to a site
|
||||
mjSENS_TOUCH = 0, // scalar contact normal forces summed over sensor zone
|
||||
mjSENS_ACCELEROMETER, // 3D linear acceleration, in local frame
|
||||
mjSENS_VELOCIMETER, // 3D linear velocity, in local frame
|
||||
mjSENS_GYRO, // 3D angular velocity, in local frame
|
||||
mjSENS_FORCE, // 3D force between site's body and its parent body
|
||||
mjSENS_TORQUE, // 3D torque between site's body and its parent body
|
||||
mjSENS_MAGNETOMETER, // 3D magnetometer
|
||||
mjSENS_RANGEFINDER, // scalar distance to nearest geom or site along z-axis
|
||||
|
||||
// sensors related to scalar joints, tendons, actuators
|
||||
mjSENS_JOINTPOS, // scalar joint position (hinge and slide only)
|
||||
mjSENS_JOINTVEL, // scalar joint velocity (hinge and slide only)
|
||||
mjSENS_TENDONPOS, // scalar tendon position
|
||||
mjSENS_TENDONVEL, // scalar tendon velocity
|
||||
mjSENS_ACTUATORPOS, // scalar actuator position
|
||||
mjSENS_ACTUATORVEL, // scalar actuator velocity
|
||||
mjSENS_ACTUATORFRC, // scalar actuator force
|
||||
|
||||
// sensors related to ball joints
|
||||
mjSENS_BALLQUAT, // 4D ball joint quaterion
|
||||
mjSENS_BALLANGVEL, // 3D ball joint angular velocity
|
||||
|
||||
// joint and tendon limit sensors, in constraint space
|
||||
mjSENS_JOINTLIMITPOS, // joint limit distance-margin
|
||||
mjSENS_JOINTLIMITVEL, // joint limit velocity
|
||||
mjSENS_JOINTLIMITFRC, // joint limit force
|
||||
mjSENS_TENDONLIMITPOS, // tendon limit distance-margin
|
||||
mjSENS_TENDONLIMITVEL, // tendon limit velocity
|
||||
mjSENS_TENDONLIMITFRC, // tendon limit force
|
||||
|
||||
// sensors attached to an object with spatial frame: (x)body, geom, site, camera
|
||||
mjSENS_FRAMEPOS, // 3D position
|
||||
mjSENS_FRAMEQUAT, // 4D unit quaternion orientation
|
||||
mjSENS_FRAMEXAXIS, // 3D unit vector: x-axis of object's frame
|
||||
mjSENS_FRAMEYAXIS, // 3D unit vector: y-axis of object's frame
|
||||
mjSENS_FRAMEZAXIS, // 3D unit vector: z-axis of object's frame
|
||||
mjSENS_FRAMELINVEL, // 3D linear velocity
|
||||
mjSENS_FRAMEANGVEL, // 3D angular velocity
|
||||
mjSENS_FRAMELINACC, // 3D linear acceleration
|
||||
mjSENS_FRAMEANGACC, // 3D angular acceleration
|
||||
|
||||
// sensors related to kinematic subtrees; attached to a body (which is the subtree root)
|
||||
mjSENS_SUBTREECOM, // 3D center of mass of subtree
|
||||
mjSENS_SUBTREELINVEL, // 3D linear velocity of subtree
|
||||
mjSENS_SUBTREEANGMOM, // 3D angular momentum of subtree
|
||||
|
||||
// user-defined sensor
|
||||
mjSENS_USER // sensor data provided by mjcb_sensor callback
|
||||
} mjtSensor;
|
||||
|
||||
|
||||
typedef enum _mjtStage // computation stage
|
||||
{
|
||||
mjSTAGE_NONE = 0, // no computations
|
||||
mjSTAGE_POS, // position-dependent computations
|
||||
mjSTAGE_VEL, // velocity-dependent computations
|
||||
mjSTAGE_ACC // acceleration/force-dependent computations
|
||||
} mjtStage;
|
||||
|
||||
|
||||
typedef enum _mjtDataType // data type for sensors
|
||||
{
|
||||
mjDATATYPE_REAL = 0, // real values, no constraints
|
||||
mjDATATYPE_POSITIVE, // positive values; 0 or negative: inactive
|
||||
mjDATATYPE_AXIS, // 3D unit vector
|
||||
mjDATATYPE_QUATERNION // unit quaternion
|
||||
} mjtDataType;
|
||||
|
||||
|
||||
typedef enum _mjtLRMode // mode for actuator length range computation
|
||||
{
|
||||
mjLRMODE_NONE = 0, // do not process any actuators
|
||||
mjLRMODE_MUSCLE, // process muscle actuators
|
||||
mjLRMODE_MUSCLEUSER, // process muscle and user actuators
|
||||
mjLRMODE_ALL // process all actuators
|
||||
} mjtLRMode;
|
||||
|
||||
|
||||
//------------------------------ mjLROpt ------------------------------------------------
|
||||
|
||||
struct _mjLROpt // options for mj_setLengthRange()
|
||||
{
|
||||
// flags
|
||||
int mode; // which actuators to process (mjtLRMode)
|
||||
int useexisting; // use existing length range if available
|
||||
int uselimit; // use joint and tendon limits if available
|
||||
|
||||
// algorithm parameters
|
||||
mjtNum accel; // target acceleration used to compute force
|
||||
mjtNum maxforce; // maximum force; 0: no limit
|
||||
mjtNum timeconst; // time constant for velocity reduction; min 0.01
|
||||
mjtNum timestep; // simulation timestep; 0: use mjOption.timestep
|
||||
mjtNum inttotal; // total simulation time interval
|
||||
mjtNum inteval; // evaluation time interval (at the end)
|
||||
mjtNum tolrange; // convergence tolerance (relative to range)
|
||||
};
|
||||
typedef struct _mjLROpt mjLROpt;
|
||||
|
||||
|
||||
//------------------------------ mjVFS --------------------------------------------------
|
||||
|
||||
struct _mjVFS // virtual file system for loading from memory
|
||||
{
|
||||
int nfile; // number of files present
|
||||
char filename[mjMAXVFS][mjMAXVFSNAME]; // file name without path
|
||||
int filesize[mjMAXVFS]; // file size in bytes
|
||||
void* filedata[mjMAXVFS]; // buffer with file data
|
||||
};
|
||||
typedef struct _mjVFS mjVFS;
|
||||
|
||||
|
||||
//------------------------------ mjOption -----------------------------------------------
|
||||
|
||||
struct _mjOption // physics options
|
||||
{
|
||||
// timing parameters
|
||||
mjtNum timestep; // timestep
|
||||
mjtNum apirate; // update rate for remote API (Hz)
|
||||
|
||||
// solver parameters
|
||||
mjtNum impratio; // ratio of friction-to-normal contact impedance
|
||||
mjtNum tolerance; // main solver tolerance
|
||||
mjtNum noslip_tolerance; // noslip solver tolerance
|
||||
mjtNum mpr_tolerance; // MPR solver tolerance
|
||||
|
||||
// physical constants
|
||||
mjtNum gravity[3]; // gravitational acceleration
|
||||
mjtNum wind[3]; // wind (for lift, drag and viscosity)
|
||||
mjtNum magnetic[3]; // global magnetic flux
|
||||
mjtNum density; // density of medium
|
||||
mjtNum viscosity; // viscosity of medium
|
||||
|
||||
// override contact solver parameters (if enabled)
|
||||
mjtNum o_margin; // margin
|
||||
mjtNum o_solref[mjNREF]; // solref
|
||||
mjtNum o_solimp[mjNIMP]; // solimp
|
||||
|
||||
// discrete settings
|
||||
int integrator; // integration mode (mjtIntegrator)
|
||||
int collision; // collision mode (mjtCollision)
|
||||
int cone; // type of friction cone (mjtCone)
|
||||
int jacobian; // type of Jacobian (mjtJacobian)
|
||||
int solver; // solver algorithm (mjtSolver)
|
||||
int iterations; // maximum number of main solver iterations
|
||||
int noslip_iterations; // maximum number of noslip solver iterations
|
||||
int mpr_iterations; // maximum number of MPR solver iterations
|
||||
int disableflags; // bit flags for disabling standard features
|
||||
int enableflags; // bit flags for enabling optional features
|
||||
};
|
||||
typedef struct _mjOption mjOption;
|
||||
|
||||
|
||||
//------------------------------ mjVisual -----------------------------------------------
|
||||
|
||||
struct _mjVisual // visualization options
|
||||
{
|
||||
struct // global parameters
|
||||
{
|
||||
float fovy; // y-field of view (deg) for free camera
|
||||
float ipd; // inter-pupilary distance for free camera
|
||||
float linewidth; // line width for wireframe and ray rendering
|
||||
float glow; // glow coefficient for selected body
|
||||
int offwidth; // width of offscreen buffer
|
||||
int offheight; // height of offscreen buffer
|
||||
} global;
|
||||
|
||||
struct // rendering quality
|
||||
{
|
||||
int shadowsize; // size of shadowmap texture
|
||||
int offsamples; // number of multisamples for offscreen rendering
|
||||
int numslices; // number of slices for builtin geom drawing
|
||||
int numstacks; // number of stacks for builtin geom drawing
|
||||
int numquads; // number of quads for box rendering
|
||||
} quality;
|
||||
|
||||
struct // head light
|
||||
{
|
||||
float ambient[3]; // ambient rgb (alpha=1)
|
||||
float diffuse[3]; // diffuse rgb (alpha=1)
|
||||
float specular[3]; // specular rgb (alpha=1)
|
||||
int active; // is headlight active
|
||||
} headlight;
|
||||
|
||||
struct // mapping
|
||||
{
|
||||
float stiffness; // mouse perturbation stiffness (space->force)
|
||||
float stiffnessrot; // mouse perturbation stiffness (space->torque)
|
||||
float force; // from force units to space units
|
||||
float torque; // from torque units to space units
|
||||
float alpha; // scale geom alphas when transparency is enabled
|
||||
float fogstart; // OpenGL fog starts at fogstart * mjModel.stat.extent
|
||||
float fogend; // OpenGL fog ends at fogend * mjModel.stat.extent
|
||||
float znear; // near clipping plane = znear * mjModel.stat.extent
|
||||
float zfar; // far clipping plane = zfar * mjModel.stat.extent
|
||||
float haze; // haze ratio
|
||||
float shadowclip; // directional light: shadowclip * mjModel.stat.extent
|
||||
float shadowscale; // spot light: shadowscale * light.cutoff
|
||||
float actuatortendon; // scale tendon width
|
||||
} map;
|
||||
|
||||
struct // scale of decor elements relative to mean body size
|
||||
{
|
||||
float forcewidth; // width of force arrow
|
||||
float contactwidth; // contact width
|
||||
float contactheight; // contact height
|
||||
float connect; // autoconnect capsule width
|
||||
float com; // com radius
|
||||
float camera; // camera object
|
||||
float light; // light object
|
||||
float selectpoint; // selection point
|
||||
float jointlength; // joint length
|
||||
float jointwidth; // joint width
|
||||
float actuatorlength; // actuator length
|
||||
float actuatorwidth; // actuator width
|
||||
float framelength; // bodyframe axis length
|
||||
float framewidth; // bodyframe axis width
|
||||
float constraint; // constraint width
|
||||
float slidercrank; // slidercrank width
|
||||
} scale;
|
||||
|
||||
struct // color of decor elements
|
||||
{
|
||||
float fog[4]; // fog
|
||||
float haze[4]; // haze
|
||||
float force[4]; // external force
|
||||
float inertia[4]; // inertia box
|
||||
float joint[4]; // joint
|
||||
float actuator[4]; // actuator, neutral
|
||||
float actuatornegative[4]; // actuator, negative limit
|
||||
float actuatorpositive[4]; // actuator, positive limit
|
||||
float com[4]; // center of mass
|
||||
float camera[4]; // camera object
|
||||
float light[4]; // light object
|
||||
float selectpoint[4]; // selection point
|
||||
float connect[4]; // auto connect
|
||||
float contactpoint[4]; // contact point
|
||||
float contactforce[4]; // contact force
|
||||
float contactfriction[4]; // contact friction force
|
||||
float contacttorque[4]; // contact torque
|
||||
float contactgap[4]; // contact point in gap
|
||||
float rangefinder[4]; // rangefinder ray
|
||||
float constraint[4]; // constraint
|
||||
float slidercrank[4]; // slidercrank
|
||||
float crankbroken[4]; // used when crank must be stretched/broken
|
||||
} rgba;
|
||||
};
|
||||
typedef struct _mjVisual mjVisual;
|
||||
|
||||
|
||||
//------------------------------ mjStatistic --------------------------------------------
|
||||
|
||||
struct _mjStatistic // model statistics (in qpos0)
|
||||
{
|
||||
mjtNum meaninertia; // mean diagonal inertia
|
||||
mjtNum meanmass; // mean body mass
|
||||
mjtNum meansize; // mean body size
|
||||
mjtNum extent; // spatial extent
|
||||
mjtNum center[3]; // center of model
|
||||
};
|
||||
typedef struct _mjStatistic mjStatistic;
|
||||
|
||||
|
||||
//---------------------------------- mjModel --------------------------------------------
|
||||
|
||||
struct _mjModel
|
||||
{
|
||||
// ------------------------------- sizes
|
||||
|
||||
// sizes needed at mjModel construction
|
||||
int nq; // number of generalized coordinates = dim(qpos)
|
||||
int nv; // number of degrees of freedom = dim(qvel)
|
||||
int nu; // number of actuators/controls = dim(ctrl)
|
||||
int na; // number of activation states = dim(act)
|
||||
int nbody; // number of bodies
|
||||
int njnt; // number of joints
|
||||
int ngeom; // number of geoms
|
||||
int nsite; // number of sites
|
||||
int ncam; // number of cameras
|
||||
int nlight; // number of lights
|
||||
int nmesh; // number of meshes
|
||||
int nmeshvert; // number of vertices in all meshes
|
||||
int nmeshtexvert; // number of vertices with texcoords in all meshes
|
||||
int nmeshface; // number of triangular faces in all meshes
|
||||
int nmeshgraph; // number of ints in mesh auxiliary data
|
||||
int nskin; // number of skins
|
||||
int nskinvert; // number of vertices in all skins
|
||||
int nskintexvert; // number of vertiex with texcoords in all skins
|
||||
int nskinface; // number of triangular faces in all skins
|
||||
int nskinbone; // number of bones in all skins
|
||||
int nskinbonevert; // number of vertices in all skin bones
|
||||
int nhfield; // number of heightfields
|
||||
int nhfielddata; // number of data points in all heightfields
|
||||
int ntex; // number of textures
|
||||
int ntexdata; // number of bytes in texture rgb data
|
||||
int nmat; // number of materials
|
||||
int npair; // number of predefined geom pairs
|
||||
int nexclude; // number of excluded geom pairs
|
||||
int neq; // number of equality constraints
|
||||
int ntendon; // number of tendons
|
||||
int nwrap; // number of wrap objects in all tendon paths
|
||||
int nsensor; // number of sensors
|
||||
int nnumeric; // number of numeric custom fields
|
||||
int nnumericdata; // number of mjtNums in all numeric fields
|
||||
int ntext; // number of text custom fields
|
||||
int ntextdata; // number of mjtBytes in all text fields
|
||||
int ntuple; // number of tuple custom fields
|
||||
int ntupledata; // number of objects in all tuple fields
|
||||
int nkey; // number of keyframes
|
||||
int nmocap; // number of mocap bodies
|
||||
int nuser_body; // number of mjtNums in body_user
|
||||
int nuser_jnt; // number of mjtNums in jnt_user
|
||||
int nuser_geom; // number of mjtNums in geom_user
|
||||
int nuser_site; // number of mjtNums in site_user
|
||||
int nuser_cam; // number of mjtNums in cam_user
|
||||
int nuser_tendon; // number of mjtNums in tendon_user
|
||||
int nuser_actuator; // number of mjtNums in actuator_user
|
||||
int nuser_sensor; // number of mjtNums in sensor_user
|
||||
int nnames; // number of chars in all names
|
||||
|
||||
// sizes set after mjModel construction (only affect mjData)
|
||||
int nM; // number of non-zeros in sparse inertia matrix
|
||||
int nemax; // number of potential equality-constraint rows
|
||||
int njmax; // number of available rows in constraint Jacobian
|
||||
int nconmax; // number of potential contacts in contact list
|
||||
int nstack; // number of fields in mjData stack
|
||||
int nuserdata; // number of extra fields in mjData
|
||||
int nsensordata; // number of fields in sensor data vector
|
||||
|
||||
int nbuffer; // number of bytes in buffer
|
||||
|
||||
// ------------------------------- options and statistics
|
||||
|
||||
mjOption opt; // physics options
|
||||
mjVisual vis; // visualization options
|
||||
mjStatistic stat; // model statistics
|
||||
|
||||
// ------------------------------- buffers
|
||||
|
||||
// main buffer
|
||||
void* buffer; // main buffer; all pointers point in it (nbuffer)
|
||||
|
||||
// default generalized coordinates
|
||||
mjtNum* qpos0; // qpos values at default pose (nq x 1)
|
||||
mjtNum* qpos_spring; // reference pose for springs (nq x 1)
|
||||
|
||||
// bodies
|
||||
int* body_parentid; // id of body's parent (nbody x 1)
|
||||
int* body_rootid; // id of root above body (nbody x 1)
|
||||
int* body_weldid; // id of body that this body is welded to (nbody x 1)
|
||||
int* body_mocapid; // id of mocap data; -1: none (nbody x 1)
|
||||
int* body_jntnum; // number of joints for this body (nbody x 1)
|
||||
int* body_jntadr; // start addr of joints; -1: no joints (nbody x 1)
|
||||
int* body_dofnum; // number of motion degrees of freedom (nbody x 1)
|
||||
int* body_dofadr; // start addr of dofs; -1: no dofs (nbody x 1)
|
||||
int* body_geomnum; // number of geoms (nbody x 1)
|
||||
int* body_geomadr; // start addr of geoms; -1: no geoms (nbody x 1)
|
||||
mjtByte* body_simple; // body is simple (has diagonal M) (nbody x 1)
|
||||
mjtByte* body_sameframe; // inertial frame is same as body frame (nbody x 1)
|
||||
mjtNum* body_pos; // position offset rel. to parent body (nbody x 3)
|
||||
mjtNum* body_quat; // orientation offset rel. to parent body (nbody x 4)
|
||||
mjtNum* body_ipos; // local position of center of mass (nbody x 3)
|
||||
mjtNum* body_iquat; // local orientation of inertia ellipsoid (nbody x 4)
|
||||
mjtNum* body_mass; // mass (nbody x 1)
|
||||
mjtNum* body_subtreemass; // mass of subtree starting at this body (nbody x 1)
|
||||
mjtNum* body_inertia; // diagonal inertia in ipos/iquat frame (nbody x 3)
|
||||
mjtNum* body_invweight0; // mean inv inert in qpos0 (trn, rot) (nbody x 2)
|
||||
mjtNum* body_user; // user data (nbody x nuser_body)
|
||||
|
||||
// joints
|
||||
int* jnt_type; // type of joint (mjtJoint) (njnt x 1)
|
||||
int* jnt_qposadr; // start addr in 'qpos' for joint's data (njnt x 1)
|
||||
int* jnt_dofadr; // start addr in 'qvel' for joint's data (njnt x 1)
|
||||
int* jnt_bodyid; // id of joint's body (njnt x 1)
|
||||
int* jnt_group; // group for visibility (njnt x 1)
|
||||
mjtByte* jnt_limited; // does joint have limits (njnt x 1)
|
||||
mjtNum* jnt_solref; // constraint solver reference: limit (njnt x mjNREF)
|
||||
mjtNum* jnt_solimp; // constraint solver impedance: limit (njnt x mjNIMP)
|
||||
mjtNum* jnt_pos; // local anchor position (njnt x 3)
|
||||
mjtNum* jnt_axis; // local joint axis (njnt x 3)
|
||||
mjtNum* jnt_stiffness; // stiffness coefficient (njnt x 1)
|
||||
mjtNum* jnt_range; // joint limits (njnt x 2)
|
||||
mjtNum* jnt_margin; // min distance for limit detection (njnt x 1)
|
||||
mjtNum* jnt_user; // user data (njnt x nuser_jnt)
|
||||
|
||||
// dofs
|
||||
int* dof_bodyid; // id of dof's body (nv x 1)
|
||||
int* dof_jntid; // id of dof's joint (nv x 1)
|
||||
int* dof_parentid; // id of dof's parent; -1: none (nv x 1)
|
||||
int* dof_Madr; // dof address in M-diagonal (nv x 1)
|
||||
int* dof_simplenum; // number of consecutive simple dofs (nv x 1)
|
||||
mjtNum* dof_solref; // constraint solver reference:frictionloss (nv x mjNREF)
|
||||
mjtNum* dof_solimp; // constraint solver impedance:frictionloss (nv x mjNIMP)
|
||||
mjtNum* dof_frictionloss; // dof friction loss (nv x 1)
|
||||
mjtNum* dof_armature; // dof armature inertia/mass (nv x 1)
|
||||
mjtNum* dof_damping; // damping coefficient (nv x 1)
|
||||
mjtNum* dof_invweight0; // diag. inverse inertia in qpos0 (nv x 1)
|
||||
mjtNum* dof_M0; // diag. inertia in qpos0 (nv x 1)
|
||||
|
||||
// geoms
|
||||
int* geom_type; // geometric type (mjtGeom) (ngeom x 1)
|
||||
int* geom_contype; // geom contact type (ngeom x 1)
|
||||
int* geom_conaffinity; // geom contact affinity (ngeom x 1)
|
||||
int* geom_condim; // contact dimensionality (1, 3, 4, 6) (ngeom x 1)
|
||||
int* geom_bodyid; // id of geom's body (ngeom x 1)
|
||||
int* geom_dataid; // id of geom's mesh/hfield (-1: none) (ngeom x 1)
|
||||
int* geom_matid; // material id for rendering (ngeom x 1)
|
||||
int* geom_group; // group for visibility (ngeom x 1)
|
||||
int* geom_priority; // geom contact priority (ngeom x 1)
|
||||
mjtByte* geom_sameframe; // same as body frame (1) or iframe (2) (ngeom x 1)
|
||||
mjtNum* geom_solmix; // mixing coef for solref/imp in geom pair (ngeom x 1)
|
||||
mjtNum* geom_solref; // constraint solver reference: contact (ngeom x mjNREF)
|
||||
mjtNum* geom_solimp; // constraint solver impedance: contact (ngeom x mjNIMP)
|
||||
mjtNum* geom_size; // geom-specific size parameters (ngeom x 3)
|
||||
mjtNum* geom_rbound; // radius of bounding sphere (ngeom x 1)
|
||||
mjtNum* geom_pos; // local position offset rel. to body (ngeom x 3)
|
||||
mjtNum* geom_quat; // local orientation offset rel. to body (ngeom x 4)
|
||||
mjtNum* geom_friction; // friction for (slide, spin, roll) (ngeom x 3)
|
||||
mjtNum* geom_margin; // detect contact if dist<margin (ngeom x 1)
|
||||
mjtNum* geom_gap; // include in solver if dist<margin-gap (ngeom x 1)
|
||||
mjtNum* geom_user; // user data (ngeom x nuser_geom)
|
||||
float* geom_rgba; // rgba when material is omitted (ngeom x 4)
|
||||
|
||||
// sites
|
||||
int* site_type; // geom type for rendering (mjtGeom) (nsite x 1)
|
||||
int* site_bodyid; // id of site's body (nsite x 1)
|
||||
int* site_matid; // material id for rendering (nsite x 1)
|
||||
int* site_group; // group for visibility (nsite x 1)
|
||||
mjtByte* site_sameframe; // same as body frame (1) or iframe (2) (nsite x 1)
|
||||
mjtNum* site_size; // geom size for rendering (nsite x 3)
|
||||
mjtNum* site_pos; // local position offset rel. to body (nsite x 3)
|
||||
mjtNum* site_quat; // local orientation offset rel. to body (nsite x 4)
|
||||
mjtNum* site_user; // user data (nsite x nuser_site)
|
||||
float* site_rgba; // rgba when material is omitted (nsite x 4)
|
||||
|
||||
// cameras
|
||||
int* cam_mode; // camera tracking mode (mjtCamLight) (ncam x 1)
|
||||
int* cam_bodyid; // id of camera's body (ncam x 1)
|
||||
int* cam_targetbodyid; // id of targeted body; -1: none (ncam x 1)
|
||||
mjtNum* cam_pos; // position rel. to body frame (ncam x 3)
|
||||
mjtNum* cam_quat; // orientation rel. to body frame (ncam x 4)
|
||||
mjtNum* cam_poscom0; // global position rel. to sub-com in qpos0 (ncam x 3)
|
||||
mjtNum* cam_pos0; // global position rel. to body in qpos0 (ncam x 3)
|
||||
mjtNum* cam_mat0; // global orientation in qpos0 (ncam x 9)
|
||||
mjtNum* cam_fovy; // y-field of view (deg) (ncam x 1)
|
||||
mjtNum* cam_ipd; // inter-pupilary distance (ncam x 1)
|
||||
mjtNum* cam_user; // user data (ncam x nuser_cam)
|
||||
|
||||
// lights
|
||||
int* light_mode; // light tracking mode (mjtCamLight) (nlight x 1)
|
||||
int* light_bodyid; // id of light's body (nlight x 1)
|
||||
int* light_targetbodyid; // id of targeted body; -1: none (nlight x 1)
|
||||
mjtByte* light_directional; // directional light (nlight x 1)
|
||||
mjtByte* light_castshadow; // does light cast shadows (nlight x 1)
|
||||
mjtByte* light_active; // is light on (nlight x 1)
|
||||
mjtNum* light_pos; // position rel. to body frame (nlight x 3)
|
||||
mjtNum* light_dir; // direction rel. to body frame (nlight x 3)
|
||||
mjtNum* light_poscom0; // global position rel. to sub-com in qpos0 (nlight x 3)
|
||||
mjtNum* light_pos0; // global position rel. to body in qpos0 (nlight x 3)
|
||||
mjtNum* light_dir0; // global direction in qpos0 (nlight x 3)
|
||||
float* light_attenuation; // OpenGL attenuation (quadratic model) (nlight x 3)
|
||||
float* light_cutoff; // OpenGL cutoff (nlight x 1)
|
||||
float* light_exponent; // OpenGL exponent (nlight x 1)
|
||||
float* light_ambient; // ambient rgb (alpha=1) (nlight x 3)
|
||||
float* light_diffuse; // diffuse rgb (alpha=1) (nlight x 3)
|
||||
float* light_specular; // specular rgb (alpha=1) (nlight x 3)
|
||||
|
||||
// meshes
|
||||
int* mesh_vertadr; // first vertex address (nmesh x 1)
|
||||
int* mesh_vertnum; // number of vertices (nmesh x 1)
|
||||
int* mesh_texcoordadr; // texcoord data address; -1: no texcoord (nmesh x 1)
|
||||
int* mesh_faceadr; // first face address (nmesh x 1)
|
||||
int* mesh_facenum; // number of faces (nmesh x 1)
|
||||
int* mesh_graphadr; // graph data address; -1: no graph (nmesh x 1)
|
||||
float* mesh_vert; // vertex positions for all meshe (nmeshvert x 3)
|
||||
float* mesh_normal; // vertex normals for all meshes (nmeshvert x 3)
|
||||
float* mesh_texcoord; // vertex texcoords for all meshes (nmeshtexvert x 2)
|
||||
int* mesh_face; // triangle face data (nmeshface x 3)
|
||||
int* mesh_graph; // convex graph data (nmeshgraph x 1)
|
||||
|
||||
// skins
|
||||
int* skin_matid; // skin material id; -1: none (nskin x 1)
|
||||
float* skin_rgba; // skin rgba (nskin x 4)
|
||||
float* skin_inflate; // inflate skin in normal direction (nskin x 1)
|
||||
int* skin_vertadr; // first vertex address (nskin x 1)
|
||||
int* skin_vertnum; // number of vertices (nskin x 1)
|
||||
int* skin_texcoordadr; // texcoord data address; -1: no texcoord (nskin x 1)
|
||||
int* skin_faceadr; // first face address (nskin x 1)
|
||||
int* skin_facenum; // number of faces (nskin x 1)
|
||||
int* skin_boneadr; // first bone in skin (nskin x 1)
|
||||
int* skin_bonenum; // number of bones in skin (nskin x 1)
|
||||
float* skin_vert; // vertex positions for all skin meshes (nskinvert x 3)
|
||||
float* skin_texcoord; // vertex texcoords for all skin meshes (nskintexvert x 2)
|
||||
int* skin_face; // triangle faces for all skin meshes (nskinface x 3)
|
||||
int* skin_bonevertadr; // first vertex in each bone (nskinbone x 1)
|
||||
int* skin_bonevertnum; // number of vertices in each bone (nskinbone x 1)
|
||||
float* skin_bonebindpos; // bind pos of each bone (nskinbone x 3)
|
||||
float* skin_bonebindquat; // bind quat of each bone (nskinbone x 4)
|
||||
int* skin_bonebodyid; // body id of each bone (nskinbone x 1)
|
||||
int* skin_bonevertid; // mesh ids of vertices in each bone (nskinbonevert x 1)
|
||||
float* skin_bonevertweight; // weights of vertices in each bone (nskinbonevert x 1)
|
||||
|
||||
// height fields
|
||||
mjtNum* hfield_size; // (x, y, z_top, z_bottom) (nhfield x 4)
|
||||
int* hfield_nrow; // number of rows in grid (nhfield x 1)
|
||||
int* hfield_ncol; // number of columns in grid (nhfield x 1)
|
||||
int* hfield_adr; // address in hfield_data (nhfield x 1)
|
||||
float* hfield_data; // elevation data (nhfielddata x 1)
|
||||
|
||||
// textures
|
||||
int* tex_type; // texture type (mjtTexture) (ntex x 1)
|
||||
int* tex_height; // number of rows in texture image (ntex x 1)
|
||||
int* tex_width; // number of columns in texture image (ntex x 1)
|
||||
int* tex_adr; // address in rgb (ntex x 1)
|
||||
mjtByte* tex_rgb; // rgb (alpha = 1) (ntexdata x 1)
|
||||
|
||||
// materials
|
||||
int* mat_texid; // texture id; -1: none (nmat x 1)
|
||||
mjtByte* mat_texuniform; // make texture cube uniform (nmat x 1)
|
||||
float* mat_texrepeat; // texture repetition for 2d mapping (nmat x 2)
|
||||
float* mat_emission; // emission (x rgb) (nmat x 1)
|
||||
float* mat_specular; // specular (x white) (nmat x 1)
|
||||
float* mat_shininess; // shininess coef (nmat x 1)
|
||||
float* mat_reflectance; // reflectance (0: disable) (nmat x 1)
|
||||
float* mat_rgba; // rgba (nmat x 4)
|
||||
|
||||
// predefined geom pairs for collision detection; has precedence over exclude
|
||||
int* pair_dim; // contact dimensionality (npair x 1)
|
||||
int* pair_geom1; // id of geom1 (npair x 1)
|
||||
int* pair_geom2; // id of geom2 (npair x 1)
|
||||
int* pair_signature; // (body1+1)<<16 + body2+1 (npair x 1)
|
||||
mjtNum* pair_solref; // constraint solver reference: contact (npair x mjNREF)
|
||||
mjtNum* pair_solimp; // constraint solver impedance: contact (npair x mjNIMP)
|
||||
mjtNum* pair_margin; // detect contact if dist<margin (npair x 1)
|
||||
mjtNum* pair_gap; // include in solver if dist<margin-gap (npair x 1)
|
||||
mjtNum* pair_friction; // tangent1, 2, spin, roll1, 2 (npair x 5)
|
||||
|
||||
// excluded body pairs for collision detection
|
||||
int* exclude_signature; // (body1+1)<<16 + body2+1 (nexclude x 1)
|
||||
|
||||
// equality constraints
|
||||
int* eq_type; // constraint type (mjtEq) (neq x 1)
|
||||
int* eq_obj1id; // id of object 1 (neq x 1)
|
||||
int* eq_obj2id; // id of object 2 (neq x 1)
|
||||
mjtByte* eq_active; // enable/disable constraint (neq x 1)
|
||||
mjtNum* eq_solref; // constraint solver reference (neq x mjNREF)
|
||||
mjtNum* eq_solimp; // constraint solver impedance (neq x mjNIMP)
|
||||
mjtNum* eq_data; // numeric data for constraint (neq x mjNEQDATA)
|
||||
|
||||
// tendons
|
||||
int* tendon_adr; // address of first object in tendon's path (ntendon x 1)
|
||||
int* tendon_num; // number of objects in tendon's path (ntendon x 1)
|
||||
int* tendon_matid; // material id for rendering (ntendon x 1)
|
||||
int* tendon_group; // group for visibility (ntendon x 1)
|
||||
mjtByte* tendon_limited; // does tendon have length limits (ntendon x 1)
|
||||
mjtNum* tendon_width; // width for rendering (ntendon x 1)
|
||||
mjtNum* tendon_solref_lim; // constraint solver reference: limit (ntendon x mjNREF)
|
||||
mjtNum* tendon_solimp_lim; // constraint solver impedance: limit (ntendon x mjNIMP)
|
||||
mjtNum* tendon_solref_fri; // constraint solver reference: friction (ntendon x mjNREF)
|
||||
mjtNum* tendon_solimp_fri; // constraint solver impedance: friction (ntendon x mjNIMP)
|
||||
mjtNum* tendon_range; // tendon length limits (ntendon x 2)
|
||||
mjtNum* tendon_margin; // min distance for limit detection (ntendon x 1)
|
||||
mjtNum* tendon_stiffness; // stiffness coefficient (ntendon x 1)
|
||||
mjtNum* tendon_damping; // damping coefficient (ntendon x 1)
|
||||
mjtNum* tendon_frictionloss; // loss due to friction (ntendon x 1)
|
||||
mjtNum* tendon_lengthspring; // tendon length in qpos_spring (ntendon x 1)
|
||||
mjtNum* tendon_length0; // tendon length in qpos0 (ntendon x 1)
|
||||
mjtNum* tendon_invweight0; // inv. weight in qpos0 (ntendon x 1)
|
||||
mjtNum* tendon_user; // user data (ntendon x nuser_tendon)
|
||||
float* tendon_rgba; // rgba when material is omitted (ntendon x 4)
|
||||
|
||||
// list of all wrap objects in tendon paths
|
||||
int* wrap_type; // wrap object type (mjtWrap) (nwrap x 1)
|
||||
int* wrap_objid; // object id: geom, site, joint (nwrap x 1)
|
||||
mjtNum* wrap_prm; // divisor, joint coef, or site id (nwrap x 1)
|
||||
|
||||
// actuators
|
||||
int* actuator_trntype; // transmission type (mjtTrn) (nu x 1)
|
||||
int* actuator_dyntype; // dynamics type (mjtDyn) (nu x 1)
|
||||
int* actuator_gaintype; // gain type (mjtGain) (nu x 1)
|
||||
int* actuator_biastype; // bias type (mjtBias) (nu x 1)
|
||||
int* actuator_trnid; // transmission id: joint, tendon, site (nu x 2)
|
||||
int* actuator_group; // group for visibility (nu x 1)
|
||||
mjtByte* actuator_ctrllimited; // is control limited (nu x 1)
|
||||
mjtByte* actuator_forcelimited;// is force limited (nu x 1)
|
||||
mjtNum* actuator_dynprm; // dynamics parameters (nu x mjNDYN)
|
||||
mjtNum* actuator_gainprm; // gain parameters (nu x mjNGAIN)
|
||||
mjtNum* actuator_biasprm; // bias parameters (nu x mjNBIAS)
|
||||
mjtNum* actuator_ctrlrange; // range of controls (nu x 2)
|
||||
mjtNum* actuator_forcerange; // range of forces (nu x 2)
|
||||
mjtNum* actuator_gear; // scale length and transmitted force (nu x 6)
|
||||
mjtNum* actuator_cranklength; // crank length for slider-crank (nu x 1)
|
||||
mjtNum* actuator_acc0; // acceleration from unit force in qpos0 (nu x 1)
|
||||
mjtNum* actuator_length0; // actuator length in qpos0 (nu x 1)
|
||||
mjtNum* actuator_lengthrange; // feasible actuator length range (nu x 2)
|
||||
mjtNum* actuator_user; // user data (nu x nuser_actuator)
|
||||
|
||||
// sensors
|
||||
int* sensor_type; // sensor type (mjtSensor) (nsensor x 1)
|
||||
int* sensor_datatype; // numeric data type (mjtDataType) (nsensor x 1)
|
||||
int* sensor_needstage; // required compute stage (mjtStage) (nsensor x 1)
|
||||
int* sensor_objtype; // type of sensorized object (mjtObj) (nsensor x 1)
|
||||
int* sensor_objid; // id of sensorized object (nsensor x 1)
|
||||
int* sensor_dim; // number of scalar outputs (nsensor x 1)
|
||||
int* sensor_adr; // address in sensor array (nsensor x 1)
|
||||
mjtNum* sensor_cutoff; // cutoff for real and positive; 0: ignore (nsensor x 1)
|
||||
mjtNum* sensor_noise; // noise standard deviation (nsensor x 1)
|
||||
mjtNum* sensor_user; // user data (nsensor x nuser_sensor)
|
||||
|
||||
// custom numeric fields
|
||||
int* numeric_adr; // address of field in numeric_data (nnumeric x 1)
|
||||
int* numeric_size; // size of numeric field (nnumeric x 1)
|
||||
mjtNum* numeric_data; // array of all numeric fields (nnumericdata x 1)
|
||||
|
||||
// custom text fields
|
||||
int* text_adr; // address of text in text_data (ntext x 1)
|
||||
int* text_size; // size of text field (strlen+1) (ntext x 1)
|
||||
char* text_data; // array of all text fields (0-terminated) (ntextdata x 1)
|
||||
|
||||
// custom tuple fields
|
||||
int* tuple_adr; // address of text in text_data (ntuple x 1)
|
||||
int* tuple_size; // number of objects in tuple (ntuple x 1)
|
||||
int* tuple_objtype; // array of object types in all tuples (ntupledata x 1)
|
||||
int* tuple_objid; // array of object ids in all tuples (ntupledata x 1)
|
||||
mjtNum* tuple_objprm; // array of object params in all tuples (ntupledata x 1)
|
||||
|
||||
// keyframes
|
||||
mjtNum* key_time; // key time (nkey x 1)
|
||||
mjtNum* key_qpos; // key position (nkey x nq)
|
||||
mjtNum* key_qvel; // key velocity (nkey x nv)
|
||||
mjtNum* key_act; // key activation (nkey x na)
|
||||
mjtNum* key_mpos; // key mocap position (nkey x 3*nmocap)
|
||||
mjtNum* key_mquat; // key mocap quaternion (nkey x 4*nmocap)
|
||||
|
||||
// names
|
||||
int* name_bodyadr; // body name pointers (nbody x 1)
|
||||
int* name_jntadr; // joint name pointers (njnt x 1)
|
||||
int* name_geomadr; // geom name pointers (ngeom x 1)
|
||||
int* name_siteadr; // site name pointers (nsite x 1)
|
||||
int* name_camadr; // camera name pointers (ncam x 1)
|
||||
int* name_lightadr; // light name pointers (nlight x 1)
|
||||
int* name_meshadr; // mesh name pointers (nmesh x 1)
|
||||
int* name_skinadr; // skin name pointers (nskin x 1)
|
||||
int* name_hfieldadr; // hfield name pointers (nhfield x 1)
|
||||
int* name_texadr; // texture name pointers (ntex x 1)
|
||||
int* name_matadr; // material name pointers (nmat x 1)
|
||||
int* name_pairadr; // geom pair name pointers (npair x 1)
|
||||
int* name_excludeadr; // exclude name pointers (nexclude x 1)
|
||||
int* name_eqadr; // equality constraint name pointers (neq x 1)
|
||||
int* name_tendonadr; // tendon name pointers (ntendon x 1)
|
||||
int* name_actuatoradr; // actuator name pointers (nu x 1)
|
||||
int* name_sensoradr; // sensor name pointers (nsensor x 1)
|
||||
int* name_numericadr; // numeric name pointers (nnumeric x 1)
|
||||
int* name_textadr; // text name pointers (ntext x 1)
|
||||
int* name_tupleadr; // tuple name pointers (ntuple x 1)
|
||||
int* name_keyadr; // keyframe name pointers (nkey x 1)
|
||||
char* names; // names of all objects, 0-terminated (nnames x 1)
|
||||
};
|
||||
typedef struct _mjModel mjModel;
|
||||
|
||||
#endif // MUJOCO_MJMODEL_H_
|
||||
Executable
+151
@@ -0,0 +1,151 @@
|
||||
// Copyright 2021 DeepMind Technologies Limited
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef MUJOCO_MJRENDER_H_
|
||||
#define MUJOCO_MJRENDER_H_
|
||||
|
||||
#define mjNAUX 10 // number of auxiliary buffers
|
||||
#define mjMAXTEXTURE 1000 // maximum number of textures
|
||||
|
||||
|
||||
typedef enum _mjtGridPos // grid position for overlay
|
||||
{
|
||||
mjGRID_TOPLEFT = 0, // top left
|
||||
mjGRID_TOPRIGHT, // top right
|
||||
mjGRID_BOTTOMLEFT, // bottom left
|
||||
mjGRID_BOTTOMRIGHT // bottom right
|
||||
} mjtGridPos;
|
||||
|
||||
|
||||
typedef enum _mjtFramebuffer // OpenGL framebuffer option
|
||||
{
|
||||
mjFB_WINDOW = 0, // default/window buffer
|
||||
mjFB_OFFSCREEN // offscreen buffer
|
||||
} mjtFramebuffer;
|
||||
|
||||
|
||||
typedef enum _mjtFontScale // font scale, used at context creation
|
||||
{
|
||||
mjFONTSCALE_50 = 50, // 50% scale, suitable for low-res rendering
|
||||
mjFONTSCALE_100 = 100, // normal scale, suitable in the absence of DPI scaling
|
||||
mjFONTSCALE_150 = 150, // 150% scale
|
||||
mjFONTSCALE_200 = 200, // 200% scale
|
||||
mjFONTSCALE_250 = 250, // 250% scale
|
||||
mjFONTSCALE_300 = 300 // 300% scale
|
||||
} mjtFontScale;
|
||||
|
||||
|
||||
typedef enum _mjtFont // font type, used at each text operation
|
||||
{
|
||||
mjFONT_NORMAL = 0, // normal font
|
||||
mjFONT_SHADOW, // normal font with shadow (for higher contrast)
|
||||
mjFONT_BIG // big font (for user alerts)
|
||||
} mjtFont;
|
||||
|
||||
|
||||
struct _mjrRect // OpenGL rectangle
|
||||
{
|
||||
int left; // left (usually 0)
|
||||
int bottom; // bottom (usually 0)
|
||||
int width; // width (usually buffer width)
|
||||
int height; // height (usually buffer height)
|
||||
};
|
||||
typedef struct _mjrRect mjrRect;
|
||||
|
||||
|
||||
struct _mjrContext // custom OpenGL context
|
||||
{
|
||||
// parameters copied from mjVisual
|
||||
float lineWidth; // line width for wireframe rendering
|
||||
float shadowClip; // clipping radius for directional lights
|
||||
float shadowScale; // fraction of light cutoff for spot lights
|
||||
float fogStart; // fog start = stat.extent * vis.map.fogstart
|
||||
float fogEnd; // fog end = stat.extent * vis.map.fogend
|
||||
float fogRGBA[4]; // fog rgba
|
||||
int shadowSize; // size of shadow map texture
|
||||
int offWidth; // width of offscreen buffer
|
||||
int offHeight; // height of offscreen buffer
|
||||
int offSamples; // number of offscreen buffer multisamples
|
||||
|
||||
// parameters specified at creation
|
||||
int fontScale; // font scale
|
||||
int auxWidth[mjNAUX]; // auxiliary buffer width
|
||||
int auxHeight[mjNAUX]; // auxiliary buffer height
|
||||
int auxSamples[mjNAUX]; // auxiliary buffer multisamples
|
||||
|
||||
// offscreen rendering objects
|
||||
unsigned int offFBO; // offscreen framebuffer object
|
||||
unsigned int offFBO_r; // offscreen framebuffer for resolving multisamples
|
||||
unsigned int offColor; // offscreen color buffer
|
||||
unsigned int offColor_r; // offscreen color buffer for resolving multisamples
|
||||
unsigned int offDepthStencil; // offscreen depth and stencil buffer
|
||||
unsigned int offDepthStencil_r; // offscreen depth and stencil buffer for resolving multisamples
|
||||
|
||||
// shadow rendering objects
|
||||
unsigned int shadowFBO; // shadow map framebuffer object
|
||||
unsigned int shadowTex; // shadow map texture
|
||||
|
||||
// auxiliary buffers
|
||||
unsigned int auxFBO[mjNAUX]; // auxiliary framebuffer object
|
||||
unsigned int auxFBO_r[mjNAUX]; // auxiliary framebuffer object for resolving
|
||||
unsigned int auxColor[mjNAUX]; // auxiliary color buffer
|
||||
unsigned int auxColor_r[mjNAUX];// auxiliary color buffer for resolving
|
||||
|
||||
// texture objects and info
|
||||
int ntexture; // number of allocated textures
|
||||
int textureType[100]; // type of texture (mjtTexture)
|
||||
unsigned int texture[100]; // texture names
|
||||
|
||||
// displaylist starting positions
|
||||
unsigned int basePlane; // all planes from model
|
||||
unsigned int baseMesh; // all meshes from model
|
||||
unsigned int baseHField; // all hfields from model
|
||||
unsigned int baseBuiltin; // all buildin geoms, with quality from model
|
||||
unsigned int baseFontNormal; // normal font
|
||||
unsigned int baseFontShadow; // shadow font
|
||||
unsigned int baseFontBig; // big font
|
||||
|
||||
// displaylist ranges
|
||||
int rangePlane; // all planes from model
|
||||
int rangeMesh; // all meshes from model
|
||||
int rangeHField; // all hfields from model
|
||||
int rangeBuiltin; // all builtin geoms, with quality from model
|
||||
int rangeFont; // all characters in font
|
||||
|
||||
// skin VBOs
|
||||
int nskin; // number of skins
|
||||
unsigned int* skinvertVBO; // skin vertex position VBOs
|
||||
unsigned int* skinnormalVBO; // skin vertex normal VBOs
|
||||
unsigned int* skintexcoordVBO; // skin vertex texture coordinate VBOs
|
||||
unsigned int* skinfaceVBO; // skin face index VBOs
|
||||
|
||||
// character info
|
||||
int charWidth[127]; // character widths: normal and shadow
|
||||
int charWidthBig[127]; // chacarter widths: big
|
||||
int charHeight; // character heights: normal and shadow
|
||||
int charHeightBig; // character heights: big
|
||||
|
||||
// capabilities
|
||||
int glewInitialized; // is glew initialized
|
||||
int windowAvailable; // is default/window framebuffer available
|
||||
int windowSamples; // number of samples for default/window framebuffer
|
||||
int windowStereo; // is stereo available for default/window framebuffer
|
||||
int windowDoublebuffer; // is default/window framebuffer double buffered
|
||||
|
||||
// framebuffer
|
||||
int currentBuffer; // currently active framebuffer: mjFB_WINDOW or mjFB_OFFSCREEN
|
||||
};
|
||||
typedef struct _mjrContext mjrContext;
|
||||
|
||||
#endif // MUJOCO_MJRENDER_H_
|
||||
Executable
+309
@@ -0,0 +1,309 @@
|
||||
// Copyright 2021 DeepMind Technologies Limited
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef MUJOCO_MJUI_H_
|
||||
#define MUJOCO_MJUI_H_
|
||||
|
||||
#define mjMAXUISECT 10 // maximum number of sections
|
||||
#define mjMAXUIITEM 80 // maximum number of items per section
|
||||
#define mjMAXUITEXT 300 // maximum number of chars in edittext and other
|
||||
#define mjMAXUINAME 40 // maximum number of chars in name
|
||||
#define mjMAXUIMULTI 35 // maximum number of radio/select items in group
|
||||
#define mjMAXUIEDIT 7 // maximum number of elements in edit list
|
||||
#define mjMAXUIRECT 25 // maximum number of rectangles
|
||||
|
||||
#define mjSEPCLOSED 1000 // closed state of adjustable separator
|
||||
|
||||
|
||||
// key codes matching GLFW (user must remap for other frameworks)
|
||||
#define mjKEY_ESCAPE 256
|
||||
#define mjKEY_ENTER 257
|
||||
#define mjKEY_TAB 258
|
||||
#define mjKEY_BACKSPACE 259
|
||||
#define mjKEY_INSERT 260
|
||||
#define mjKEY_DELETE 261
|
||||
#define mjKEY_RIGHT 262
|
||||
#define mjKEY_LEFT 263
|
||||
#define mjKEY_DOWN 264
|
||||
#define mjKEY_UP 265
|
||||
#define mjKEY_PAGE_UP 266
|
||||
#define mjKEY_PAGE_DOWN 267
|
||||
#define mjKEY_HOME 268
|
||||
#define mjKEY_END 269
|
||||
#define mjKEY_F1 290
|
||||
#define mjKEY_F2 291
|
||||
#define mjKEY_F3 292
|
||||
#define mjKEY_F4 293
|
||||
#define mjKEY_F5 294
|
||||
#define mjKEY_F6 295
|
||||
#define mjKEY_F7 296
|
||||
#define mjKEY_F8 297
|
||||
#define mjKEY_F9 298
|
||||
#define mjKEY_F10 299
|
||||
#define mjKEY_F11 300
|
||||
#define mjKEY_F12 301
|
||||
|
||||
|
||||
typedef enum _mjtButton // mouse button
|
||||
{
|
||||
mjBUTTON_NONE = 0, // no button
|
||||
mjBUTTON_LEFT, // left button
|
||||
mjBUTTON_RIGHT, // right button
|
||||
mjBUTTON_MIDDLE // middle button
|
||||
} mjtButton;
|
||||
|
||||
|
||||
typedef enum _mjtEvent // mouse and keyboard event type
|
||||
{
|
||||
mjEVENT_NONE = 0, // no event
|
||||
mjEVENT_MOVE, // mouse move
|
||||
mjEVENT_PRESS, // mouse button press
|
||||
mjEVENT_RELEASE, // mouse button release
|
||||
mjEVENT_SCROLL, // scroll
|
||||
mjEVENT_KEY, // key press
|
||||
mjEVENT_RESIZE // resize
|
||||
} mjtEvent;
|
||||
|
||||
|
||||
typedef enum _mjtItem // UI item type
|
||||
{
|
||||
mjITEM_END = -2, // end of definition list (not an item)
|
||||
mjITEM_SECTION = -1, // section (not an item)
|
||||
mjITEM_SEPARATOR = 0, // separator
|
||||
mjITEM_STATIC, // static text
|
||||
mjITEM_BUTTON, // button
|
||||
|
||||
// the rest have data pointer
|
||||
mjITEM_CHECKINT, // check box, int value
|
||||
mjITEM_CHECKBYTE, // check box, mjtByte value
|
||||
mjITEM_RADIO, // radio group
|
||||
mjITEM_RADIOLINE, // radio group, single line
|
||||
mjITEM_SELECT, // selection box
|
||||
mjITEM_SLIDERINT, // slider, int value
|
||||
mjITEM_SLIDERNUM, // slider, mjtNum value
|
||||
mjITEM_EDITINT, // editable array, int values
|
||||
mjITEM_EDITNUM, // editable array, mjtNum values
|
||||
mjITEM_EDITTXT, // editable text
|
||||
|
||||
mjNITEM // number of item types
|
||||
} mjtItem;
|
||||
|
||||
|
||||
// predicate function: set enable/disable based on item category
|
||||
typedef int (*mjfItemEnable)(int category, void* data);
|
||||
|
||||
|
||||
struct _mjuiState // mouse and keyboard state
|
||||
{
|
||||
// constants set by user
|
||||
int nrect; // number of rectangles used
|
||||
mjrRect rect[mjMAXUIRECT]; // rectangles (index 0: entire window)
|
||||
void* userdata; // pointer to user data (for callbacks)
|
||||
|
||||
// event type
|
||||
int type; // (type mjtEvent)
|
||||
|
||||
// mouse buttons
|
||||
int left; // is left button down
|
||||
int right; // is right button down
|
||||
int middle; // is middle button down
|
||||
int doubleclick; // is last press a double click
|
||||
int button; // which button was pressed (mjtButton)
|
||||
double buttontime; // time of last button press
|
||||
|
||||
// mouse position
|
||||
double x; // x position
|
||||
double y; // y position
|
||||
double dx; // x displacement
|
||||
double dy; // y displacement
|
||||
double sx; // x scroll
|
||||
double sy; // y scroll
|
||||
|
||||
// keyboard
|
||||
int control; // is control down
|
||||
int shift; // is shift down
|
||||
int alt; // is alt down
|
||||
int key; // which key was pressed
|
||||
double keytime; // time of last key press
|
||||
|
||||
// rectangle ownership and dragging
|
||||
int mouserect; // which rectangle contains mouse
|
||||
int dragrect; // which rectangle is dragged with mouse
|
||||
int dragbutton; // which button started drag (mjtButton)
|
||||
};
|
||||
typedef struct _mjuiState mjuiState;
|
||||
|
||||
|
||||
struct _mjuiThemeSpacing // UI visualization theme spacing
|
||||
{
|
||||
int total; // total width
|
||||
int scroll; // scrollbar width
|
||||
int label; // label width
|
||||
int section; // section gap
|
||||
int itemside; // item side gap
|
||||
int itemmid; // item middle gap
|
||||
int itemver; // item vertical gap
|
||||
int texthor; // text horizontal gap
|
||||
int textver; // text vertical gap
|
||||
int linescroll; // number of pixels to scroll
|
||||
int samples; // number of multisamples
|
||||
};
|
||||
typedef struct _mjuiThemeSpacing mjuiThemeSpacing;
|
||||
|
||||
|
||||
struct _mjuiThemeColor // UI visualization theme color
|
||||
{
|
||||
float master[3]; // master background
|
||||
float thumb[3]; // scrollbar thumb
|
||||
float secttitle[3]; // section title
|
||||
float sectfont[3]; // section font
|
||||
float sectsymbol[3]; // section symbol
|
||||
float sectpane[3]; // section pane
|
||||
float shortcut[3]; // shortcut background
|
||||
float fontactive[3]; // font active
|
||||
float fontinactive[3]; // font inactive
|
||||
float decorinactive[3]; // decor inactive
|
||||
float decorinactive2[3]; // inactive slider color 2
|
||||
float button[3]; // button
|
||||
float check[3]; // check
|
||||
float radio[3]; // radio
|
||||
float select[3]; // select
|
||||
float select2[3]; // select pane
|
||||
float slider[3]; // slider
|
||||
float slider2[3]; // slider color 2
|
||||
float edit[3]; // edit
|
||||
float edit2[3]; // edit invalid
|
||||
float cursor[3]; // edit cursor
|
||||
};
|
||||
typedef struct _mjuiThemeColor mjuiThemeColor;
|
||||
|
||||
|
||||
struct _mjuiItemSingle // check and button-related
|
||||
{
|
||||
int modifier; // 0: none, 1: control, 2: shift; 4: alt
|
||||
int shortcut; // shortcut key; 0: undefined
|
||||
};
|
||||
|
||||
|
||||
struct _mjuiItemMulti // static, radio and select-related
|
||||
{
|
||||
int nelem; // number of elements in group
|
||||
char name[mjMAXUIMULTI][mjMAXUINAME]; // element names
|
||||
};
|
||||
|
||||
|
||||
struct _mjuiItemSlider // slider-related
|
||||
{
|
||||
double range[2]; // slider range
|
||||
double divisions; // number of range divisions
|
||||
};
|
||||
|
||||
|
||||
struct _mjuiItemEdit // edit-related
|
||||
{
|
||||
int nelem; // number of elements in list
|
||||
double range[mjMAXUIEDIT][2]; // element range (min>=max: ignore)
|
||||
};
|
||||
|
||||
|
||||
struct _mjuiItem // UI item
|
||||
{
|
||||
// common properties
|
||||
int type; // type (mjtItem)
|
||||
char name[mjMAXUINAME]; // name
|
||||
int state; // 0: disable, 1: enable, 2+: use predicate
|
||||
void *pdata; // data pointer (type-specific)
|
||||
int sectionid; // id of section containing item
|
||||
int itemid; // id of item within section
|
||||
|
||||
// type-specific properties
|
||||
union
|
||||
{
|
||||
struct _mjuiItemSingle single; // check and button
|
||||
struct _mjuiItemMulti multi; // static, radio and select
|
||||
struct _mjuiItemSlider slider; // slider
|
||||
struct _mjuiItemEdit edit; // edit
|
||||
};
|
||||
|
||||
// internal
|
||||
mjrRect rect; // rectangle occupied by item
|
||||
};
|
||||
typedef struct _mjuiItem mjuiItem;
|
||||
|
||||
|
||||
struct _mjuiSection // UI section
|
||||
{
|
||||
// properties
|
||||
char name[mjMAXUINAME]; // name
|
||||
int state; // 0: closed, 1: open
|
||||
int modifier; // 0: none, 1: control, 2: shift; 4: alt
|
||||
int shortcut; // shortcut key; 0: undefined
|
||||
int nitem; // number of items in use
|
||||
mjuiItem item[mjMAXUIITEM]; // preallocated array of items
|
||||
|
||||
// internal
|
||||
mjrRect rtitle; // rectangle occupied by title
|
||||
mjrRect rcontent; // rectangle occupied by content
|
||||
};
|
||||
typedef struct _mjuiSection mjuiSection;
|
||||
|
||||
|
||||
struct _mjUI // entire UI
|
||||
{
|
||||
// constants set by user
|
||||
mjuiThemeSpacing spacing; // UI theme spacing
|
||||
mjuiThemeColor color; // UI theme color
|
||||
mjfItemEnable predicate; // callback to set item state programmatically
|
||||
void* userdata; // pointer to user data (passed to predicate)
|
||||
int rectid; // index of this ui rectangle in mjuiState
|
||||
int auxid; // aux buffer index of this ui
|
||||
int radiocol; // number of radio columns (0 defaults to 2)
|
||||
|
||||
// UI sizes (framebuffer units)
|
||||
int width; // width
|
||||
int height; // current heigth
|
||||
int maxheight; // height when all sections open
|
||||
int scroll; // scroll from top of UI
|
||||
|
||||
// mouse focus
|
||||
int mousesect; // 0: none, -1: scroll, otherwise 1+section
|
||||
int mouseitem; // item within section
|
||||
int mousehelp; // help button down: print shortcuts
|
||||
|
||||
// keyboard focus and edit
|
||||
int editsect; // 0: none, otherwise 1+section
|
||||
int edititem; // item within section
|
||||
int editcursor; // cursor position
|
||||
int editscroll; // horizontal scroll
|
||||
char edittext[mjMAXUITEXT]; // current text
|
||||
mjuiItem* editchanged; // pointer to changed edit in last mjui_event
|
||||
|
||||
// sections
|
||||
int nsect; // number of sections in use
|
||||
mjuiSection sect[mjMAXUISECT]; // preallocated array of sections
|
||||
};
|
||||
typedef struct _mjUI mjUI;
|
||||
|
||||
|
||||
struct _mjuiDef // table passed to mjui_add()
|
||||
{
|
||||
int type; // type (mjtItem); -1: section
|
||||
char name[mjMAXUINAME]; // name
|
||||
int state; // state
|
||||
void* pdata; // pointer to data
|
||||
char other[mjMAXUITEXT]; // string with type-specific properties
|
||||
};
|
||||
typedef struct _mjuiDef mjuiDef;
|
||||
|
||||
#endif // MUJOCO_MJUI_H_
|
||||
Executable
+350
@@ -0,0 +1,350 @@
|
||||
// Copyright 2021 DeepMind Technologies Limited
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef MUJOCO_MJVISUALIZE_H_
|
||||
#define MUJOCO_MJVISUALIZE_H_
|
||||
|
||||
#define mjNGROUP 6 // number of geom, site, joint groups with visflags
|
||||
#define mjMAXOVERLAY 500 // maximum number of characters in overlay text
|
||||
#define mjMAXLINE 100 // maximum number of lines per plot
|
||||
#define mjMAXLINEPNT 1000 // maximum number points per line
|
||||
#define mjMAXPLANEGRID 200 // maximum number of grid divisions for plane
|
||||
|
||||
|
||||
typedef enum _mjtCatBit // bitflags for mjvGeom category
|
||||
{
|
||||
mjCAT_STATIC = 1, // model elements in body 0
|
||||
mjCAT_DYNAMIC = 2, // model elements in all other bodies
|
||||
mjCAT_DECOR = 4, // decorative geoms
|
||||
mjCAT_ALL = 7 // select all categories
|
||||
} mjtCatBit;
|
||||
|
||||
|
||||
typedef enum _mjtMouse // mouse interaction mode
|
||||
{
|
||||
mjMOUSE_NONE = 0, // no action
|
||||
mjMOUSE_ROTATE_V, // rotate, vertical plane
|
||||
mjMOUSE_ROTATE_H, // rotate, horizontal plane
|
||||
mjMOUSE_MOVE_V, // move, vertical plane
|
||||
mjMOUSE_MOVE_H, // move, horizontal plane
|
||||
mjMOUSE_ZOOM, // zoom
|
||||
mjMOUSE_SELECT // selection
|
||||
} mjtMouse;
|
||||
|
||||
|
||||
typedef enum _mjtPertBit // mouse perturbations
|
||||
{
|
||||
mjPERT_TRANSLATE = 1, // translation
|
||||
mjPERT_ROTATE = 2 // rotation
|
||||
} mjtPertBit;
|
||||
|
||||
|
||||
typedef enum _mjtCamera // abstract camera type
|
||||
{
|
||||
mjCAMERA_FREE = 0, // free camera
|
||||
mjCAMERA_TRACKING, // tracking camera; uses trackbodyid
|
||||
mjCAMERA_FIXED, // fixed camera; uses fixedcamid
|
||||
mjCAMERA_USER // user is responsible for setting OpenGL camera
|
||||
} mjtCamera;
|
||||
|
||||
|
||||
typedef enum _mjtLabel // object labeling
|
||||
{
|
||||
mjLABEL_NONE = 0, // nothing
|
||||
mjLABEL_BODY, // body labels
|
||||
mjLABEL_JOINT, // joint labels
|
||||
mjLABEL_GEOM, // geom labels
|
||||
mjLABEL_SITE, // site labels
|
||||
mjLABEL_CAMERA, // camera labels
|
||||
mjLABEL_LIGHT, // light labels
|
||||
mjLABEL_TENDON, // tendon labels
|
||||
mjLABEL_ACTUATOR, // actuator labels
|
||||
mjLABEL_CONSTRAINT, // constraint labels
|
||||
mjLABEL_SKIN, // skin labels
|
||||
mjLABEL_SELECTION, // selected object
|
||||
mjLABEL_SELPNT, // coordinates of selection point
|
||||
mjLABEL_CONTACTFORCE, // magnitude of contact force
|
||||
|
||||
mjNLABEL // number of label types
|
||||
} mjtLabel;
|
||||
|
||||
|
||||
typedef enum _mjtFrame // frame visualization
|
||||
{
|
||||
mjFRAME_NONE = 0, // no frames
|
||||
mjFRAME_BODY, // body frames
|
||||
mjFRAME_GEOM, // geom frames
|
||||
mjFRAME_SITE, // site frames
|
||||
mjFRAME_CAMERA, // camera frames
|
||||
mjFRAME_LIGHT, // light frames
|
||||
mjFRAME_WORLD, // world frame
|
||||
|
||||
mjNFRAME // number of visualization frames
|
||||
} mjtFrame;
|
||||
|
||||
|
||||
typedef enum _mjtVisFlag // flags enabling model element visualization
|
||||
{
|
||||
mjVIS_CONVEXHULL = 0, // mesh convex hull
|
||||
mjVIS_TEXTURE, // textures
|
||||
mjVIS_JOINT, // joints
|
||||
mjVIS_ACTUATOR, // actuators
|
||||
mjVIS_CAMERA, // cameras
|
||||
mjVIS_LIGHT, // lights
|
||||
mjVIS_TENDON, // tendons
|
||||
mjVIS_RANGEFINDER, // rangefinder sensors
|
||||
mjVIS_CONSTRAINT, // point constraints
|
||||
mjVIS_INERTIA, // equivalent inertia boxes
|
||||
mjVIS_SCLINERTIA, // scale equivalent inertia boxes with mass
|
||||
mjVIS_PERTFORCE, // perturbation force
|
||||
mjVIS_PERTOBJ, // perturbation object
|
||||
mjVIS_CONTACTPOINT, // contact points
|
||||
mjVIS_CONTACTFORCE, // contact force
|
||||
mjVIS_CONTACTSPLIT, // split contact force into normal and tanget
|
||||
mjVIS_TRANSPARENT, // make dynamic geoms more transparent
|
||||
mjVIS_AUTOCONNECT, // auto connect joints and body coms
|
||||
mjVIS_COM, // center of mass
|
||||
mjVIS_SELECT, // selection point
|
||||
mjVIS_STATIC, // static bodies
|
||||
mjVIS_SKIN, // skin
|
||||
|
||||
mjNVISFLAG // number of visualization flags
|
||||
} mjtVisFlag;
|
||||
|
||||
|
||||
typedef enum _mjtRndFlag // flags enabling rendering effects
|
||||
{
|
||||
mjRND_SHADOW = 0, // shadows
|
||||
mjRND_WIREFRAME, // wireframe
|
||||
mjRND_REFLECTION, // reflections
|
||||
mjRND_ADDITIVE, // additive transparency
|
||||
mjRND_SKYBOX, // skybox
|
||||
mjRND_FOG, // fog
|
||||
mjRND_HAZE, // haze
|
||||
mjRND_SEGMENT, // segmentation with random color
|
||||
mjRND_IDCOLOR, // segmentation with segid color
|
||||
|
||||
mjNRNDFLAG // number of rendering flags
|
||||
} mjtRndFlag;
|
||||
|
||||
|
||||
typedef enum _mjtStereo // type of stereo rendering
|
||||
{
|
||||
mjSTEREO_NONE = 0, // no stereo; use left eye only
|
||||
mjSTEREO_QUADBUFFERED, // quad buffered; revert to side-by-side if no hardware support
|
||||
mjSTEREO_SIDEBYSIDE // side-by-side
|
||||
} mjtStereo;
|
||||
|
||||
|
||||
struct _mjvPerturb // object selection and perturbation
|
||||
{
|
||||
int select; // selected body id; non-positive: none
|
||||
int skinselect; // selected skin id; negative: none
|
||||
int active; // perturbation bitmask (mjtPertBit)
|
||||
int active2; // secondary perturbation bitmask (mjtPertBit)
|
||||
mjtNum refpos[3]; // desired position for selected object
|
||||
mjtNum refquat[4]; // desired orientation for selected object
|
||||
mjtNum localpos[3]; // selection point in object coordinates
|
||||
mjtNum scale; // relative mouse motion-to-space scaling (set by initPerturb)
|
||||
};
|
||||
typedef struct _mjvPerturb mjvPerturb;
|
||||
|
||||
|
||||
struct _mjvCamera // abstract camera
|
||||
{
|
||||
// type and ids
|
||||
int type; // camera type (mjtCamera)
|
||||
int fixedcamid; // fixed camera id
|
||||
int trackbodyid; // body id to track
|
||||
|
||||
// abstract camera pose specification
|
||||
mjtNum lookat[3]; // lookat point
|
||||
mjtNum distance; // distance to lookat point or tracked body
|
||||
mjtNum azimuth; // camera azimuth (deg)
|
||||
mjtNum elevation; // camera elevation (deg)
|
||||
};
|
||||
typedef struct _mjvCamera mjvCamera;
|
||||
|
||||
|
||||
struct _mjvGLCamera // OpenGL camera
|
||||
{
|
||||
// camera frame
|
||||
float pos[3]; // position
|
||||
float forward[3]; // forward direction
|
||||
float up[3]; // up direction
|
||||
|
||||
// camera projection
|
||||
float frustum_center; // hor. center (left,right set to match aspect)
|
||||
float frustum_bottom; // bottom
|
||||
float frustum_top; // top
|
||||
float frustum_near; // near
|
||||
float frustum_far; // far
|
||||
};
|
||||
typedef struct _mjvGLCamera mjvGLCamera;
|
||||
|
||||
|
||||
struct _mjvGeom // abstract geom
|
||||
{
|
||||
// type info
|
||||
int type; // geom type (mjtGeom)
|
||||
int dataid; // mesh, hfield or plane id; -1: none
|
||||
int objtype; // mujoco object type; mjOBJ_UNKNOWN for decor
|
||||
int objid; // mujoco object id; -1 for decor
|
||||
int category; // visual category
|
||||
int texid; // texture id; -1: no texture
|
||||
int texuniform; // uniform cube mapping
|
||||
int texcoord; // mesh geom has texture coordinates
|
||||
int segid; // segmentation id; -1: not shown
|
||||
|
||||
// OpenGL info
|
||||
float texrepeat[2]; // texture repetition for 2D mapping
|
||||
float size[3]; // size parameters
|
||||
float pos[3]; // Cartesian position
|
||||
float mat[9]; // Cartesian orientation
|
||||
float rgba[4]; // color and transparency
|
||||
float emission; // emission coef
|
||||
float specular; // specular coef
|
||||
float shininess; // shininess coef
|
||||
float reflectance; // reflectance coef
|
||||
char label[100]; // text label
|
||||
|
||||
// transparency rendering (set internally)
|
||||
float camdist; // distance to camera (used by sorter)
|
||||
float modelrbound; // geom rbound from model, 0 if not model geom
|
||||
mjtByte transparent; // treat geom as transparent
|
||||
};
|
||||
typedef struct _mjvGeom mjvGeom;
|
||||
|
||||
|
||||
struct _mjvLight // OpenGL light
|
||||
{
|
||||
float pos[3]; // position rel. to body frame
|
||||
float dir[3]; // direction rel. to body frame
|
||||
float attenuation[3]; // OpenGL attenuation (quadratic model)
|
||||
float cutoff; // OpenGL cutoff
|
||||
float exponent; // OpenGL exponent
|
||||
float ambient[3]; // ambient rgb (alpha=1)
|
||||
float diffuse[3]; // diffuse rgb (alpha=1)
|
||||
float specular[3]; // specular rgb (alpha=1)
|
||||
mjtByte headlight; // headlight
|
||||
mjtByte directional; // directional light
|
||||
mjtByte castshadow; // does light cast shadows
|
||||
};
|
||||
typedef struct _mjvLight mjvLight;
|
||||
|
||||
|
||||
struct _mjvOption // abstract visualization options
|
||||
{
|
||||
int label; // what objects to label (mjtLabel)
|
||||
int frame; // which frame to show (mjtFrame)
|
||||
mjtByte geomgroup[mjNGROUP]; // geom visualization by group
|
||||
mjtByte sitegroup[mjNGROUP]; // site visualization by group
|
||||
mjtByte jointgroup[mjNGROUP]; // joint visualization by group
|
||||
mjtByte tendongroup[mjNGROUP]; // tendon visualization by group
|
||||
mjtByte actuatorgroup[mjNGROUP]; // actuator visualization by group
|
||||
mjtByte flags[mjNVISFLAG]; // visualization flags (indexed by mjtVisFlag)
|
||||
};
|
||||
typedef struct _mjvOption mjvOption;
|
||||
|
||||
|
||||
struct _mjvScene // abstract scene passed to OpenGL renderer
|
||||
{
|
||||
// abstract geoms
|
||||
int maxgeom; // size of allocated geom buffer
|
||||
int ngeom; // number of geoms currently in buffer
|
||||
mjvGeom* geoms; // buffer for geoms
|
||||
int* geomorder; // buffer for ordering geoms by distance to camera
|
||||
|
||||
// skin data
|
||||
int nskin; // number of skins
|
||||
int* skinfacenum; // number of faces in skin
|
||||
int* skinvertadr; // address of skin vertices
|
||||
int* skinvertnum; // number of vertices in skin
|
||||
float* skinvert; // skin vertex data
|
||||
float* skinnormal; // skin normal data
|
||||
|
||||
// OpenGL lights
|
||||
int nlight; // number of lights currently in buffer
|
||||
mjvLight lights[8]; // buffer for lights
|
||||
|
||||
// OpenGL cameras
|
||||
mjvGLCamera camera[2]; // left and right camera
|
||||
|
||||
// OpenGL model transformation
|
||||
mjtByte enabletransform; // enable model transformation
|
||||
float translate[3]; // model translation
|
||||
float rotate[4]; // model quaternion rotation
|
||||
float scale; // model scaling
|
||||
|
||||
// OpenGL rendering effects
|
||||
int stereo; // stereoscopic rendering (mjtStereo)
|
||||
mjtByte flags[mjNRNDFLAG]; // rendering flags (indexed by mjtRndFlag)
|
||||
|
||||
// framing
|
||||
int framewidth; // frame pixel width; 0: disable framing
|
||||
float framergb[3]; // frame color
|
||||
};
|
||||
typedef struct _mjvScene mjvScene;
|
||||
|
||||
|
||||
struct _mjvFigure // abstract 2D figure passed to OpenGL renderer
|
||||
{
|
||||
// enable flags
|
||||
int flg_legend; // show legend
|
||||
int flg_ticklabel[2]; // show grid tick labels (x,y)
|
||||
int flg_extend; // automatically extend axis ranges to fit data
|
||||
int flg_barplot; // isolated line segments (i.e. GL_LINES)
|
||||
int flg_selection; // vertical selection line
|
||||
int flg_symmetric; // symmetric y-axis
|
||||
|
||||
// style settings
|
||||
float linewidth; // line width
|
||||
float gridwidth; // grid line width
|
||||
int gridsize[2]; // number of grid points in (x,y)
|
||||
float gridrgb[3]; // grid line rgb
|
||||
float figurergba[4]; // figure color and alpha
|
||||
float panergba[4]; // pane color and alpha
|
||||
float legendrgba[4]; // legend color and alpha
|
||||
float textrgb[3]; // text color
|
||||
float linergb[mjMAXLINE][3]; // line colors
|
||||
float range[2][2]; // axis ranges; (min>=max) automatic
|
||||
char xformat[20]; // x-tick label format for sprintf
|
||||
char yformat[20]; // y-tick label format for sprintf
|
||||
char minwidth[20]; // string used to determine min y-tick width
|
||||
|
||||
// text labels
|
||||
char title[1000]; // figure title; subplots separated with 2+ spaces
|
||||
char xlabel[100]; // x-axis label
|
||||
char linename[mjMAXLINE][100]; // line names for legend
|
||||
|
||||
// dynamic settings
|
||||
int legendoffset; // number of lines to offset legend
|
||||
int subplot; // selected subplot (for title rendering)
|
||||
int highlight[2]; // if point is in legend rect, highlight line
|
||||
int highlightid; // if id>=0 and no point, highlight id
|
||||
float selection; // selection line x-value
|
||||
|
||||
// line data
|
||||
int linepnt[mjMAXLINE]; // number of points in line; (0) disable
|
||||
float linedata[mjMAXLINE][2*mjMAXLINEPNT]; // line data (x,y)
|
||||
|
||||
// output from renderer
|
||||
int xaxispixel[2]; // range of x-axis in pixels
|
||||
int yaxispixel[2]; // range of y-axis in pixels
|
||||
float xaxisdata[2]; // range of x-axis in data units
|
||||
float yaxisdata[2]; // range of y-axis in data units
|
||||
};
|
||||
typedef struct _mjvFigure mjvFigure;
|
||||
|
||||
#endif // MUJOCO_MJVISUALIZE_H_
|
||||
Executable
+511
@@ -0,0 +1,511 @@
|
||||
// Copyright 2021 DeepMind Technologies Limited
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef MUJOCO_MJXMACRO_H_
|
||||
#define MUJOCO_MJXMACRO_H_
|
||||
|
||||
//-------------------------------- mjOption ---------------------------------------------
|
||||
|
||||
// scalar fields of mjOption
|
||||
#define MJOPTION_SCALARS \
|
||||
X( mjtNum, timestep ) \
|
||||
X( mjtNum, apirate ) \
|
||||
X( mjtNum, impratio ) \
|
||||
X( mjtNum, tolerance ) \
|
||||
X( mjtNum, noslip_tolerance ) \
|
||||
X( mjtNum, mpr_tolerance ) \
|
||||
X( mjtNum, density ) \
|
||||
X( mjtNum, viscosity ) \
|
||||
X( mjtNum, o_margin ) \
|
||||
X( int, integrator ) \
|
||||
X( int, collision ) \
|
||||
X( int, cone ) \
|
||||
X( int, jacobian ) \
|
||||
X( int, solver ) \
|
||||
X( int, iterations ) \
|
||||
X( int, noslip_iterations ) \
|
||||
X( int, mpr_iterations ) \
|
||||
X( int, disableflags ) \
|
||||
X( int, enableflags )
|
||||
|
||||
|
||||
// vector fields of mjOption
|
||||
#define MJOPTION_VECTORS \
|
||||
X( gravity, 3 ) \
|
||||
X( wind, 3 ) \
|
||||
X( magnetic, 3 ) \
|
||||
X( o_solref, mjNREF ) \
|
||||
X( o_solimp, mjNIMP )
|
||||
|
||||
|
||||
|
||||
//-------------------------------- mjModel ----------------------------------------------
|
||||
|
||||
// int fields of mjModel
|
||||
#define MJMODEL_INTS \
|
||||
X( nq ) \
|
||||
X( nv ) \
|
||||
X( nu ) \
|
||||
X( na ) \
|
||||
X( nbody ) \
|
||||
X( njnt ) \
|
||||
X( ngeom ) \
|
||||
X( nsite ) \
|
||||
X( ncam ) \
|
||||
X( nlight ) \
|
||||
X( nmesh ) \
|
||||
X( nmeshvert ) \
|
||||
X( nmeshtexvert ) \
|
||||
X( nmeshface ) \
|
||||
X( nmeshgraph ) \
|
||||
X( nskin ) \
|
||||
X( nskinvert ) \
|
||||
X( nskintexvert ) \
|
||||
X( nskinface ) \
|
||||
X( nskinbone ) \
|
||||
X( nskinbonevert ) \
|
||||
X( nhfield ) \
|
||||
X( nhfielddata ) \
|
||||
X( ntex ) \
|
||||
X( ntexdata ) \
|
||||
X( nmat ) \
|
||||
X( npair ) \
|
||||
X( nexclude ) \
|
||||
X( neq ) \
|
||||
X( ntendon ) \
|
||||
X( nwrap ) \
|
||||
X( nsensor ) \
|
||||
X( nnumeric ) \
|
||||
X( nnumericdata ) \
|
||||
X( ntext ) \
|
||||
X( ntextdata ) \
|
||||
X( ntuple ) \
|
||||
X( ntupledata ) \
|
||||
X( nkey ) \
|
||||
X( nmocap ) \
|
||||
X( nuser_body ) \
|
||||
X( nuser_jnt ) \
|
||||
X( nuser_geom ) \
|
||||
X( nuser_site ) \
|
||||
X( nuser_cam ) \
|
||||
X( nuser_tendon ) \
|
||||
X( nuser_actuator ) \
|
||||
X( nuser_sensor ) \
|
||||
X( nnames ) \
|
||||
X( nM ) \
|
||||
X( nemax ) \
|
||||
X( njmax ) \
|
||||
X( nconmax ) \
|
||||
X( nstack ) \
|
||||
X( nuserdata ) \
|
||||
X( nsensordata ) \
|
||||
X( nbuffer )
|
||||
|
||||
|
||||
// pointer fields of mjModel
|
||||
#define MJMODEL_POINTERS \
|
||||
X( mjtNum, qpos0, nq, 1 ) \
|
||||
X( mjtNum, qpos_spring, nq, 1 ) \
|
||||
X( int, body_parentid, nbody, 1 ) \
|
||||
X( int, body_rootid, nbody, 1 ) \
|
||||
X( int, body_weldid, nbody, 1 ) \
|
||||
X( int, body_mocapid, nbody, 1 ) \
|
||||
X( int, body_jntnum, nbody, 1 ) \
|
||||
X( int, body_jntadr, nbody, 1 ) \
|
||||
X( int, body_dofnum, nbody, 1 ) \
|
||||
X( int, body_dofadr, nbody, 1 ) \
|
||||
X( int, body_geomnum, nbody, 1 ) \
|
||||
X( int, body_geomadr, nbody, 1 ) \
|
||||
X( mjtByte, body_simple, nbody, 1 ) \
|
||||
X( mjtByte, body_sameframe, nbody, 1 ) \
|
||||
X( mjtNum, body_pos, nbody, 3 ) \
|
||||
X( mjtNum, body_quat, nbody, 4 ) \
|
||||
X( mjtNum, body_ipos, nbody, 3 ) \
|
||||
X( mjtNum, body_iquat, nbody, 4 ) \
|
||||
X( mjtNum, body_mass, nbody, 1 ) \
|
||||
X( mjtNum, body_subtreemass, nbody, 1 ) \
|
||||
X( mjtNum, body_inertia, nbody, 3 ) \
|
||||
X( mjtNum, body_invweight0, nbody, 2 ) \
|
||||
X( mjtNum, body_user, nbody, nuser_body ) \
|
||||
X( int, jnt_type, njnt, 1 ) \
|
||||
X( int, jnt_qposadr, njnt, 1 ) \
|
||||
X( int, jnt_dofadr, njnt, 1 ) \
|
||||
X( int, jnt_bodyid, njnt, 1 ) \
|
||||
X( int, jnt_group, njnt, 1 ) \
|
||||
X( mjtByte, jnt_limited, njnt, 1 ) \
|
||||
X( mjtNum, jnt_solref, njnt, mjNREF ) \
|
||||
X( mjtNum, jnt_solimp, njnt, mjNIMP ) \
|
||||
X( mjtNum, jnt_pos, njnt, 3 ) \
|
||||
X( mjtNum, jnt_axis, njnt, 3 ) \
|
||||
X( mjtNum, jnt_stiffness, njnt, 1 ) \
|
||||
X( mjtNum, jnt_range, njnt, 2 ) \
|
||||
X( mjtNum, jnt_margin, njnt, 1 ) \
|
||||
X( mjtNum, jnt_user, njnt, nuser_jnt ) \
|
||||
X( int, dof_bodyid, nv, 1 ) \
|
||||
X( int, dof_jntid, nv, 1 ) \
|
||||
X( int, dof_parentid, nv, 1 ) \
|
||||
X( int, dof_Madr, nv, 1 ) \
|
||||
X( int, dof_simplenum, nv, 1 ) \
|
||||
X( mjtNum, dof_solref, nv, mjNREF ) \
|
||||
X( mjtNum, dof_solimp, nv, mjNIMP ) \
|
||||
X( mjtNum, dof_frictionloss, nv, 1 ) \
|
||||
X( mjtNum, dof_armature, nv, 1 ) \
|
||||
X( mjtNum, dof_damping, nv, 1 ) \
|
||||
X( mjtNum, dof_invweight0, nv, 1 ) \
|
||||
X( mjtNum, dof_M0, nv, 1 ) \
|
||||
X( int, geom_type, ngeom, 1 ) \
|
||||
X( int, geom_contype, ngeom, 1 ) \
|
||||
X( int, geom_conaffinity, ngeom, 1 ) \
|
||||
X( int, geom_condim, ngeom, 1 ) \
|
||||
X( int, geom_bodyid, ngeom, 1 ) \
|
||||
X( int, geom_dataid, ngeom, 1 ) \
|
||||
X( int, geom_matid, ngeom, 1 ) \
|
||||
X( int, geom_group, ngeom, 1 ) \
|
||||
X( int, geom_priority, ngeom, 1 ) \
|
||||
X( mjtByte, geom_sameframe, ngeom, 1 ) \
|
||||
X( mjtNum, geom_solmix, ngeom, 1 ) \
|
||||
X( mjtNum, geom_solref, ngeom, mjNREF ) \
|
||||
X( mjtNum, geom_solimp, ngeom, mjNIMP ) \
|
||||
X( mjtNum, geom_size, ngeom, 3 ) \
|
||||
X( mjtNum, geom_rbound, ngeom, 1 ) \
|
||||
X( mjtNum, geom_pos, ngeom, 3 ) \
|
||||
X( mjtNum, geom_quat, ngeom, 4 ) \
|
||||
X( mjtNum, geom_friction, ngeom, 3 ) \
|
||||
X( mjtNum, geom_margin, ngeom, 1 ) \
|
||||
X( mjtNum, geom_gap, ngeom, 1 ) \
|
||||
X( mjtNum, geom_user, ngeom, nuser_geom ) \
|
||||
X( float, geom_rgba, ngeom, 4 ) \
|
||||
X( int, site_type, nsite, 1 ) \
|
||||
X( int, site_bodyid, nsite, 1 ) \
|
||||
X( int, site_matid, nsite, 1 ) \
|
||||
X( int, site_group, nsite, 1 ) \
|
||||
X( mjtByte, site_sameframe, nsite, 1 ) \
|
||||
X( mjtNum, site_size, nsite, 3 ) \
|
||||
X( mjtNum, site_pos, nsite, 3 ) \
|
||||
X( mjtNum, site_quat, nsite, 4 ) \
|
||||
X( mjtNum, site_user, nsite, nuser_site ) \
|
||||
X( float, site_rgba, nsite, 4 ) \
|
||||
X( int, cam_mode, ncam, 1 ) \
|
||||
X( int, cam_bodyid, ncam, 1 ) \
|
||||
X( int, cam_targetbodyid, ncam, 1 ) \
|
||||
X( mjtNum, cam_pos, ncam, 3 ) \
|
||||
X( mjtNum, cam_quat, ncam, 4 ) \
|
||||
X( mjtNum, cam_poscom0, ncam, 3 ) \
|
||||
X( mjtNum, cam_pos0, ncam, 3 ) \
|
||||
X( mjtNum, cam_mat0, ncam, 9 ) \
|
||||
X( mjtNum, cam_fovy, ncam, 1 ) \
|
||||
X( mjtNum, cam_ipd, ncam, 1 ) \
|
||||
X( mjtNum, cam_user, ncam, nuser_cam ) \
|
||||
X( int, light_mode, nlight, 1 ) \
|
||||
X( int, light_bodyid, nlight, 1 ) \
|
||||
X( int, light_targetbodyid, nlight, 1 ) \
|
||||
X( mjtByte, light_directional, nlight, 1 ) \
|
||||
X( mjtByte, light_castshadow, nlight, 1 ) \
|
||||
X( mjtByte, light_active, nlight, 1 ) \
|
||||
X( mjtNum, light_pos, nlight, 3 ) \
|
||||
X( mjtNum, light_dir, nlight, 3 ) \
|
||||
X( mjtNum, light_poscom0, nlight, 3 ) \
|
||||
X( mjtNum, light_pos0, nlight, 3 ) \
|
||||
X( mjtNum, light_dir0, nlight, 3 ) \
|
||||
X( float, light_attenuation, nlight, 3 ) \
|
||||
X( float, light_cutoff, nlight, 1 ) \
|
||||
X( float, light_exponent, nlight, 1 ) \
|
||||
X( float, light_ambient, nlight, 3 ) \
|
||||
X( float, light_diffuse, nlight, 3 ) \
|
||||
X( float, light_specular, nlight, 3 ) \
|
||||
X( int, mesh_vertadr, nmesh, 1 ) \
|
||||
X( int, mesh_vertnum, nmesh, 1 ) \
|
||||
X( int, mesh_texcoordadr, nmesh, 1 ) \
|
||||
X( int, mesh_faceadr, nmesh, 1 ) \
|
||||
X( int, mesh_facenum, nmesh, 1 ) \
|
||||
X( int, mesh_graphadr, nmesh, 1 ) \
|
||||
X( float, mesh_vert, nmeshvert, 3 ) \
|
||||
X( float, mesh_normal, nmeshvert, 3 ) \
|
||||
X( float, mesh_texcoord, nmeshtexvert, 2 ) \
|
||||
X( int, mesh_face, nmeshface, 3 ) \
|
||||
X( int, mesh_graph, nmeshgraph,1 ) \
|
||||
X( int, skin_matid, nskin, 1 ) \
|
||||
X( float, skin_rgba, nskin, 4 ) \
|
||||
X( float, skin_inflate, nskin, 1 ) \
|
||||
X( int, skin_vertadr, nskin, 1 ) \
|
||||
X( int, skin_vertnum, nskin, 1 ) \
|
||||
X( int, skin_texcoordadr, nskin, 1 ) \
|
||||
X( int, skin_faceadr, nskin, 1 ) \
|
||||
X( int, skin_facenum, nskin, 1 ) \
|
||||
X( int, skin_boneadr, nskin, 1 ) \
|
||||
X( int, skin_bonenum, nskin, 1 ) \
|
||||
X( float, skin_vert, nskinvert, 3 ) \
|
||||
X( float, skin_texcoord, nskintexvert, 2 ) \
|
||||
X( int, skin_face, nskinface, 3 ) \
|
||||
X( int, skin_bonevertadr, nskinbone, 1 ) \
|
||||
X( int, skin_bonevertnum, nskinbone, 1 ) \
|
||||
X( float, skin_bonebindpos, nskinbone, 3 ) \
|
||||
X( float, skin_bonebindquat, nskinbone, 4 ) \
|
||||
X( int, skin_bonebodyid, nskinbone, 1 ) \
|
||||
X( int, skin_bonevertid, nskinbonevert, 1 ) \
|
||||
X( float, skin_bonevertweight, nskinbonevert, 1 ) \
|
||||
X( mjtNum, hfield_size, nhfield, 4 ) \
|
||||
X( int, hfield_nrow, nhfield, 1 ) \
|
||||
X( int, hfield_ncol, nhfield, 1 ) \
|
||||
X( int, hfield_adr, nhfield, 1 ) \
|
||||
X( float, hfield_data, nhfielddata, 1 ) \
|
||||
X( int, tex_type, ntex, 1 ) \
|
||||
X( int, tex_height, ntex, 1 ) \
|
||||
X( int, tex_width, ntex, 1 ) \
|
||||
X( int, tex_adr, ntex, 1 ) \
|
||||
X( mjtByte, tex_rgb, ntexdata, 1 ) \
|
||||
X( int, mat_texid, nmat, 1 ) \
|
||||
X( mjtByte, mat_texuniform, nmat, 1 ) \
|
||||
X( float, mat_texrepeat, nmat, 2 ) \
|
||||
X( float, mat_emission, nmat, 1 ) \
|
||||
X( float, mat_specular, nmat, 1 ) \
|
||||
X( float, mat_shininess, nmat, 1 ) \
|
||||
X( float, mat_reflectance, nmat, 1 ) \
|
||||
X( float, mat_rgba, nmat, 4 ) \
|
||||
X( int, pair_dim, npair, 1 ) \
|
||||
X( int, pair_geom1, npair, 1 ) \
|
||||
X( int, pair_geom2, npair, 1 ) \
|
||||
X( int, pair_signature, npair, 1 ) \
|
||||
X( mjtNum, pair_solref, npair, mjNREF ) \
|
||||
X( mjtNum, pair_solimp, npair, mjNIMP ) \
|
||||
X( mjtNum, pair_margin, npair, 1 ) \
|
||||
X( mjtNum, pair_gap, npair, 1 ) \
|
||||
X( mjtNum, pair_friction, npair, 5 ) \
|
||||
X( int, exclude_signature, nexclude, 1 ) \
|
||||
X( int, eq_type, neq, 1 ) \
|
||||
X( int, eq_obj1id, neq, 1 ) \
|
||||
X( int, eq_obj2id, neq, 1 ) \
|
||||
X( mjtByte, eq_active, neq, 1 ) \
|
||||
X( mjtNum, eq_solref, neq, mjNREF ) \
|
||||
X( mjtNum, eq_solimp, neq, mjNIMP ) \
|
||||
X( mjtNum, eq_data, neq, mjNEQDATA ) \
|
||||
X( int, tendon_adr, ntendon, 1 ) \
|
||||
X( int, tendon_num, ntendon, 1 ) \
|
||||
X( int, tendon_matid, ntendon, 1 ) \
|
||||
X( int, tendon_group, ntendon, 1 ) \
|
||||
X( mjtByte, tendon_limited, ntendon, 1 ) \
|
||||
X( mjtNum, tendon_width, ntendon, 1 ) \
|
||||
X( mjtNum, tendon_solref_lim, ntendon, mjNREF ) \
|
||||
X( mjtNum, tendon_solimp_lim, ntendon, mjNIMP ) \
|
||||
X( mjtNum, tendon_solref_fri, ntendon, mjNREF ) \
|
||||
X( mjtNum, tendon_solimp_fri, ntendon, mjNIMP ) \
|
||||
X( mjtNum, tendon_range, ntendon, 2 ) \
|
||||
X( mjtNum, tendon_margin, ntendon, 1 ) \
|
||||
X( mjtNum, tendon_stiffness, ntendon, 1 ) \
|
||||
X( mjtNum, tendon_damping, ntendon, 1 ) \
|
||||
X( mjtNum, tendon_frictionloss, ntendon, 1 ) \
|
||||
X( mjtNum, tendon_lengthspring, ntendon, 1 ) \
|
||||
X( mjtNum, tendon_length0, ntendon, 1 ) \
|
||||
X( mjtNum, tendon_invweight0, ntendon, 1 ) \
|
||||
X( mjtNum, tendon_user, ntendon, nuser_tendon) \
|
||||
X( float, tendon_rgba, ntendon, 4 ) \
|
||||
X( int, wrap_type, nwrap, 1 ) \
|
||||
X( int, wrap_objid, nwrap, 1 ) \
|
||||
X( mjtNum, wrap_prm, nwrap, 1 ) \
|
||||
X( int, actuator_trntype, nu, 1 ) \
|
||||
X( int, actuator_dyntype, nu, 1 ) \
|
||||
X( int, actuator_gaintype, nu, 1 ) \
|
||||
X( int, actuator_biastype, nu, 1 ) \
|
||||
X( int, actuator_trnid, nu, 2 ) \
|
||||
X( int, actuator_group, nu, 1 ) \
|
||||
X( mjtByte, actuator_ctrllimited, nu, 1 ) \
|
||||
X( mjtByte, actuator_forcelimited, nu, 1 ) \
|
||||
X( mjtNum, actuator_dynprm, nu, mjNDYN ) \
|
||||
X( mjtNum, actuator_gainprm, nu, mjNGAIN ) \
|
||||
X( mjtNum, actuator_biasprm, nu, mjNBIAS ) \
|
||||
X( mjtNum, actuator_ctrlrange, nu, 2 ) \
|
||||
X( mjtNum, actuator_forcerange, nu, 2 ) \
|
||||
X( mjtNum, actuator_gear, nu, 6 ) \
|
||||
X( mjtNum, actuator_cranklength, nu, 1 ) \
|
||||
X( mjtNum, actuator_acc0, nu, 1 ) \
|
||||
X( mjtNum, actuator_length0, nu, 1 ) \
|
||||
X( mjtNum, actuator_lengthrange, nu, 2 ) \
|
||||
X( mjtNum, actuator_user, nu, nuser_actuator) \
|
||||
X( int, sensor_type, nsensor, 1 ) \
|
||||
X( int, sensor_datatype, nsensor, 1 ) \
|
||||
X( int, sensor_needstage, nsensor, 1 ) \
|
||||
X( int, sensor_objtype, nsensor, 1 ) \
|
||||
X( int, sensor_objid, nsensor, 1 ) \
|
||||
X( int, sensor_dim, nsensor, 1 ) \
|
||||
X( int, sensor_adr, nsensor, 1 ) \
|
||||
X( mjtNum, sensor_cutoff, nsensor, 1 ) \
|
||||
X( mjtNum, sensor_noise, nsensor, 1 ) \
|
||||
X( mjtNum, sensor_user, nsensor, nuser_sensor) \
|
||||
X( int, numeric_adr, nnumeric, 1 ) \
|
||||
X( int, numeric_size, nnumeric, 1 ) \
|
||||
X( mjtNum, numeric_data, nnumericdata, 1 ) \
|
||||
X( int, text_adr, ntext, 1 ) \
|
||||
X( int, text_size, ntext, 1 ) \
|
||||
X( char, text_data, ntextdata, 1 ) \
|
||||
X( int, tuple_adr, ntuple, 1 ) \
|
||||
X( int, tuple_size, ntuple, 1 ) \
|
||||
X( int, tuple_objtype, ntupledata, 1 ) \
|
||||
X( int, tuple_objid, ntupledata, 1 ) \
|
||||
X( mjtNum, tuple_objprm, ntupledata, 1 ) \
|
||||
X( mjtNum, key_time, nkey, 1 ) \
|
||||
X( mjtNum, key_qpos, nkey, nq ) \
|
||||
X( mjtNum, key_qvel, nkey, nv ) \
|
||||
X( mjtNum, key_act, nkey, na ) \
|
||||
X( mjtNum, key_mpos, nkey, nmocap3 ) \
|
||||
X( mjtNum, key_mquat, nkey, nmocap4 ) \
|
||||
X( int, name_bodyadr, nbody, 1 ) \
|
||||
X( int, name_jntadr, njnt, 1 ) \
|
||||
X( int, name_geomadr, ngeom, 1 ) \
|
||||
X( int, name_siteadr, nsite, 1 ) \
|
||||
X( int, name_camadr, ncam, 1 ) \
|
||||
X( int, name_lightadr, nlight, 1 ) \
|
||||
X( int, name_meshadr, nmesh, 1 ) \
|
||||
X( int, name_skinadr, nskin, 1 ) \
|
||||
X( int, name_hfieldadr, nhfield, 1 ) \
|
||||
X( int, name_texadr, ntex, 1 ) \
|
||||
X( int, name_matadr, nmat, 1 ) \
|
||||
X( int, name_pairadr, npair, 1 ) \
|
||||
X( int, name_excludeadr, nexclude, 1 ) \
|
||||
X( int, name_eqadr, neq, 1 ) \
|
||||
X( int, name_tendonadr, ntendon, 1 ) \
|
||||
X( int, name_actuatoradr, nu, 1 ) \
|
||||
X( int, name_sensoradr, nsensor, 1 ) \
|
||||
X( int, name_numericadr, nnumeric, 1 ) \
|
||||
X( int, name_textadr, ntext, 1 ) \
|
||||
X( int, name_tupleadr, ntuple, 1 ) \
|
||||
X( int, name_keyadr, nkey, 1 ) \
|
||||
X( char, names, nnames, 1 )
|
||||
|
||||
|
||||
|
||||
//-------------------------------- mjData -----------------------------------------------
|
||||
|
||||
// pointer fields of mjData
|
||||
#define MJDATA_POINTERS \
|
||||
X( mjtNum, qpos, nq, 1 ) \
|
||||
X( mjtNum, qvel, nv, 1 ) \
|
||||
X( mjtNum, act, na, 1 ) \
|
||||
X( mjtNum, qacc_warmstart, nv, 1 ) \
|
||||
X( mjtNum, ctrl, nu, 1 ) \
|
||||
X( mjtNum, qfrc_applied, nv, 1 ) \
|
||||
X( mjtNum, xfrc_applied, nbody, 6 ) \
|
||||
X( mjtNum, qacc, nv, 1 ) \
|
||||
X( mjtNum, act_dot, na, 1 ) \
|
||||
X( mjtNum, mocap_pos, nmocap, 3 ) \
|
||||
X( mjtNum, mocap_quat, nmocap, 4 ) \
|
||||
X( mjtNum, userdata, nuserdata, 1 ) \
|
||||
X( mjtNum, sensordata, nsensordata,1 ) \
|
||||
X( mjtNum, xpos, nbody, 3 ) \
|
||||
X( mjtNum, xquat, nbody, 4 ) \
|
||||
X( mjtNum, xmat, nbody, 9 ) \
|
||||
X( mjtNum, xipos, nbody, 3 ) \
|
||||
X( mjtNum, ximat, nbody, 9 ) \
|
||||
X( mjtNum, xanchor, njnt, 3 ) \
|
||||
X( mjtNum, xaxis, njnt, 3 ) \
|
||||
X( mjtNum, geom_xpos, ngeom, 3 ) \
|
||||
X( mjtNum, geom_xmat, ngeom, 9 ) \
|
||||
X( mjtNum, site_xpos, nsite, 3 ) \
|
||||
X( mjtNum, site_xmat, nsite, 9 ) \
|
||||
X( mjtNum, cam_xpos, ncam, 3 ) \
|
||||
X( mjtNum, cam_xmat, ncam, 9 ) \
|
||||
X( mjtNum, light_xpos, nlight, 3 ) \
|
||||
X( mjtNum, light_xdir, nlight, 3 ) \
|
||||
X( mjtNum, subtree_com, nbody, 3 ) \
|
||||
X( mjtNum, cdof, nv, 6 ) \
|
||||
X( mjtNum, cinert, nbody, 10 ) \
|
||||
X( int, ten_wrapadr, ntendon, 1 ) \
|
||||
X( int, ten_wrapnum, ntendon, 1 ) \
|
||||
X( int, ten_J_rownnz, ntendon, 1 ) \
|
||||
X( int, ten_J_rowadr, ntendon, 1 ) \
|
||||
X( int, ten_J_colind, ntendon, nv ) \
|
||||
X( mjtNum, ten_length, ntendon, 1 ) \
|
||||
X( mjtNum, ten_J, ntendon, nv ) \
|
||||
X( int, wrap_obj, nwrap, 2 ) \
|
||||
X( mjtNum, wrap_xpos, nwrap, 6 ) \
|
||||
X( mjtNum, actuator_length, nu, 1 ) \
|
||||
X( mjtNum, actuator_moment, nu, nv ) \
|
||||
X( mjtNum, crb, nbody, 10 ) \
|
||||
X( mjtNum, qM, nM, 1 ) \
|
||||
X( mjtNum, qLD, nM, 1 ) \
|
||||
X( mjtNum, qLDiagInv, nv, 1 ) \
|
||||
X( mjtNum, qLDiagSqrtInv, nv, 1 ) \
|
||||
X( mjContact, contact, nconmax, 1 ) \
|
||||
X( int, efc_type, njmax, 1 ) \
|
||||
X( int, efc_id, njmax, 1 ) \
|
||||
X( int, efc_J_rownnz, njmax, 1 ) \
|
||||
X( int, efc_J_rowadr, njmax, 1 ) \
|
||||
X( int, efc_J_rowsuper, njmax, 1 ) \
|
||||
X( int, efc_J_colind, njmax, nv ) \
|
||||
X( int, efc_JT_rownnz, nv, 1 ) \
|
||||
X( int, efc_JT_rowadr, nv, 1 ) \
|
||||
X( int, efc_JT_rowsuper, nv, 1 ) \
|
||||
X( int, efc_JT_colind, nv, njmax ) \
|
||||
X( mjtNum, efc_J, njmax, nv ) \
|
||||
X( mjtNum, efc_JT, nv, njmax ) \
|
||||
X( mjtNum, efc_pos, njmax, 1 ) \
|
||||
X( mjtNum, efc_margin, njmax, 1 ) \
|
||||
X( mjtNum, efc_frictionloss, njmax, 1 ) \
|
||||
X( mjtNum, efc_diagApprox, njmax, 1 ) \
|
||||
X( mjtNum, efc_KBIP, njmax, 4 ) \
|
||||
X( mjtNum, efc_D, njmax, 1 ) \
|
||||
X( mjtNum, efc_R, njmax, 1 ) \
|
||||
X( int, efc_AR_rownnz, njmax, 1 ) \
|
||||
X( int, efc_AR_rowadr, njmax, 1 ) \
|
||||
X( int, efc_AR_colind, njmax, njmax ) \
|
||||
X( mjtNum, efc_AR, njmax, njmax ) \
|
||||
X( mjtNum, ten_velocity, ntendon, 1 ) \
|
||||
X( mjtNum, actuator_velocity, nu, 1 ) \
|
||||
X( mjtNum, cvel, nbody, 6 ) \
|
||||
X( mjtNum, cdof_dot, nv, 6 ) \
|
||||
X( mjtNum, qfrc_bias, nv, 1 ) \
|
||||
X( mjtNum, qfrc_passive, nv, 1 ) \
|
||||
X( mjtNum, efc_vel, njmax, 1 ) \
|
||||
X( mjtNum, efc_aref, njmax, 1 ) \
|
||||
X( mjtNum, subtree_linvel, nbody, 3 ) \
|
||||
X( mjtNum, subtree_angmom, nbody, 3 ) \
|
||||
X( mjtNum, actuator_force, nu, 1 ) \
|
||||
X( mjtNum, qfrc_actuator, nv, 1 ) \
|
||||
X( mjtNum, qfrc_unc, nv, 1 ) \
|
||||
X( mjtNum, qacc_unc, nv, 1 ) \
|
||||
X( mjtNum, efc_b, njmax, 1 ) \
|
||||
X( mjtNum, efc_force, njmax, 1 ) \
|
||||
X( int, efc_state, njmax, 1 ) \
|
||||
X( mjtNum, qfrc_constraint, nv, 1 ) \
|
||||
X( mjtNum, qfrc_inverse, nv, 1 ) \
|
||||
X( mjtNum, cacc, nbody, 6 ) \
|
||||
X( mjtNum, cfrc_int, nbody, 6 ) \
|
||||
X( mjtNum, cfrc_ext, nbody, 6 )
|
||||
|
||||
|
||||
// scalar fields of mjData
|
||||
#define MJDATA_SCALAR \
|
||||
X( int, nstack ) \
|
||||
X( int, nbuffer ) \
|
||||
X( int, pstack ) \
|
||||
X( int, maxuse_stack ) \
|
||||
X( int, maxuse_con ) \
|
||||
X( int, maxuse_efc ) \
|
||||
X( int, solver_iter ) \
|
||||
X( int, solver_nnz ) \
|
||||
X( int, ne ) \
|
||||
X( int, nf ) \
|
||||
X( int, nefc ) \
|
||||
X( int, ncon ) \
|
||||
X( mjtNum, time )
|
||||
|
||||
|
||||
// vector fields of mjData
|
||||
#define MJDATA_VECTOR \
|
||||
X( mjWarningStat, warning, mjNWARNING, 1 ) \
|
||||
X( mjTimerStat, timer, mjNTIMER, 1 ) \
|
||||
X( mjSolverStat, solver, mjNSOLVER, 1 ) \
|
||||
X( mjtNum, solver_fwdinv, 2, 1 ) \
|
||||
X( mjtNum, energy, 2, 1 )
|
||||
|
||||
#endif // MUJOCO_MJXMACRO_H_
|
||||
Executable
+1099
File diff suppressed because it is too large
Load Diff
Executable
+322
@@ -0,0 +1,322 @@
|
||||
// Copyright 2021 DeepMind Technologies Limited
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "uitools.h"
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
|
||||
|
||||
//-------------------------------- Internal GLFW callbacks ------------------------------
|
||||
|
||||
// update state
|
||||
static void uiUpdateState(GLFWwindow* wnd)
|
||||
{
|
||||
// extract data from user pointer
|
||||
uiUserPointer* ptr = (uiUserPointer*)glfwGetWindowUserPointer(wnd);
|
||||
mjuiState* state = ptr->state;
|
||||
|
||||
// mouse buttons
|
||||
state->left = (glfwGetMouseButton(wnd, GLFW_MOUSE_BUTTON_LEFT)==GLFW_PRESS);
|
||||
state->right = (glfwGetMouseButton(wnd, GLFW_MOUSE_BUTTON_RIGHT)==GLFW_PRESS);
|
||||
state->middle = (glfwGetMouseButton(wnd, GLFW_MOUSE_BUTTON_MIDDLE)==GLFW_PRESS);
|
||||
|
||||
// keyboard modifiers
|
||||
state->control = (glfwGetKey(wnd, GLFW_KEY_LEFT_CONTROL)==GLFW_PRESS ||
|
||||
glfwGetKey(wnd, GLFW_KEY_RIGHT_CONTROL)==GLFW_PRESS);
|
||||
state->shift = (glfwGetKey(wnd, GLFW_KEY_LEFT_SHIFT)==GLFW_PRESS ||
|
||||
glfwGetKey(wnd, GLFW_KEY_RIGHT_SHIFT)==GLFW_PRESS);
|
||||
state->alt = (glfwGetKey(wnd, GLFW_KEY_LEFT_ALT)==GLFW_PRESS ||
|
||||
glfwGetKey(wnd, GLFW_KEY_RIGHT_ALT)==GLFW_PRESS);
|
||||
|
||||
// swap left and right if Alt
|
||||
if( state->alt )
|
||||
{
|
||||
int tmp = state->left;
|
||||
state->left = state->right;
|
||||
state->right = tmp;
|
||||
}
|
||||
|
||||
// get mouse position, scale by buffer-to-window ratio
|
||||
double x, y;
|
||||
glfwGetCursorPos(wnd, &x, &y);
|
||||
x *= ptr->buffer2window;
|
||||
y *= ptr->buffer2window;
|
||||
|
||||
// invert y to match OpenGL convention
|
||||
y = state->rect[0].height - y;
|
||||
|
||||
// save
|
||||
state->dx = x - state->x;
|
||||
state->dy = y - state->y;
|
||||
state->x = x;
|
||||
state->y = y;
|
||||
|
||||
// find mouse rectangle
|
||||
state->mouserect = mjr_findRect(mju_round(x), mju_round(y),
|
||||
state->nrect-1, state->rect+1) + 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// keyboard
|
||||
static void uiKeyboard(GLFWwindow* wnd, int key, int scancode, int act, int mods)
|
||||
{
|
||||
// release: nothing to do
|
||||
if( act==GLFW_RELEASE )
|
||||
return;
|
||||
|
||||
// extract data from user pointer
|
||||
uiUserPointer* ptr = (uiUserPointer*)glfwGetWindowUserPointer(wnd);
|
||||
mjuiState* state = ptr->state;
|
||||
|
||||
// update state
|
||||
uiUpdateState(wnd);
|
||||
|
||||
// set key info
|
||||
state->type = mjEVENT_KEY;
|
||||
state->key = key;
|
||||
state->keytime = glfwGetTime();
|
||||
|
||||
// application-specific processing
|
||||
ptr->uiEvent(state);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// mouse button
|
||||
static void uiMouseButton(GLFWwindow* wnd, int button, int act, int mods)
|
||||
{
|
||||
// extract data from user pointer
|
||||
uiUserPointer* ptr = (uiUserPointer*)glfwGetWindowUserPointer(wnd);
|
||||
mjuiState* state = ptr->state;
|
||||
|
||||
// update state
|
||||
uiUpdateState(wnd);
|
||||
|
||||
// translate button
|
||||
if( button==GLFW_MOUSE_BUTTON_LEFT )
|
||||
button = mjBUTTON_LEFT;
|
||||
else if( button==GLFW_MOUSE_BUTTON_RIGHT )
|
||||
button = mjBUTTON_RIGHT;
|
||||
else
|
||||
button = mjBUTTON_MIDDLE;
|
||||
|
||||
// swap left and right if Alt
|
||||
if( glfwGetKey(wnd, GLFW_KEY_LEFT_ALT)==GLFW_PRESS ||
|
||||
glfwGetKey(wnd, GLFW_KEY_RIGHT_ALT)==GLFW_PRESS )
|
||||
{
|
||||
if( button==mjBUTTON_LEFT )
|
||||
button = mjBUTTON_RIGHT;
|
||||
else if( button==mjBUTTON_RIGHT )
|
||||
button = mjBUTTON_LEFT;
|
||||
}
|
||||
|
||||
// press
|
||||
if( act==GLFW_PRESS )
|
||||
{
|
||||
// detect doubleclick: 250 ms
|
||||
if( button==state->button && glfwGetTime()-state->buttontime<0.25 )
|
||||
state->doubleclick = 1;
|
||||
else
|
||||
state->doubleclick = 0;
|
||||
|
||||
// set info
|
||||
state->type = mjEVENT_PRESS;
|
||||
state->button = button;
|
||||
state->buttontime = glfwGetTime();
|
||||
|
||||
// start dragging
|
||||
if( state->mouserect )
|
||||
{
|
||||
state->dragbutton = state->button;
|
||||
state->dragrect = state->mouserect;
|
||||
}
|
||||
}
|
||||
|
||||
// release
|
||||
else
|
||||
state->type = mjEVENT_RELEASE;
|
||||
|
||||
// application-specific processing
|
||||
ptr->uiEvent(state);
|
||||
|
||||
// stop dragging after application processing
|
||||
if( state->type==mjEVENT_RELEASE )
|
||||
{
|
||||
state->dragrect = 0;
|
||||
state->dragbutton = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// mouse move
|
||||
static void uiMouseMove(GLFWwindow* wnd, double xpos, double ypos)
|
||||
{
|
||||
// extract data from user pointer
|
||||
uiUserPointer* ptr = (uiUserPointer*)glfwGetWindowUserPointer(wnd);
|
||||
mjuiState* state = ptr->state;
|
||||
|
||||
// no buttons down: nothing to do
|
||||
if( !state->left && !state->right && !state->middle )
|
||||
return;
|
||||
|
||||
// update state
|
||||
uiUpdateState(wnd);
|
||||
|
||||
// set move info
|
||||
state->type = mjEVENT_MOVE;
|
||||
|
||||
// application-specific processing
|
||||
ptr->uiEvent(state);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// scroll
|
||||
static void uiScroll(GLFWwindow* wnd, double xoffset, double yoffset)
|
||||
{
|
||||
// extract data from user pointer
|
||||
uiUserPointer* ptr = (uiUserPointer*)glfwGetWindowUserPointer(wnd);
|
||||
mjuiState* state = ptr->state;
|
||||
|
||||
// update state
|
||||
uiUpdateState(wnd);
|
||||
|
||||
// set scroll info, scale by buffer-to-window ratio
|
||||
state->type = mjEVENT_SCROLL;
|
||||
state->sx = xoffset * ptr->buffer2window;
|
||||
state->sy = yoffset * ptr->buffer2window;
|
||||
|
||||
// application-specific processing
|
||||
ptr->uiEvent(state);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// resize
|
||||
static void uiResize(GLFWwindow* wnd, int width, int height)
|
||||
{
|
||||
// extract data from user pointer
|
||||
uiUserPointer* ptr = (uiUserPointer*)glfwGetWindowUserPointer(wnd);
|
||||
mjuiState* state = ptr->state;
|
||||
|
||||
// set layout
|
||||
ptr->uiLayout(state);
|
||||
|
||||
// update state
|
||||
uiUpdateState(wnd);
|
||||
|
||||
// set resize info
|
||||
state->type = mjEVENT_RESIZE;
|
||||
|
||||
// stop dragging
|
||||
state->dragbutton = 0;
|
||||
state->dragrect = 0;
|
||||
|
||||
// application-specific processing (unless called with 0,0 from uiModify)
|
||||
if( width && height )
|
||||
ptr->uiEvent(state);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//----------------------------------- Public API ----------------------------------------
|
||||
|
||||
// Compute suitable font scale.
|
||||
int uiFontScale(GLFWwindow* wnd)
|
||||
{
|
||||
// compute framebuffer-to-window ratio
|
||||
int width_win, width_buf, height;
|
||||
glfwGetWindowSize(wnd, &width_win, &height);
|
||||
glfwGetFramebufferSize(wnd, &width_buf, &height);
|
||||
double b2w = (double)width_buf / (double)width_win;
|
||||
|
||||
// compute PPI
|
||||
int width_MM, height_MM;
|
||||
glfwGetMonitorPhysicalSize(glfwGetPrimaryMonitor(), &width_MM, &height_MM);
|
||||
int width_vmode = glfwGetVideoMode(glfwGetPrimaryMonitor())->width;
|
||||
double PPI = 25.4 * b2w * (double)width_vmode / (double)width_MM;
|
||||
|
||||
// estimate font scaling, guard against unrealistic PPI
|
||||
int fs;
|
||||
if( width_buf>width_win )
|
||||
fs = mju_round(b2w * 100);
|
||||
else if( PPI>50 && PPI<350 )
|
||||
fs = mju_round(PPI);
|
||||
else
|
||||
fs = 150;
|
||||
fs = mju_round(fs * 0.02) * 50;
|
||||
fs = mjMIN(300, mjMAX(100, fs));
|
||||
|
||||
return fs;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Set internal and user-supplied UI callbacks in GLFW window.
|
||||
void uiSetCallback(GLFWwindow* wnd, mjuiState* state,
|
||||
uiEventFn uiEvent, uiLayoutFn uiLayout)
|
||||
{
|
||||
// make container with user-supplied objects and set window pointer
|
||||
uiUserPointer* ptr = (uiUserPointer*) mju_malloc(sizeof(uiUserPointer));
|
||||
ptr->state = state;
|
||||
ptr->uiEvent = uiEvent;
|
||||
ptr->uiLayout = uiLayout;
|
||||
glfwSetWindowUserPointer(wnd, ptr);
|
||||
|
||||
// compute framebuffer-to-window pixel ratio
|
||||
int width_win, width_buf, height;
|
||||
glfwGetWindowSize(wnd, &width_win, &height);
|
||||
glfwGetFramebufferSize(wnd, &width_buf, &height);
|
||||
ptr->buffer2window = (double)width_buf / (double)width_win;
|
||||
|
||||
// set internal callbacks
|
||||
glfwSetKeyCallback(wnd, uiKeyboard);
|
||||
glfwSetCursorPosCallback(wnd, uiMouseMove);
|
||||
glfwSetMouseButtonCallback(wnd, uiMouseButton);
|
||||
glfwSetScrollCallback(wnd, uiScroll);
|
||||
glfwSetWindowSizeCallback(wnd, uiResize);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Clear UI callbacks in GLFW window.
|
||||
void uiClearCallback(GLFWwindow* wnd)
|
||||
{
|
||||
// clear container
|
||||
if( glfwGetWindowUserPointer(wnd) )
|
||||
{
|
||||
mju_free(glfwGetWindowUserPointer(wnd));
|
||||
glfwSetWindowUserPointer(wnd, NULL);
|
||||
}
|
||||
|
||||
// clear internal callbacks
|
||||
glfwSetKeyCallback(wnd, NULL);
|
||||
glfwSetCursorPosCallback(wnd, NULL);
|
||||
glfwSetMouseButtonCallback(wnd, NULL);
|
||||
glfwSetScrollCallback(wnd, NULL);
|
||||
glfwSetWindowSizeCallback(wnd, NULL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Modify UI structure.
|
||||
void uiModify(GLFWwindow* wnd, mjUI* ui, mjuiState* state, mjrContext* con)
|
||||
{
|
||||
mjui_resize(ui, con);
|
||||
mjr_addAux(ui->auxid, ui->width, ui->maxheight, ui->spacing.samples, con);
|
||||
uiResize(wnd, 0, 0);
|
||||
mjui_update(-1, -1, ui, state, con);
|
||||
}
|
||||
Executable
+62
@@ -0,0 +1,62 @@
|
||||
// Copyright 2021 DeepMind Technologies Limited
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef MUJOCO_UITOOLS_H_
|
||||
#define MUJOCO_UITOOLS_H_
|
||||
|
||||
|
||||
#include "mujoco.h"
|
||||
#include "glfw3.h"
|
||||
|
||||
|
||||
// this is a C-API
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
|
||||
// User-supplied callback function types.
|
||||
typedef void (*uiEventFn)(mjuiState* state);
|
||||
typedef void (*uiLayoutFn)(mjuiState* state);
|
||||
|
||||
// Container for GLFW window pointer.
|
||||
struct _uiUserPointer
|
||||
{
|
||||
mjuiState* state;
|
||||
uiEventFn uiEvent;
|
||||
uiLayoutFn uiLayout;
|
||||
double buffer2window;
|
||||
};
|
||||
typedef struct _uiUserPointer uiUserPointer;
|
||||
|
||||
// Set internal and user-supplied UI callbacks in GLFW window.
|
||||
void uiSetCallback(GLFWwindow* wnd, mjuiState* state,
|
||||
uiEventFn uiEvent, uiLayoutFn uiLayout);
|
||||
|
||||
// Clear UI callbacks in GLFW window.
|
||||
void uiClearCallback(GLFWwindow* wnd);
|
||||
|
||||
// Compute suitable font scale.
|
||||
int uiFontScale(GLFWwindow* wnd);
|
||||
|
||||
// Modify UI structure.
|
||||
void uiModify(GLFWwindow* wnd, mjUI* ui, mjuiState* state, mjrContext* con);
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // MUJOCO_UITOOLS_H_
|
||||
Reference in New Issue
Block a user