static int IPhysicsObject_CalculateForceOffset (lua_State *L) {
  Vector centerForce, centerTorque;
  luaL_checkphysicsobject(L, 1)->CalculateForceOffset(luaL_checkvector(L, 2), luaL_checkvector(L, 3), &centerForce, &centerTorque);
  lua_pushvector(L, centerForce);
  lua_pushvector(L, centerTorque);
  return 2;
}
static int IPhysicsObject_GetVelocity (lua_State *L) {
  Vector velocity, angularVelocity;
  luaL_checkphysicsobject(L, 1)->GetVelocity(&velocity, &angularVelocity);
  lua_pushvector(L, velocity);
  lua_pushvector(L, angularVelocity);
  return 2;
}
static int IPhysicsObject_CalculateVelocityOffset (lua_State *L) {
  Vector centerVelocity, centerAngularVelocity;
  luaL_checkphysicsobject(L, 1)->CalculateVelocityOffset(luaL_checkvector(L, 2), luaL_checkvector(L, 3), &centerVelocity, &centerAngularVelocity);
  lua_pushvector(L, centerVelocity);
  lua_pushvector(L, centerAngularVelocity);
  return 2;
}
Exemplo n.º 4
0
int CLuaVector4Defs::Div ( lua_State* luaVM )
{
    CLuaVector4D* pVector1 = NULL;
    CLuaVector4D* pVector2 = NULL;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pVector1 );

    if ( argStream.NextIsNumber () )
    {
        float fValue = 0.0f;
        argStream.ReadNumber ( fValue );

        lua_pushvector ( luaVM, *pVector1 / fValue );
        return 1;
    }
    else
    {
        argStream.ReadUserData ( pVector2 );

        if ( !argStream.HasErrors () )
        {
            lua_pushvector ( luaVM, *pVector1 / *pVector2 );
            return 1;
        }
        else
        {
            m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );
        }
    }

    lua_pushboolean ( luaVM, false );
    return 1;
}
Exemplo n.º 5
0
static int CBaseEntity_GetVelocity (lua_State *L) {
  Vector vVelocity;
  AngularImpulse vAngVelocity;
  luaL_checkentity(L, 1)->GetVelocity(&vVelocity, &vAngVelocity);
  lua_pushvector(L, vVelocity);
  lua_pushvector(L, (Vector &)vAngVelocity);
  return 2;
}
Exemplo n.º 6
0
/*
** Open Vector object
*/
int luaopen_Vector (lua_State *L) {
  luaL_newmetatable(L, "Vector");
  luaL_register(L, NULL, Vectormeta);
  lua_pushstring(L, "vector");
  lua_setfield(L, -2, "__type");  /* metatable.__type = "vector" */
  luaL_register(L, "_G", Vector_funcs);
  lua_pop(L, 2);
  Vector origin = vec3_origin;
  lua_pushvector(L, &origin);
  lua_setglobal(L, "vec3_origin");  /* set global vec3_origin */
  Vector invalid = vec3_invalid;
  lua_pushvector(L, &invalid);
  lua_setglobal(L, "vec3_invalid");  /* set global vec3_invalid */
  return 1;
}
Exemplo n.º 7
0
static int vectorL_sub__( lua_State *L )
{
   Vector2d *v1, *v2;
   double x, y;

   /* Get self. */
   v1    = luaL_checkvector(L,1);

   /* Get rest of parameters. */
   v2 = NULL;
   if (lua_isvector(L,2)) {
      v2 = lua_tovector(L,2);
      x = v2->x;
      y = v2->y;
   }
   else if ((lua_gettop(L) > 2) && lua_isnumber(L,2) && lua_isnumber(L,3)) {
      x = lua_tonumber(L,2);
      y = lua_tonumber(L,3);
   }
   else {
      NLUA_INVALID_PARAMETER(L);
      return 0;
   }

   /* Actually add it */
   vect_cset( v1, v1->x - x, v1->y - y );
   lua_pushvector( L, *v1 );
   return 1;
}
Exemplo n.º 8
0
/**
 * @brief Subtracts two vectors or a vector and some cartesian coordinates.
 *
 * If x is a vector it subtracts both vectors, otherwise it subtracts cartesian
 * coordinates to the vector.
 *
 * @usage my_vec = my_vec - your_vec
 * @usage my_vec:sub( your_vec )
 * @usage my_vec:sub( 5, 3 )
 *
 *    @luaparam v Vector getting stuff subtracted from.
 *    @luaparam x X coordinate or vector to subtract.
 *    @luaparam y Y coordinate or nil to subtract.
 *    @luareturn The result of the vector operation.
 * @luafunc sub( v, x, y )
 */
