RAS_ITexVert::RAS_ITexVert(const MT_Vector3& xyz, const MT_Vector4& tangent, const MT_Vector3& normal) { xyz.getValue(m_localxyz); SetNormal(normal); SetTangent(tangent); }
void LOD_ExternVColorEditor:: SetColor( MT_Vector3 c, const LOD_VertexInd &v ) { c.getValue(m_extern_info->vertex_color_buffer + int(v)*3); }
static bool getNavmeshNormal(dtStatNavMesh* navmesh, const MT_Vector3& pos, MT_Vector3& normal) { static const float polyPickExt[3] = {2, 4, 2}; float spos[3]; pos.getValue(spos); flipAxes(spos); dtStatPolyRef sPolyRef = navmesh->findNearestPoly(spos, polyPickExt); if (sPolyRef == 0) return false; const dtStatPoly* p = navmesh->getPoly(sPolyRef-1); const dtStatPolyDetail* pd = navmesh->getPolyDetail(sPolyRef-1); float distMin = FLT_MAX; int idxMin = -1; for (int i = 0; i < pd->ntris; ++i) { const unsigned char* t = navmesh->getDetailTri(pd->tbase+i); const float* v[3]; for (int j = 0; j < 3; ++j) { if (t[j] < p->nv) v[j] = navmesh->getVertex(p->v[t[j]]); else v[j] = navmesh->getDetailVertex(pd->vbase+(t[j]-p->nv)); } float dist = barDistSqPointToTri(spos, v[0], v[1], v[2]); if (dist<distMin) { distMin = dist; idxMin = i; } } if (idxMin>=0) { const unsigned char* t = navmesh->getDetailTri(pd->tbase+idxMin); const float* v[3]; for (int j = 0; j < 3; ++j) { if (t[j] < p->nv) v[j] = navmesh->getVertex(p->v[t[j]]); else v[j] = navmesh->getDetailVertex(pd->vbase+(t[j]-p->nv)); } MT_Vector3 tri[3]; for (size_t j=0; j<3; j++) tri[j].setValue(v[j][0],v[j][2],v[j][1]); MT_Vector3 a,b; a = tri[1]-tri[0]; b = tri[2]-tri[0]; normal = b.cross(a).safe_normalized(); return true; } return false; }
void KX_KetsjiEngine::DoSound(KX_Scene* scene) { m_logger->StartLog(tc_sound, m_kxsystem->GetTimeInSeconds(), true); KX_Camera* cam = scene->GetActiveCamera(); if (!cam) return; MT_Point3 listenerposition = cam->NodeGetWorldPosition(); MT_Vector3 listenervelocity = cam->GetLinearVelocity(); MT_Matrix3x3 listenerorientation = cam->NodeGetWorldOrientation(); { AUD_3DData data; float f; listenerorientation.getValue3x3(data.orientation); listenerposition.getValue(data.position); listenervelocity.getValue(data.velocity); f = data.position[1]; data.position[1] = data.position[2]; data.position[2] = -f; f = data.velocity[1]; data.velocity[1] = data.velocity[2]; data.velocity[2] = -f; f = data.orientation[1]; data.orientation[1] = data.orientation[2]; data.orientation[2] = -f; f = data.orientation[3]; data.orientation[3] = -data.orientation[6]; data.orientation[6] = f; f = data.orientation[4]; data.orientation[4] = -data.orientation[8]; data.orientation[8] = -f; f = data.orientation[5]; data.orientation[5] = data.orientation[7]; data.orientation[7] = f; AUD_updateListener(&data); } }
bool KX_SoundActuator::Update(double curtime, bool frame) { if (!frame) return true; bool result = false; #ifdef WITH_AUDASPACE // do nothing on negative events, otherwise sounds are played twice! bool bNegativeEvent = IsNegativeEvent(); bool bPositiveEvent = m_posevent; #endif // WITH_AUDASPACE RemoveAllEvents(); #ifdef WITH_AUDASPACE if (!m_sound) return false; // actual audio device playing state bool isplaying = m_handle ? (AUD_Handle_getStatus(m_handle) == AUD_STATUS_PLAYING) : false; if (bNegativeEvent) { // here must be a check if it is still playing if (m_isplaying && isplaying) { switch (m_type) { case KX_SOUNDACT_PLAYSTOP: case KX_SOUNDACT_LOOPSTOP: case KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP: { // stop immediately if (m_handle) { AUD_Handle_stop(m_handle); m_handle = NULL; } break; } case KX_SOUNDACT_PLAYEND: { // do nothing, sound will stop anyway when it's finished break; } case KX_SOUNDACT_LOOPEND: case KX_SOUNDACT_LOOPBIDIRECTIONAL: { // stop the looping so that the sound stops when it finished if (m_handle) AUD_Handle_setLoopCount(m_handle, 0); break; } default: // implement me !! break; } } // remember that we tried to stop the actuator m_isplaying = false; } #if 1 // Warning: when de-activating the actuator, after a single negative event this runs again with... // m_posevent==false && m_posevent==false, in this case IsNegativeEvent() returns false // and assumes this is a positive event. // check that we actually have a positive event so as not to play sounds when being disabled. else if (bPositiveEvent) /* <- added since 2.49 */ #else else // <- works in most cases except a loop-end sound will never stop unless // the negative pulse is done continuesly #endif { if (!m_isplaying) play(); } // verify that the sound is still playing isplaying = m_handle ? (AUD_Handle_getStatus(m_handle) == AUD_STATUS_PLAYING) : false; if (isplaying) { if (m_is3d) { KX_Camera* cam = KX_GetActiveScene()->GetActiveCamera(); if (cam) { KX_GameObject* obj = (KX_GameObject*)this->GetParent(); MT_Vector3 p; MT_Matrix3x3 Mo; float data[4]; Mo = cam->NodeGetWorldOrientation().inverse(); p = (obj->NodeGetWorldPosition() - cam->NodeGetWorldPosition()); p = Mo * p; p.getValue(data); AUD_Handle_setLocation(m_handle, data); p = (obj->GetLinearVelocity() - cam->GetLinearVelocity()); p = Mo * p; p.getValue(data); AUD_Handle_setVelocity(m_handle, data); (Mo * obj->NodeGetWorldOrientation()).getRotation().getValue(data); AUD_Handle_setOrientation(m_handle, data); } } result = true; } else { m_isplaying = false; result = false; } #endif // WITH_AUDASPACE return result; }
void RAS_TexVert::SetTangent(const MT_Vector3& tangent) { tangent.getValue(m_tangent); }
void RAS_TexVert::SetNormal(const MT_Vector3& normal) { normal.getValue(m_normal); }
/* note, this is called as a python 'getset, where the PyAttributeDef is the closure */ PyObject *PyObjectPlus::py_get_attrdef(PyObject *self_py, const PyAttributeDef *attrdef) { PyObjectPlus *ref= (BGE_PROXY_REF(self_py)); char* ptr = (attrdef->m_usePtr) ? (char*)BGE_PROXY_PTR(self_py) : (char*)ref; if (ptr == NULL || (BGE_PROXY_PYREF(self_py) && (ref==NULL || !ref->py_is_valid()))) { if (attrdef == BGE_PY_ATTR_INVALID) Py_RETURN_TRUE; // don't bother running the function PyErr_SetString(PyExc_SystemError, BGE_PROXY_ERROR_MSG); return NULL; } if (attrdef->m_type == KX_PYATTRIBUTE_TYPE_DUMMY) { // fake attribute, ignore return NULL; } if (attrdef->m_type == KX_PYATTRIBUTE_TYPE_FUNCTION) { // the attribute has no field correspondence, handover processing to function. if (attrdef->m_getFunction == NULL) return NULL; return (*attrdef->m_getFunction)(ptr, attrdef); } ptr += attrdef->m_offset; if (attrdef->m_length > 1) { PyObject *resultlist = PyList_New(attrdef->m_length); for (unsigned int i=0; i<attrdef->m_length; i++) { switch (attrdef->m_type) { case KX_PYATTRIBUTE_TYPE_BOOL: { bool *val = reinterpret_cast<bool*>(ptr); ptr += sizeof(bool); PyList_SET_ITEM(resultlist, i, PyBool_FromLong(*val)); break; } case KX_PYATTRIBUTE_TYPE_SHORT: { short int *val = reinterpret_cast<short int*>(ptr); ptr += sizeof(short int); PyList_SET_ITEM(resultlist, i, PyLong_FromLong(*val)); break; } case KX_PYATTRIBUTE_TYPE_ENUM: // enum are like int, just make sure the field size is the same if (sizeof(int) != attrdef->m_size) { Py_DECREF(resultlist); return NULL; } // walkthrough case KX_PYATTRIBUTE_TYPE_INT: { int *val = reinterpret_cast<int*>(ptr); ptr += sizeof(int); PyList_SET_ITEM(resultlist, i, PyLong_FromLong(*val)); break; } case KX_PYATTRIBUTE_TYPE_FLOAT: { float *val = reinterpret_cast<float*>(ptr); ptr += sizeof(float); PyList_SET_ITEM(resultlist, i, PyFloat_FromDouble(*val)); break; } default: // no support for array of complex data Py_DECREF(resultlist); return NULL; } } return resultlist; } else { switch (attrdef->m_type) { case KX_PYATTRIBUTE_TYPE_FLAG: { bool bval; switch (attrdef->m_size) { case 1: { unsigned char *val = reinterpret_cast<unsigned char*>(ptr); bval = (*val & attrdef->m_imin); break; } case 2: { unsigned short *val = reinterpret_cast<unsigned short*>(ptr); bval = (*val & attrdef->m_imin); break; } case 4: { unsigned int *val = reinterpret_cast<unsigned int*>(ptr); bval = (*val & attrdef->m_imin); break; } default: return NULL; } if (attrdef->m_imax) bval = !bval; return PyBool_FromLong(bval); } case KX_PYATTRIBUTE_TYPE_BOOL: { bool *val = reinterpret_cast<bool*>(ptr); return PyBool_FromLong(*val); } case KX_PYATTRIBUTE_TYPE_SHORT: { short int *val = reinterpret_cast<short int*>(ptr); return PyLong_FromLong(*val); } case KX_PYATTRIBUTE_TYPE_ENUM: // enum are like int, just make sure the field size is the same if (sizeof(int) != attrdef->m_size) { return NULL; } // walkthrough case KX_PYATTRIBUTE_TYPE_INT: { int *val = reinterpret_cast<int*>(ptr); return PyLong_FromLong(*val); } case KX_PYATTRIBUTE_TYPE_FLOAT: { float *val = reinterpret_cast<float*>(ptr); if (attrdef->m_imin == 0) { if (attrdef->m_imax == 0) { return PyFloat_FromDouble(*val); } else { // vector, verify size if (attrdef->m_size != attrdef->m_imax*sizeof(float)) { return NULL; } #ifdef USE_MATHUTILS return Vector_CreatePyObject(val, attrdef->m_imax, NULL); #else PyObject *resultlist = PyList_New(attrdef->m_imax); for (unsigned int i=0; i<attrdef->m_imax; i++) { PyList_SET_ITEM(resultlist, i, PyFloat_FromDouble(val[i])); } return resultlist; #endif } } else { // matrix case if (attrdef->m_size != attrdef->m_imax*attrdef->m_imin*sizeof(float)) { return NULL; } #ifdef USE_MATHUTILS return Matrix_CreatePyObject_wrap(val, attrdef->m_imin, attrdef->m_imax, NULL); #else PyObject *collist = PyList_New(attrdef->m_imin); for (unsigned int i=0; i<attrdef->m_imin; i++) { PyObject *col = PyList_New(attrdef->m_imax); for (unsigned int j=0; j<attrdef->m_imax; j++) { PyList_SET_ITEM(col, j, PyFloat_FromDouble(val[j])); } PyList_SET_ITEM(collist, i, col); val += attrdef->m_imax; } return collist; #endif } } case KX_PYATTRIBUTE_TYPE_VECTOR: { MT_Vector3 *val = reinterpret_cast<MT_Vector3*>(ptr); #ifdef USE_MATHUTILS float fval[3]; val->getValue(fval); return Vector_CreatePyObject(fval, 3, NULL); #else PyObject *resultlist = PyList_New(3); for (unsigned int i=0; i<3; i++) { PyList_SET_ITEM(resultlist, i, PyFloat_FromDouble((*val)[i])); } return resultlist; #endif } case KX_PYATTRIBUTE_TYPE_STRING: { STR_String *val = reinterpret_cast<STR_String*>(ptr); return PyUnicode_From_STR_String(*val); } case KX_PYATTRIBUTE_TYPE_CHAR: { return PyUnicode_FromString(ptr); } default: return NULL; } } }