Esempio n. 1
0
//-------------------------------------------------------------------------------------
PyObject* ScriptVector2::py_subtract(PyObject *a, PyObject *b)
{
	if(!check(a) || !check(b))
	{
		PyErr_Clear();
		Py_INCREF(Py_NotImplemented);
		return Py_NotImplemented;
	}
	
	Vector2 av;
	Vector2 bv;

	convertPyObjectToVector2(av, a);
	convertPyObjectToVector2(bv, b);
	return new ScriptVector2(av - bv);
}
Esempio n. 2
0
//-------------------------------------------------------------------------------------
PyObject* ScriptVector2::__py_pySet(PyObject* self, PyObject* args)
{
	ScriptVector2* sv = static_cast<ScriptVector2*>(self);
	bool good = false;
	Vector2 v;

	// 如果参数只有1个元素
	int tupleSize = (int)PyTuple_Size(args);
	if(tupleSize == 1)
	{
		PyObject* pyItem = PyTuple_GetItem(args, 0);

		if(ScriptVector2::check(pyItem, false))
		{
			convertPyObjectToVector2(v, pyItem);
			good = true;
		}
		else
		{
			float f = float(PyFloat_AsDouble(pyItem));
			for (int i=0; i < VECTOR_SIZE; ++i)
			{
				v[i] = f;
			}
			good = true;
		}
	}
	else if(tupleSize >= VECTOR_SIZE)
	{
		convertPyObjectToVector2(v, args);
		good = true;
	}

	if(!good)
	{
		PyErr_Format(PyExc_TypeError, "Vector.set must be set to a tuple of %d floats, or one float", VECTOR_SIZE);
		PyErr_PrintEx(0);
		return NULL;
	}

	sv->setVector(v);
	S_Return;
}
Esempio n. 3
0
//-------------------------------------------------------------------------------------
PyObject* ScriptVector2::py_divide(PyObject *a, PyObject *b)
{
	if(!check(a))
	{
		PyErr_Clear();
		Py_INCREF(Py_NotImplemented);
		return Py_NotImplemented;
	}

	Vector2 av;
	convertPyObjectToVector2(av, a);
	float f = float(PyFloat_AsDouble(b));
	return new ScriptVector2(av / f);
}
Esempio n. 4
0
//-------------------------------------------------------------------------------------
PyObject* ScriptVector2::py_inplace_subtract(PyObject *self, PyObject *b)
{
	if(!check(b))
	{
		PyErr_Clear();
		Py_INCREF(Py_NotImplemented);
		return Py_NotImplemented;
	}
	
	Vector2 bv;
	convertPyObjectToVector2(bv, b);
	ScriptVector2* sv = static_cast<ScriptVector2*>(self);
	Vector2& v = sv->getVector();
	v -= bv;
	Py_INCREF(sv);
	return sv;
}
Esempio n. 5
0
//-------------------------------------------------------------------------------------
PyObject* ScriptVector2::__py_pyDistSqrTo(PyObject* self, PyObject* args)
{
	if (PyTuple_Size(args) != 1)
	{
		PyErr_SetString(PyExc_TypeError, "args > 1 is error!\n");
		PyErr_PrintEx(0);
		S_Return;
	}
	
	ScriptVector2* sv = static_cast<ScriptVector2*>(self);
	Vector2& v = sv->getVector();
	
	Vector2 v1;
	convertPyObjectToVector2(v1, PyTuple_GET_ITEM(args, 0));
	
	Vector2 rv = (v - v1);
	return PyFloat_FromDouble(KBEVec2LengthSq(&rv)); //计算点乘并返回
}