static int vectorL_sub( lua_State *L )
{
    LuaVector vout, *v1, *v2;
    double x, y;

    /* Get self. */
    v1    = luaL_checkvector(L,1);

    /* Get rest of parameters. */
    v2 = NULL;
    if (lua_isvector(L,2)) {
        v2 = lua_tovector(L,2);
        x = v2->vec.x;
        y = v2->vec.y;
    }
    else if ((lua_gettop(L) > 2) && lua_isnumber(L,2) && lua_isnumber(L,3)) {
        x = lua_tonumber(L,2);
        y = lua_tonumber(L,3);
    }
    else NLUA_INVALID_PARAMETER(L);

    /* Actually add it */
    vect_cset( &vout.vec, v1->vec.x - x, v1->vec.y - y );
    lua_pushvector( L, vout );
    return 1;
}
Exemplo n.º 9
0
int CLuaMarkerDefs::OOP_GetMarkerTarget(lua_State* luaVM)
{
    CMarker* pMarker = NULL;

    CScriptArgReader argStream(luaVM);
    argStream.ReadUserData(pMarker);

    if (!argStream.HasErrors())
    {
        CVector vecPosition;
        if (CStaticFunctionDefinitions::GetMarkerTarget(pMarker, vecPosition))
        {
            lua_pushvector(luaVM, vecPosition);
        }
        else
            lua_pushboolean(luaVM, false);

        return 1;
    }
    else
        m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());

    lua_pushboolean(luaVM, false);
    return 1;
}
Exemplo n.º 10
0
/**
 * @brief Gets the position of the planet in the system.
 *
 * @usage v = p:pos()
 *    @luatparam Planet p Planet to get the position of.
 *    @luatreturn Vec2 The position of the planet in the system.
 * @luafunc pos( p )
 */
static int planetL_position( lua_State *L )
{
   Planet *p;
   p = luaL_validplanet(L,1);
   lua_pushvector(L, p->pos);
   return 1;
}
Exemplo n.º 11
0
int CLuaVector4Defs::Dot ( lua_State* luaVM )
{
    CLuaVector4D* pVector1 = NULL;
    CLuaVector4D* pVector2 = NULL;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pVector1 );
    argStream.ReadUserData ( pVector2 );

    if ( !argStream.HasErrors () )
    {
        CVector4D vector ( *pVector1 );
        vector.DotProduct ( *pVector2 );

        lua_pushvector ( luaVM, vector );
        return 1;
    }
    else
    {
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );
    }

    lua_pushboolean ( luaVM, false );
    return 1;
}
Exemplo n.º 12
0
/**
 * @brief Gets the position of the jump in the system.
 *
 * @usage v = j:pos()
 *    @luaparam j Jump to get the position of.
 *    @luareturn The position of the jump in the system as a vec2.
 * @luafunc pos( j )
 */
