// vector.DotProduct(vec1/self, vec2)
static int GLua_Vector_DotProduct(lua_State *L) {
	GLuaVec_t *vec1;
	GLuaVec_t *vec2;

	vec1 = GLua_CheckVector(L,1);
	vec2 = GLua_CheckVector(L,2);
	
	return vec1->x*vec2->x + vec1->y*vec2->y + vec1->z*vec2->z;
}
// vector.sub(self, vec)
static int GLua_Vector_Sub2(lua_State *L) {
	GLuaVec_t *self;
	GLuaVec_t *vec;

	self = GLua_CheckVector(L,1);
	vec = GLua_CheckVector(L,2);
	
	self->x -= vec->x;
	self->y -= vec->y;
	self->z -= vec->z;
	return 0;
}
Esempio n. 3
0
static int GLua_Sys_PlayEffect(lua_State *L) {
	vec3_t org, angs;
	GLuaVec_t *org2, *angs2;
	org2 = GLua_CheckVector(L,2);
	ConvertVec(org2, org);
	if (!lua_isnoneornil(L,3)) {
		angs2 = GLua_CheckVector(L,2);
		ConvertVec(angs2, angs);
	} else {
		VectorClear(angs);
	}
	G_PlayEffectID(luaL_checkint(L,1), org, angs);
	return 0;
}
// vector.__eq(vec1, vec2)
static int GLua_Vector_Eq(lua_State *L) {
	GLuaVec_t *vec1;
	GLuaVec_t *vec2;

	vec1 = GLua_CheckVector(L,1);
	vec2 = GLua_CheckVector(L,2);
	
	if ((vec1->x == vec2->x) && (vec1->y == vec2->y) && (vec1->z == vec2->z)) {
		lua_pushboolean(L,1);
	} else {
		lua_pushboolean(L,0);
	}
	return 1;
}
// vector.__sub(vec1, vec2)
static int GLua_Vector_Sub(lua_State *L) {
	GLuaVec_t *vec1;
	GLuaVec_t *vec2;
	GLuaVec_t *vec3;

	vec1 = GLua_CheckVector(L,1);
	vec2 = GLua_CheckVector(L,2);
	
	vec3 = (GLuaVec_t *)lua_newuserdata(L,12);
	vec3->x = vec1->x - vec2->x;
	vec3->y = vec1->y - vec2->y;
	vec3->z = vec1->z - vec2->z;
	luaL_getmetatable(L,"Vector");
	lua_setmetatable(L,-2);
	return 1;
}
// vector.__tostring(self)
static int GLua_Vector_ToString(lua_State *L) {
	GLuaVec_t *vec;
	vec = GLua_CheckVector(L, 1);
	
	lua_pushfstring(L, "Vector (%f %f %f)",vec->x, vec->y, vec->z);
	return 1;
}
// vector.__NewIndex(self, key, value)
static int GLua_Vector_NewIndex(lua_State *L) {
	GLuaVec_t *vec;
	const char *key;
	float value;

	vec = GLua_CheckVector(L,1);
	key = lua_tostring(L,2);

	// its not a meta function, check if its 'x', 'y' or 'z'
	if (!strcmp(key,"x")) {
		value = luaL_checknumber(L,3);
		vec->x = value;
		return 0;
	}
	if (!strcmp(key,"y")) {
		value = luaL_checknumber(L,3);
		vec->y = value;
		return 0;
	}
	if (!strcmp(key,"z")) {
		value = luaL_checknumber(L,3);
		vec->z = value;
		return 0;
	}
	return 0;
}
// vector.Distance(self, vec)
static int GLua_Vector_Distance(lua_State *L) {
	GLuaVec_t *self;
	GLuaVec_t *vec;

	GLuaVec_t distvec;

	self = GLua_CheckVector(L,1);
	vec = GLua_CheckVector(L,2);
	
	distvec.x = self->x - vec->x;
	distvec.y = self->y - vec->y;
	distvec.z = self->z - vec->z;


	return sqrt(distvec.x*distvec.x + distvec.y*distvec.y + distvec.z*distvec.z);
}	
// vector.__Index(self, key)
static int GLua_Vector_Index(lua_State *L) {
	GLuaVec_t *vec;
	const char *key;
	vec = GLua_CheckVector(L, 1);
	key = lua_tostring(L,2);
	
	// See if this key is a function/constant in the metatable
	lua_getmetatable(L,1);
	lua_getfield(L,-1,key);
	if (!lua_isnil(L,-1)) {
		return 1;
	}
	// its not a meta function, check if its 'x', 'y' or 'z'
	if (!strcmp(key,"x")) {
		lua_pushnumber(L,vec->x);
		return 1;
	}
	if (!strcmp(key,"y")) {
		lua_pushnumber(L,vec->y);
		return 1;
	}
	if (!strcmp(key,"z")) {
		lua_pushnumber(L,vec->z);
		return 1;
	}
	// None of these, we requested a nonexisting key, return nil
	lua_pushnil(L);
	return 1;
}
static int GLua_Vector_CrossProduct(lua_State *L) {
	GLuaVec_t *self;
	GLuaVec_t *vec;
	GLuaVec_t *vec2;

	self = GLua_CheckVector(L,1);
	vec = GLua_CheckVector(L,2);
	
	vec2 = (GLuaVec_t *)lua_newuserdata(L,12);
	vec2->x = self->y*vec->z - self->z*vec->y; 
	vec2->y = self->z*vec->x - self->x*vec->z;
	vec2->z = self->x*vec->y - self->y*vec->x; 
	luaL_getmetatable(L,"Vector");
	lua_setmetatable(L,-2);
	return 1;
}
// vector.Length(vec1)
static int GLua_Vector_Length(lua_State *L) {
	GLuaVec_t *vec;

	vec = GLua_CheckVector(L,1);
	
	lua_pushnumber(L, sqrt((vec->x * vec->x)+(vec->y * vec->y)+(vec->z * vec->z)));
	return 1;
}
Esempio n. 12
0
static int GLua_Sys_PlaySound(lua_State *L) {
	vec3_t org;
	GLuaVec_t *org2;
	org2 = GLua_CheckVector(L,1);
	ConvertVec(org2, org);

	G_SoundAtLoc(org, luaL_checkint(L,2), G_SoundIndex(luaL_checkstring(L,3)));
	return 0;
}
// vector.Scale(self, scale)
static int GLua_Vector_Scale(lua_State *L) {
	GLuaVec_t *self;
	float scale;

	self = GLua_CheckVector(L,1);
	scale = luaL_checknumber(L,2);
	
	self->x *= scale;
	self->y *= scale;
	self->z *= scale;
	return 0;
}
Esempio n. 14
0
static int GLua_Sys_SpotWouldTelefrag(lua_State *L) {
	gentity_t *ent = GLua_CheckEntity(L, 1);
	GLuaVec_t *vec = GLua_CheckVector(L, 2);
	vec3_t vec2;
	ConvertVec(vec, vec2);
	if (SpotWouldTelefrag2(ent, vec2)) {
		lua_pushboolean(L, 1);
	} else {
		lua_pushboolean(L, 0);
	}
	return 1;
}
static int GLua_Vector_ToAngles(lua_State *L) {
	GLuaVec_t *self;
	vec3_t vec2;

	self = GLua_CheckVector(L,1);

	vectoangles((const vec_t *)self, vec2);

	self->x = vec2[0];
	self->y = vec2[1];
	self->z = vec2[2];
	return 0;
}
Esempio n. 16
0
static int GLua_Sys_RadiusDamage(lua_State *L) {
	vec3_t org;
	gentity_t *attacker = 0, *ignore = 0, *missile = 0;
	GLuaVec_t *org2;
	org2 = GLua_CheckVector(L,1);
	ConvertVec(org2, org);
	if (!lua_isnoneornil(L,2)) attacker = GLua_CheckEntity(L,2);
	if (!lua_isnoneornil(L,5)) ignore = GLua_CheckEntity(L,5);
	if (!lua_isnoneornil(L,6)) missile = GLua_CheckEntity(L,6);

	G_RadiusDamage(org, attacker, lua_tonumber(L,3), lua_tonumber(L,4), ignore, missile, lua_tonumber(L,7));
	return 0;
}
static int GLua_Vector_Copy(lua_State *L) {
	GLuaVec_t *self;
	GLuaVec_t *vec2;

	self = GLua_CheckVector(L,1);
	
	vec2 = (GLuaVec_t *)lua_newuserdata(L,12);
	vec2->x = self->x;
	vec2->y = self->y;
	vec2->z = self->z;
	luaL_getmetatable(L,"Vector");
	lua_setmetatable(L,-2);
	return 1;
}
// vector.Normalize(vec1/self)
static int GLua_Vector_Normalize(lua_State *L) {
	GLuaVec_t *self;
	
	double len;

	self = GLua_CheckVector(L,1);

	len = sqrt((self->x * self->x)+(self->y * self->y)+(self->z * self->z));

	self->x = self->x / len;
	self->y = self->y / len;
	self->z = self->z / len; 

	return 0;
}
// vector.GetNormalize(vec1/self)
static int GLua_Vector_GetNormalized(lua_State *L) {
	GLuaVec_t *vec1;
	GLuaVec_t *vec2;
	double len;
	vec1 = GLua_CheckVector(L,1);

	len = sqrt((vec1->x * vec1->x)+(vec1->y * vec1->y)+(vec1->z * vec1->z));

	vec2 = (GLuaVec_t *)lua_newuserdata(L,12);
	vec2->x = vec1->x / len;
	vec2->y = vec1->y / len;
	vec2->z = vec1->z / len; 
	luaL_getmetatable(L,"Vector");
	lua_setmetatable(L,-2);
	return 1;
}
static int GLua_Vector_ToUp(lua_State *L) {
	GLuaVec_t *self;
	vec3_t vec;
	vec3_t vec2;

	self = GLua_CheckVector(L,1);
	vec[0] = self->x;
	vec[1] = self->y;
	vec[2] = self->z;

	AngleVectors(vec, NULL, NULL, vec2);

	self->x = vec2[0];
	self->y = vec2[1];
	self->z = vec2[2];
	return 0;
}
// vector.__div(vec1, num)
static int GLua_Vector_Div(lua_State *L) {
	GLuaVec_t *vec1;
	GLuaVec_t *vec2;
	float factor;

	vec1 = GLua_CheckVector(L,1);
	factor = luaL_checknumber(L,2);

	vec2 = (GLuaVec_t *)lua_newuserdata(L,12);
	vec2->x = vec1->x / factor;
	vec2->y = vec1->y / factor;
	vec2->z = vec1->z / factor;
	luaL_getmetatable(L,"Vector");
	lua_setmetatable(L,-2);

	return 1;
}
static int GLua_Vector_GetAngles(lua_State *L) {
	GLuaVec_t *self;
	GLuaVec_t *vec;
	vec3_t vec2;

	self = GLua_CheckVector(L,1);

	vectoangles((const vec_t *)self, vec2);

	vec = (GLuaVec_t *)lua_newuserdata(L,12);
	vec->x = vec2[0];
	vec->y = vec2[1];
	vec->z = vec2[2];
	luaL_getmetatable(L,"Vector");
	lua_setmetatable(L,-2);

	return 1;
}
static int GLua_Vector_GetUp(lua_State *L) {
	GLuaVec_t *self;
	GLuaVec_t *vec3;
	vec3_t vec;
	vec3_t vec2;

	self = GLua_CheckVector(L,1);
	vec[0] = self->x;
	vec[1] = self->y;
	vec[2] = self->z;

	AngleVectors(vec, NULL, NULL, vec2);

	vec3 = (GLuaVec_t *)lua_newuserdata(L,12);
	vec3->x = vec2[0];
	vec3->y = vec2[1];
	vec3->z = vec2[2];
	luaL_getmetatable(L,"Vector");
	lua_setmetatable(L,-2);
	return 1;
}