1 Star 0 Fork 121

blog/kbengine

forked from likecg/kbengine 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
vector4.hpp 4.08 KB
一键复制 编辑 原始数据 按行查看 历史
liquidx 提交于 2012-10-29 09:39 +08:00 . 规范化部分代码.
/*
This source file is part of KBEngine
For the latest info, see http://www.kbengine.org/
Copyright (c) 2008-2012 KBEngine.
KBEngine is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
KBEngine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with KBEngine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _SCRIPT_VECTOR4_H
#define _SCRIPT_VECTOR4_H
#include "cstdkbe/cstdkbe.hpp"
#include "math/math.hpp"
#include "scriptobject.hpp"
#include "pickler.hpp"
namespace KBEngine{ namespace script{
class ScriptVector4 : public ScriptObject
{
/** 子类化 将一些py操作填充进派生类 */
INSTANCE_SCRIPT_HREADER(ScriptVector4, ScriptObject)
public:
static PySequenceMethods seqMethods;
static PyNumberMethods numberMethods;
ScriptVector4(Vector4 v);
ScriptVector4(Vector4* v);
ScriptVector4(float x, float y, float z, float w);
virtual ~ScriptVector4();
/**
获得对象的描述
*/
PyObject* tp_repr();
PyObject* tp_str();
/**
脚本模块对象从python中创建
*/
static PyObject* tp_new(PyTypeObject* type, PyObject* args, PyObject* kwds);
/**
seq相关操作
*/
static Py_ssize_t seq_length(PyObject* self);
static PyObject* seq_item(PyObject* self, Py_ssize_t index);
static PyObject* seq_slice(PyObject* self, Py_ssize_t startIndex, Py_ssize_t endIndex);
static int seq_ass_item(PyObject* self, Py_ssize_t index, PyObject* value);
/**
加减乘除相关操作
*/
static PyObject* py_add(PyObject *a, PyObject *b);
static PyObject* py_subtract(PyObject *a, PyObject *b);
static PyObject* py_multiply(PyObject *a, PyObject *b);
static PyObject* py_divide(PyObject *a, PyObject *b);
static PyObject* py_negative(PyObject *self);
static PyObject* py_positive(PyObject *self);
static int py_nonzero(PyObject *self);
static PyObject* py_inplace_add(PyObject *self, PyObject *b);
static PyObject* py_inplace_subtract(PyObject *self, PyObject *b);
static PyObject* py_inplace_multiply(PyObject *self, PyObject *b);
static PyObject* py_inplace_divide(PyObject *self, PyObject *b);
/**
暴漏一些方法
*/
static PyObject* __py_pyDistTo(PyObject* self, PyObject* args);
static PyObject* __py_pyDistSqrTo(PyObject* self, PyObject* args);
static PyObject* __py_pyScale(PyObject* self, PyObject* args);
static PyObject* __py_pyDot(PyObject* self, PyObject* args);
static PyObject* __py_pyNormalise(PyObject* self, PyObject* args);
static PyObject* __py_pyTuple(PyObject* self, PyObject* args);
static PyObject* __py_pyList(PyObject* self, PyObject* args);
static PyObject* __py_pySet(PyObject* self, PyObject* args);
DECLARE_PY_GET_MOTHOD(pyGetVectorLength);
DECLARE_PY_GET_MOTHOD(pyGetVectorLengthSquared);
DECLARE_PY_GETSET_MOTHOD(pyGetX, pySetX);
DECLARE_PY_GETSET_MOTHOD(pyGetY, pySetY);
DECLARE_PY_GETSET_MOTHOD(pyGetZ, pySetZ);
DECLARE_PY_GETSET_MOTHOD(pyGetW, pySetW);
/**
支持pickler 方法
*/
static PyObject* __reduce_ex__(PyObject* self, PyObject* protocol);
/**
unpickle方法
*/
static PyObject* __unpickle__(PyObject* self, PyObject* args);
/**
脚本被安装时被调用
*/
static void onInstallScript(PyObject* mod);
int length(void){ return VECTOR_SIZE; }
Vector4& getVector(void){ return *val_; }
void setVector(const Vector4& v){ *val_ = v; }
/**
检查某个python对象是否可以转换为本类型
*/
static bool check(PyObject* value, bool isPrintErr = true);
/**
将某个经过check检查过的python对象转换为vector4
*/
static void convertPyObjectToVector4(Vector4& v, PyObject* obj);
private:
Vector4* val_;
bool isCopy_;
bool isReadOnly_;
static const int VECTOR_SIZE;
} ;
}
}
#endif
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/blog/kbengine.git
git@gitee.com:blog/kbengine.git
blog
kbengine
kbengine
0.1.1

搜索帮助