static int jumpL_position( lua_State *L )
{
   JumpPoint *jp;
   jp = luaL_validjump(L,1);
   lua_pushvector(L, jp->pos);
   return 1;
}
Exemplo n.º 13
0
static int l_uc_C(lua_State* L)
{
	UnitCell* uc = lua_tounitcell(L, 1);
	if(!uc) return 0;

	lua_pushvector(L, new Vector(uc->C()));
	return 1;
}
static int IPhysicsObject_GetShadowPosition (lua_State *L) {
  Vector position;
  QAngle angles;
  lua_pushinteger(L, luaL_checkphysicsobject(L, 1)->GetShadowPosition(&position, &angles));
  lua_pushvector(L, position);
  lua_pushangle(L, angles);
  return 3;
}
static int IPhysicsObject_GetContactPoint (lua_State *L) {
  Vector contactPoint;
  IPhysicsObject *contactObject;
  lua_pushboolean(L, luaL_checkphysicsobject(L, 1)->GetContactPoint(&contactPoint, &contactObject));
  lua_pushvector(L, contactPoint);
  lua_pushphysicsobject(L, contactObject);
  return 3;
}
static int IPhysicsObject_GetPosition (lua_State *L) {
  Vector worldPosition;
  QAngle angles;
  luaL_checkphysicsobject(L, 1)->GetPosition(&worldPosition, &angles);
  lua_pushvector(L, worldPosition);
  lua_pushangle(L, angles);
  return 2;
}
Exemplo n.º 17
0
static int CBaseEntity_GetInputDispatchEffectPosition (lua_State *L) {
  Vector pVector;
  QAngle pAngle;
  luaL_checkentity(L, 1)->GetInputDispatchEffectPosition(luaL_checkstring(L, 2), pVector, pAngle);
  lua_pushvector(L, pVector);
  lua_pushangle(L, pAngle);
  return 2;
}
Exemplo n.º 18
0
static int l_atom_getpos(lua_State* L)
{
	Atom* a = lua_toatom(L, 1);
	if(!a) return 0;

	lua_pushvector(L, new Vector(a->pos()));
	return 1;
}
Exemplo n.º 19
0
/**
 * @brief Gets the player's position.
 *
 * @usage v = player.pos()
 *
 *    @luareturn The position of the player (Vec2).
 * @luafunc pos()
 */
