PyObject *KX_VertexProxy::pyattr_get_uvs(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v); PyObject* uvlist = PyList_New(RAS_TexVert::MAX_UNIT); for (int i=0; i<RAS_TexVert::MAX_UNIT; ++i) { PyList_SET_ITEM(uvlist, i, PyObjectFrom(MT_Point2(self->m_vertex->getUV(i)))); } return uvlist; }
PyObject* KX_VertexProxy::py_getattro(PyObject *attr) { char *attr_str= _PyUnicode_AsString(attr); if (attr_str[1]=='\0') { // Group single letters // pos if (attr_str[0]=='x') return PyFloat_FromDouble(m_vertex->getXYZ()[0]); if (attr_str[0]=='y') return PyFloat_FromDouble(m_vertex->getXYZ()[1]); if (attr_str[0]=='z') return PyFloat_FromDouble(m_vertex->getXYZ()[2]); // Col if (attr_str[0]=='r') return PyFloat_FromDouble(m_vertex->getRGBA()[0]/255.0); if (attr_str[0]=='g') return PyFloat_FromDouble(m_vertex->getRGBA()[1]/255.0); if (attr_str[0]=='b') return PyFloat_FromDouble(m_vertex->getRGBA()[2]/255.0); if (attr_str[0]=='a') return PyFloat_FromDouble(m_vertex->getRGBA()[3]/255.0); // UV if (attr_str[0]=='u') return PyFloat_FromDouble(m_vertex->getUV1()[0]); if (attr_str[0]=='v') return PyFloat_FromDouble(m_vertex->getUV1()[1]); } if (!strcmp(attr_str, "XYZ")) return PyObjectFrom(MT_Vector3(m_vertex->getXYZ())); if (!strcmp(attr_str, "UV")) return PyObjectFrom(MT_Point2(m_vertex->getUV1())); if (!strcmp(attr_str, "color") || !strcmp(attr_str, "colour")) { const unsigned char *colp = m_vertex->getRGBA(); MT_Vector4 color(colp[0], colp[1], colp[2], colp[3]); color /= 255.0; return PyObjectFrom(color); } if (!strcmp(attr_str, "normal")) { return PyObjectFrom(MT_Vector3(m_vertex->getNormal())); } py_getattro_up(CValue); }
void KX_Camera::ExtractFrustumSphere() { if (m_set_frustum_center) return; // compute sphere for the general case and not only symmetric frustum: // the mirror code in ImageRender can use very asymmetric frustum. // We will put the sphere center on the line that goes from origin to the center of the far clipping plane // This is the optimal position if the frustum is symmetric or very asymmetric and probably close // to optimal for the general case. The sphere center position is computed so that the distance to // the near and far extreme frustum points are equal. // get the transformation matrix from device coordinate to camera coordinate MT_Matrix4x4 clip_camcs_matrix = m_projection_matrix; clip_camcs_matrix.invert(); if (m_projection_matrix[3][3] == MT_Scalar(0.0)) { // frustrum projection // detect which of the corner of the far clipping plane is the farthest to the origin MT_Vector4 nfar; // far point in device normalized coordinate MT_Point3 farpoint; // most extreme far point in camera coordinate MT_Point3 nearpoint;// most extreme near point in camera coordinate MT_Point3 farcenter(0.0, 0.0, 0.0);// center of far cliping plane in camera coordinate MT_Scalar F=-1.0, N; // square distance of far and near point to origin MT_Scalar f, n; // distance of far and near point to z axis. f is always > 0 but n can be < 0 MT_Scalar e, s; // far and near clipping distance (<0) MT_Scalar c; // slope of center line = distance of far clipping center to z axis / far clipping distance MT_Scalar z; // projection of sphere center on z axis (<0) // tmp value MT_Vector4 npoint(1.0, 1.0, 1.0, 1.0); MT_Vector4 hpoint; MT_Point3 point; MT_Scalar len; for (int i=0; i<4; i++) { hpoint = clip_camcs_matrix*npoint; point.setValue(hpoint[0]/hpoint[3], hpoint[1]/hpoint[3], hpoint[2]/hpoint[3]); len = point.dot(point); if (len > F) { nfar = npoint; farpoint = point; F = len; } // rotate by 90 degree along the z axis to walk through the 4 extreme points of the far clipping plane len = npoint[0]; npoint[0] = -npoint[1]; npoint[1] = len; farcenter += point; } // the far center is the average of the far clipping points farcenter *= 0.25; // the extreme near point is the opposite point on the near clipping plane nfar.setValue(-nfar[0], -nfar[1], -1.0, 1.0); nfar = clip_camcs_matrix*nfar; nearpoint.setValue(nfar[0]/nfar[3], nfar[1]/nfar[3], nfar[2]/nfar[3]); // this is a frustrum projection N = nearpoint.dot(nearpoint); e = farpoint[2]; s = nearpoint[2]; // projection on XY plane for distance to axis computation MT_Point2 farxy(farpoint[0], farpoint[1]); // f is forced positive by construction f = farxy.length(); // get corresponding point on the near plane farxy *= s/e; // this formula preserve the sign of n n = f*s/e - MT_Point2(nearpoint[0]-farxy[0], nearpoint[1]-farxy[1]).length(); c = MT_Point2(farcenter[0], farcenter[1]).length()/e; // the big formula, it simplifies to (F-N)/(2(e-s)) for the symmetric case z = (F-N)/(2.0*(e-s+c*(f-n))); m_frustum_center = MT_Point3(farcenter[0]*z/e, farcenter[1]*z/e, z); m_frustum_radius = m_frustum_center.distance(farpoint); } else { // orthographic projection // The most extreme points on the near and far plane. (normalized device coords) MT_Vector4 hnear(1.0, 1.0, 1.0, 1.0), hfar(-1.0, -1.0, -1.0, 1.0); // Transform to hom camera local space hnear = clip_camcs_matrix*hnear; hfar = clip_camcs_matrix*hfar; // Tranform to 3d camera local space. MT_Point3 nearpoint(hnear[0]/hnear[3], hnear[1]/hnear[3], hnear[2]/hnear[3]); MT_Point3 farpoint(hfar[0]/hfar[3], hfar[1]/hfar[3], hfar[2]/hfar[3]); // just use mediant point m_frustum_center = (farpoint + nearpoint)*0.5; m_frustum_radius = m_frustum_center.distance(farpoint); } // Transform to world space. m_frustum_center = GetCameraToWorld()(m_frustum_center); m_frustum_radius /= fabs(NodeGetWorldScaling()[NodeGetWorldScaling().closestAxis()]); m_set_frustum_center = true; }
PyObject *KX_VertexProxy::pyattr_get_UV(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { KX_VertexProxy* self = static_cast<KX_VertexProxy*>(self_v); return PyObjectFrom(MT_Point2(self->m_vertex->getUV(0))); }
void BL_Material::Initialize() { rgb[0] = 0; rgb[1] = 0; rgb[2] = 0; rgb[3] = 0; IdMode = 0; ras_mode = 0; glslmat = 0; tile = 0; matname = "NoMaterial"; matcolor[0] = 0.5f; matcolor[1] = 0.5f; matcolor[2] = 0.5f; matcolor[3] = 0.5f; speccolor[0] = 1.f; speccolor[1] = 1.f; speccolor[2] = 1.f; alphablend = 0; hard = 50.f; spec_f = 0.5f; alpha = 1.f; emit = 0.f; material = 0; tface = 0; materialindex = 0; amb=0.5f; num_enabled = 0; num_users = 1; share = false; int i; for(i=0; i<4; i++) { uv[i] = MT_Point2(0.f,1.f); uv2[i] = MT_Point2(0.f, 1.f); } for(i=0; i<MAXTEX; i++) // :( { mapping[i].mapping = 0; mapping[i].offsets[0] = 0.f; mapping[i].offsets[1] = 0.f; mapping[i].offsets[2] = 0.f; mapping[i].scale[0] = 1.f; mapping[i].scale[1] = 1.f; mapping[i].scale[2] = 1.f; mapping[i].projplane[0] = PROJX; mapping[i].projplane[1] = PROJY; mapping[i].projplane[2] = PROJZ; mapping[i].objconame = ""; mtexname[i] = "NULL"; imageId[i]="NULL"; flag[i] = 0; texname[i] = "NULL"; tilexrep[i] = 1; tileyrep[i] = 1; color_blend[i] = 1.f; blend_mode[i] = 0; img[i] = 0; cubemap[i] = 0; } }