示例#1
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;
}
示例#2
0
int qlua_ProjectToPlane(lua_State *L) {
	vec3_t dst,src,plane;

	luaL_checktype(L,1,LUA_TVECTOR);
	luaL_checktype(L,2,LUA_TVECTOR);
	luaL_checktype(L,3,LUA_TVECTOR);
	
	lua_tovector(L,1,src);
	lua_tovector(L,2,plane);
	lua_tovector(L,3,dst);

	ProjectPointOnPlane(dst,src,plane);

	lua_pushvector(L,dst);
	return 1;
}
示例#3
0
文件: nlua_vec2.c 项目: Elderman/naev
/**
 * @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;
}
示例#4
0
文件: model.c 项目: ForsakenX/6dof
struct model *luaL_checkmodel(lua_State *L, int index)
{
	int n, i;
	struct mesh *group;
	vector offset;
	struct model *m;

	n = lua_objlen(L, index);
	if (n <= 0)
	{
		luaL_error(L, "invalid table length at index %d", index);
	}
	m = model_create(NULL);
	for (i=0; i<n; i++)
	{
		lua_getfieldi(L, index, i+1);
		group = luaL_checkmesh(L, -1);
		lua_getfield(L, -1, "offset");
		if (lua_isvector(L, -1))
			lua_tovector(L, -1, &offset);
		else
			offset.x = offset.y = offset.z = 0.0f;
		lua_pop(L, 2);
		model_addgroup(m, group, &offset);
		mesh_destroy(group);
	}

	return m;
}
示例#5
0
int qlua_VectorRotate(lua_State *L) {
	vec3_t in,out;
	vec3_t axis[3];

	luaL_checktype(L,1,LUA_TVECTOR);
	luaL_checktype(L,2,LUA_TVECTOR);
	luaL_checktype(L,3,LUA_TVECTOR);
	luaL_checktype(L,4,LUA_TVECTOR);

	lua_tovector(L,1,in);
	lua_tovector(L,2,axis[0]);
	lua_tovector(L,3,axis[1]);
	lua_tovector(L,4,axis[2]);

	VectorRotate(in,axis,out);

	lua_pushvector(L,out);
	return 1;
}
示例#6
0
void qlua_pullvector_i(lua_State *L, int i, vec3_t vec, qboolean req, int m) {
	vec3_t v;
	VectorClear(v);
	lua_pushinteger(L,i);
	lua_gettable(L,m);
	if(req) luaL_checktype(L,lua_gettop(L),LUA_TVECTOR);
	if(lua_type(L,lua_gettop(L)) == LUA_TVECTOR) {
		lua_tovector(L,lua_gettop(L),v);
		vec[0] = v[0];
		vec[1] = v[1];
		vec[2] = v[2];
	}
}
示例#7
0
void qlua_pullvector(lua_State *L, char *str, vec3_t vec, qboolean req) {
	vec3_t v;
	VectorClear(v);
	lua_pushstring(L,str);
	lua_gettable(L,1);
	if(req) luaL_checktype(L,lua_gettop(L),LUA_TVECTOR);
	if(lua_type(L,lua_gettop(L)) == LUA_TVECTOR) {
		lua_tovector(L,lua_gettop(L),v);
		vec[0] = v[0];
		vec[1] = v[1];
		vec[2] = v[2];
	}
}
示例#8
0
int qlua_trace(lua_State *L) {
	trace_t results;
	vec3_t start, end;
	vec3_t mins, maxs;
	centity_t *ent;
	int pass=ENTITYNUM_NONE, mask=MASK_ALL;
	int top = lua_gettop(L);

	if(top > 1) {
		lua_tovector(L,1,start);
		lua_tovector(L,2,end);
		VectorSet(mins,vec3_origin[0],vec3_origin[1],vec3_origin[2]);
		VectorSet(maxs,vec3_origin[0],vec3_origin[1],vec3_origin[2]);
		if(top > 2) {
			if(lua_type(L,3) == LUA_TNUMBER) {
				pass = lua_tointeger(L,3);
			} else if(lua_type(L,3) == LUA_TUSERDATA) {
				ent = lua_toentity(L,3);
				if(ent != NULL) {
					pass = ent->currentState.number;
				}
			}
			if(top > 3)
				mask = lua_tointeger(L,4);
			if(top > 4) {
				if(lua_type(L,5) == LUA_TVECTOR) lua_tovector(L,5,mins);
				if(lua_type(L,6) == LUA_TVECTOR) lua_tovector(L,6,maxs);
			}
		}
		CG_Trace(&results,start,mins,maxs,end,pass,mask);

		lua_pushtrace(L, results);

		return 1;
	}


	return 0;
}
示例#9
0
int qlua_setangles(lua_State *L) {
	centity_t	*luaentity;

	luaL_checktype(L,1,LUA_TUSERDATA);
	luaL_checktype(L,2,LUA_TVECTOR);

	luaentity = lua_toentity(L,1);
	if(luaentity != NULL) {
		lua_tovector(L,2,luaentity->currentState.angles);
		return 1;
	}
	return 0;
}
示例#10
0
int qlua_ProjectVector(lua_State *L) {
	vec3_t in;
	vec3_t out;
	refdef_t		refdef;
	
	memset( &refdef, 0, sizeof( refdef ) );
	lua_torefdef(L,1,&refdef,qtrue);

	luaL_checktype(L,2,LUA_TVECTOR);
	lua_tovector(L,2,in);
	
	CG_ProjectVector(refdef,in,out);

	lua_pushvector(L,out);
	return 1;
}
示例#11
0
int luautil_pointcontents(lua_State *L) {
	vec3_t point;
	int pass = -1;
	int contents;

	//luaL_checkudata(L,1,"Vector");
	if(lua_type(L,1) != LUA_TUSERDATA) return 0;

	lua_tovector(L,1,point);

	if(lua_type(L,2) == LUA_TNUMBER) {
		pass = lua_tonumber(L,2);
	}
	contents = trap_PointContents(point,pass);

	lua_pushinteger(L,contents);
	return 1;
}
示例#12
0
int qlua_setpos(lua_State *L) {
	centity_t	*luaentity;
	vec3_t		origin;

	luaL_checktype(L,1,LUA_TUSERDATA);
	luaL_checktype(L,2,LUA_TVECTOR);

	luaentity = lua_toentity(L,1);
	if(luaentity != NULL) {
			BG_EvaluateTrajectory( &luaentity->currentState.pos, cg.time, origin );
			lua_tovector(L,2,luaentity->currentState.pos.trBase);
			luaentity->currentState.pos.trDuration += (cg.time - luaentity->currentState.pos.trTime);
			luaentity->currentState.pos.trTime = cg.time;
			
			VectorCopy(luaentity->currentState.pos.trBase, luaentity->currentState.origin);
		return 1;
	}
	return 0;
}
示例#13
0
LUALIB_API lua_Vector *luaL_checkvector (lua_State *L, int narg) {
  lua_Vector *d = lua_tovector(L, narg);
  if (d == NULL)  /* avoid extra test when d is not 0 */
    luaL_typerror(L, narg, "Vector");
  return d;
}