static int playerL_getPosition( lua_State *L )
{
   LuaVector v;

   vectcpy( &v.vec, &player.p->solid->pos );
   lua_pushvector(L, v);
   return 1;
}
Exemplo n.º 20
0
int CLuaVector4Defs::Pow ( lua_State* luaVM )
{
    CLuaVector4D* pVector1 = NULL;
    CLuaVector4D* pVector2 = NULL;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pVector1 );

    if ( argStream.NextIsNumber () )
    {
        float fValue = 0.0f;
        argStream.ReadNumber ( fValue );

        CVector4D vector ( *pVector1 );
        vector.fX = pow ( vector.fX, fValue );
        vector.fY = pow ( vector.fY, fValue );
        vector.fZ = pow ( vector.fZ, fValue );
        vector.fW = pow ( vector.fW, fValue );

        lua_pushvector ( luaVM, vector );
        return 1;
    }
    else
    {
        argStream.ReadUserData ( pVector2 );

        if ( !argStream.HasErrors () )
        {
            CVector4D vector ( *pVector1 );
            vector.fX = pow ( vector.fX, pVector2->fX );
            vector.fY = pow ( vector.fY, pVector2->fY );
            vector.fZ = pow ( vector.fZ, pVector2->fZ );
            vector.fW = pow ( vector.fW, pVector2->fW );

            lua_pushvector ( luaVM, vector );
            return 1;
        }
        else
        {
            m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );
        }
    }

    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaOOPDefs::GetCameraRotation ( lua_State* luaVM )
{
    CVector vecPosition;
    m_pManager->GetCamera ()->GetRotationDegrees ( vecPosition );

    lua_pushvector ( luaVM, vecPosition );
    return 1;
}
Exemplo n.º 22
0
int CLuaVector2Defs::Create ( lua_State* luaVM )
{
    CVector2D vector;

    CScriptArgReader argStream ( luaVM );
    if ( argStream.NextIsTable () )
    {
        lua_pushvalue ( luaVM, 1 );

        lua_pushstring ( luaVM, "x" );
        lua_rawget ( luaVM, -2 );
        if ( lua_isnumber ( luaVM, -1 ) )
        {
            vector.fX = ( float ) lua_tonumber ( luaVM, -1 );
            lua_pop ( luaVM, 1 );
        }
        else
        {
            lua_pop ( luaVM, 1 );
            lua_rawgeti ( luaVM, -1, 1 );
            if ( lua_isnumber ( luaVM, -1 ) )
                vector.fX = ( float ) lua_tonumber ( luaVM, -1 );
            lua_pop ( luaVM, 1 );
        }

        lua_pushstring ( luaVM, "y" );
        lua_rawget ( luaVM, -2 );
        if ( lua_isnumber ( luaVM, -1 ) )
        {
            vector.fY = ( float ) lua_tonumber ( luaVM, -1 );
            lua_pop ( luaVM, 1 );
        }
        else
        {
            lua_pop ( luaVM, 1 );
            lua_rawgeti ( luaVM, -1, 2 );
            if ( lua_isnumber ( luaVM, -1 ) )
                vector.fY = ( float ) lua_tonumber ( luaVM, -1 );
            lua_pop ( luaVM, 1 );
        }
    }
    else if ( argStream.NextIsNumber () )
    {
        argStream.ReadNumber ( vector.fX );
        if ( argStream.NextIsNumber () )
        {
            argStream.ReadNumber ( vector.fY );
        }
    }
    else if ( argStream.NextIsVector2D () )
    {
        argStream.ReadVector2D ( vector );
    }

    lua_pushvector ( luaVM, vector );
    return 1;
}
Exemplo n.º 23
0
/**
 * @brief Gets the position of the jump in the system.
 *
 * @usage v = j:pos()
 *    @luaparam j Jump to get the position of.
 *    @luareturn The position of the jump in the system as a vec2.
 * @luafunc pos( j )
 */
static int jumpL_position( lua_State *L )
{
   JumpPoint *jp;
   LuaVector v;
   jp = luaL_validjump(L,1);
   vectcpy(&v.vec, &jp->pos);
   lua_pushvector(L, v);
   return 1;
}
Exemplo n.º 24
0
/**
 * @brief Gets the position of the planet in the system.
 *
 * @usage v = p:pos()
 *    @luaparam p Planet to get the position of.
 *    @luareturn The position of the planet in the system as a vec2.
 * @luafunc pos( p )
 */
static int planetL_position( lua_State *L )
{
   LuaPlanet *p;
   LuaVector v;
   p = luaL_checkplanet(L,1);
   vectcpy(&v.vec, &p->p->pos);
   lua_pushvector(L, v);
   return 1;
}
Exemplo n.º 25
0
static int inverse_leg(lua_State *L) {
  std::vector<double> qLeg;
  std::vector<double> pLeg = lua_checkvector(L, 1);
  int leg = luaL_checkint(L, 2);
  double hipYawPitch = 0;
  Transform trLeg = transform6D(&pLeg[0]);
  qLeg = darwinop_kinematics_inverse_leg(trLeg, leg, hipYawPitch);
  lua_pushvector(L, qLeg);
  return 1;
}
Exemplo n.º 26
0
void lua_pushtrace(lua_State *L, trace_t results) {
	lua_newtable(L);

	if(results.fraction != 1.0) {
		lua_pushstring(L, "allsolid");
		lua_pushboolean(L,results.allsolid);
		lua_rawset(L, -3);

		lua_pushstring(L, "contents");
		lua_pushinteger(L,results.contents);
		lua_rawset(L, -3);

		if(results.entityNum != ENTITYNUM_MAX_NORMAL) {
			lua_pushstring(L, "entity");
			lua_pushentity(L,&cg_entities[ results.entityNum ]);
			lua_rawset(L, -3);
		}

		lua_pushstring(L, "normal");
		lua_pushvector(L,results.plane.normal);
		lua_rawset(L, -3);

		lua_pushstring(L, "surfaceflags");
		lua_pushinteger(L,results.surfaceFlags);
		lua_rawset(L, -3);
	}

	lua_pushstring(L, "startsolid");
	lua_pushboolean(L,results.startsolid);
	lua_rawset(L, -3);

	lua_pushstring(L, "endpos");
	lua_pushvector(L,results.endpos);
	lua_rawset(L, -3);

	lua_pushstring(L, "fraction");
	lua_pushnumber(L,results.fraction);
	lua_rawset(L, -3);

	lua_pushstring(L, "hit");
	lua_pushboolean(L, (results.fraction != 1.0));
	lua_rawset(L, -3);
}
Exemplo n.º 27
0
static int inverse_arm(lua_State *L) {
  std::vector<double> qArm;
  std::vector<double> dArm = lua_checkvector(L, 1);
  qArm = darwinop_kinematics_inverse_arm(&dArm[0]);
  if(qArm[0]==-999)
    lua_pushnil(L);    
  else
    lua_pushvector(L, qArm);
  return 1;
}
Exemplo n.º 28
0
int qlua_getlerpangles(lua_State *L) {
	centity_t	*luaentity;

	luaL_checktype(L,1,LUA_TUSERDATA);

	luaentity = lua_toentity(L,1);
	if(luaentity != NULL) {
		lua_pushvector(L,luaentity->lerpAngles);
		return 1;
	}
	return 0;
}
Exemplo n.º 29
0
void lua_pushuserdata ( lua_State* luaVM, void* pData )
{
    if ( CClientEntity* pEntity = UserDataCast < CClientEntity > ( ( CClientEntity* ) NULL, pData, luaVM ) )
        return lua_pushelement ( luaVM, pEntity );
    else if ( CResource* pResource = UserDataCast < CResource > ( ( CResource* ) NULL, pData, luaVM ) )
        return lua_pushresource ( luaVM, pResource );
    else if ( CXMLNode* pNode = UserDataCast < CXMLNode > ( ( CXMLNode* ) NULL, pData, luaVM ) )
        return lua_pushxmlnode ( luaVM, pNode );
    else if ( CLuaTimer* pTimer = UserDataCast < CLuaTimer > ( ( CLuaTimer* ) NULL, pData, luaVM ) )
        return lua_pushtimer ( luaVM, pTimer );
    else if ( CLuaVector2D* pVector = UserDataCast < CLuaVector2D > ( (CLuaVector2D*) NULL, pData, luaVM ) )
        return lua_pushvector ( luaVM,* pVector );
    else if ( CLuaVector3D* pVector = UserDataCast < CLuaVector3D > ( (CLuaVector3D*) NULL, pData, luaVM ) )
        return lua_pushvector ( luaVM, *pVector );
    else if ( CLuaVector4D* pVector = UserDataCast < CLuaVector4D > ( (CLuaVector4D*) NULL, pData, luaVM ) )
        return lua_pushvector ( luaVM, *pVector );
    else if ( CLuaMatrix* pMatrix = UserDataCast < CLuaMatrix > ( (CLuaMatrix*) NULL, pData, luaVM ) )
        return lua_pushmatrix ( luaVM, *pMatrix );

    lua_pushobject ( luaVM, NULL, pData );
}
Exemplo n.º 30
0
int qlua_aimvec(lua_State *L) {
	centity_t	*luaentity;

	luaL_checktype(L,1,LUA_TUSERDATA);

	luaentity = lua_toentity(L,1);
	if(luaentity != NULL) {
		lua_pushvector(L,luaentity->currentState.angles);
		return 1;
	}
	return 0;
}