Exemplo n.º 1
0
void IK_QSegment::UpdateTransform(const MT_Transform& global)
{
	// compute the global transform at the end of the segment
	m_global_start = global.getOrigin() + global.getBasis()*m_start;

	m_global_transform.setOrigin(m_global_start);
	m_global_transform.setBasis(global.getBasis() * m_rest_basis * m_basis);
	m_global_transform.translate(m_translation);

	// update child transforms
	for (IK_QSegment *seg = m_child; seg; seg = seg->m_sibling)
		seg->UpdateTransform(m_global_transform);
}
Exemplo n.º 2
0
void RAS_BucketManager::OrderBuckets(const MT_Transform& cameratrans, BucketList& buckets, vector<sortedmeshslot>& slots, bool alpha)
{
	BucketList::iterator bit;
	list<RAS_MeshSlot>::iterator mit;
	size_t size = 0, i = 0;

	/* Camera's near plane equation: pnorm.dot(point) + pval,
	 * but we leave out pval since it's constant anyway */
	const MT_Vector3 pnorm(cameratrans.getBasis()[2]);

	for (bit = buckets.begin(); bit != buckets.end(); ++bit)
	{
		SG_DList::iterator<RAS_MeshSlot> mit((*bit)->GetActiveMeshSlots());
		for(mit.begin(); !mit.end(); ++mit)
			size++;
	}

	slots.resize(size);

	for (bit = buckets.begin(); bit != buckets.end(); ++bit)
	{
		RAS_MaterialBucket* bucket = *bit;
		RAS_MeshSlot* ms;
		// remove the mesh slot form the list, it culls them automatically for next frame
		while((ms = bucket->GetNextActiveMeshSlot())) {
			slots[i++].set(ms, bucket, pnorm);
		}
	}
		
	if(alpha)
		sort(slots.begin(), slots.end(), backtofront());
	else
		sort(slots.begin(), slots.end(), fronttoback());
}
Exemplo n.º 3
0
void KX_LightObject::BindShadowBuffer(RAS_IRasterizer *ras, KX_Camera *cam, MT_Transform& camtrans)
{
	GPULamp *lamp;
	float viewmat[4][4], winmat[4][4];
	int winsize;

	/* bind framebuffer */
	lamp = GetGPULamp();
	GPU_lamp_shadow_buffer_bind(lamp, viewmat, &winsize, winmat);

	/* setup camera transformation */
	MT_Matrix4x4 modelviewmat((float*)viewmat);
	MT_Matrix4x4 projectionmat((float*)winmat);

	MT_Transform trans = MT_Transform((float*)viewmat);
	camtrans.invert(trans);

	cam->SetModelviewMatrix(modelviewmat);
	cam->SetProjectionMatrix(projectionmat);
	
	cam->NodeSetLocalPosition(camtrans.getOrigin());
	cam->NodeSetLocalOrientation(camtrans.getBasis());
	cam->NodeUpdateGS(0);

	/* setup rasterizer transformations */
	/* SetViewMatrix may use stereomode which we temporarily disable here */
	RAS_IRasterizer::StereoMode stereomode = ras->GetStereoMode();
	ras->SetStereoMode(RAS_IRasterizer::RAS_STEREO_NOSTEREO);
	ras->SetProjectionMatrix(projectionmat);
	ras->SetViewMatrix(modelviewmat, cam->NodeGetWorldOrientation(), cam->NodeGetWorldPosition(), cam->GetCameraData()->m_perspective);
	ras->SetStereoMode(stereomode);
}
Exemplo n.º 4
0
MT_BBox DT_Complex::bbox(const MT_Transform& t, MT_Scalar margin) const 
{
    MT_Matrix3x3 abs_b = t.getBasis().absolute();  
    MT_Point3 center = t(m_cbox.getCenter());
    MT_Vector3 extent(margin + abs_b[0].dot(m_cbox.getExtent()),
                      margin + abs_b[1].dot(m_cbox.getExtent()),
                      margin + abs_b[2].dot(m_cbox.getExtent()));
    
    return MT_BBox(center - extent, center + extent);
}
Exemplo n.º 5
0
void KX_KetsjiEngine::PostProcessScene(KX_Scene* scene)
{
	bool override_camera = (m_overrideCam && (scene->GetName() == m_overrideSceneName));

	SG_SetActiveStage(SG_STAGE_SCENE);

	// if there is no activecamera, or the camera is being
	// overridden we need to construct a temporarily camera
	if (!scene->GetActiveCamera() || override_camera)
	{
		KX_Camera* activecam = NULL;

		RAS_CameraData camdata = RAS_CameraData();
		if (override_camera)
		{
			camdata.m_lens = m_overrideCamLens;
			camdata.m_clipstart = m_overrideCamNear;
			camdata.m_clipend = m_overrideCamFar;
			
			camdata.m_perspective= !m_overrideCamUseOrtho;
		}
		activecam = new KX_Camera(scene,KX_Scene::m_callbacks,camdata);
		activecam->SetName("__default__cam__");
	
			// set transformation
		if (override_camera) {
			const MT_CmMatrix4x4& cammatdata = m_overrideCamViewMat;
			MT_Transform trans = MT_Transform(cammatdata.getPointer());
			MT_Transform camtrans;
			camtrans.invert(trans);
			
			activecam->NodeSetLocalPosition(camtrans.getOrigin());
			activecam->NodeSetLocalOrientation(camtrans.getBasis());
			activecam->NodeUpdateGS(0);
		} else {
			activecam->NodeSetLocalPosition(MT_Point3(0.0, 0.0, 0.0));
			activecam->NodeSetLocalOrientation(MT_Vector3(0.0, 0.0, 0.0));
			activecam->NodeUpdateGS(0);
		}

		scene->AddCamera(activecam);
		scene->SetActiveCamera(activecam);
		scene->GetObjectList()->Add(activecam->AddRef());
		scene->GetRootParentList()->Add(activecam->AddRef());
		//done with activecam
		activecam->Release();
	}
	
	scene->UpdateParents(0.0);
}
void RAS_MeshObject::SortPolygons(RAS_MeshSlot& ms, const MT_Transform &transform)
{
	// Limitations: sorting is quite simple, and handles many
	// cases wrong, partially due to polygons being sorted per
	// bucket.
	// 
	// a) mixed triangles/quads are sorted wrong
	// b) mixed materials are sorted wrong
	// c) more than 65k faces are sorted wrong
	// d) intersecting objects are sorted wrong
	// e) intersecting polygons are sorted wrong
	//
	// a) can be solved by making all faces either triangles or quads
	// if they need to be z-sorted. c) could be solved by allowing
	// larger buckets, b) and d) cannot be solved easily if we want
	// to avoid excessive state changes while drawing. e) would
	// require splitting polygons.

	RAS_MeshSlot::iterator it;
	size_t j;

	for (ms.begin(it); !ms.end(it); ms.next(it)) {
		unsigned int nvert = (int)it.array->m_type;
		unsigned int totpoly = it.totindex/nvert;

		if (totpoly <= 1)
			continue;
		if (it.array->m_type == RAS_DisplayArray::LINE)
			continue;

		// Extract camera Z plane...
		const MT_Vector3 pnorm(transform.getBasis()[2]);
		// unneeded: const MT_Scalar pval = transform.getOrigin()[2];

		vector<polygonSlot> poly_slots(totpoly);

		/* get indices and z into temporary array */
		for (j=0; j<totpoly; j++)
			poly_slots[j].get(it.vertex, it.index, j*nvert, nvert, pnorm);

		/* sort (stable_sort might be better, if flickering happens?) */
		std::sort(poly_slots.begin(), poly_slots.end(), backtofront());

		/* get indices from temporary array again */
		for (j=0; j<totpoly; j++)
			poly_slots[j].set(it.index, j*nvert, nvert);
	}
}
Exemplo n.º 7
0
void RAS_BucketManager::OrderBuckets(const MT_Transform& cameratrans, RAS_BucketManager::BucketType bucketType,
                                     std::vector<sortedmeshslot>& slots, bool alpha, RAS_IRasterizer *rasty)
{
	const unsigned int size = GetNumActiveMeshSlots(bucketType);
	// Discard if there's no mesh slots.
	if (size == 0) {
		return;
	}

	size_t i = 0;

	/* Camera's near plane equation: pnorm.dot(point) + pval,
	 * but we leave out pval since it's constant anyway */
	const MT_Vector3 pnorm(cameratrans.getBasis()[2]);

	slots.resize(size);

	BucketList& buckets = m_buckets[bucketType];

	for (BucketList::iterator bit = buckets.begin(); bit != buckets.end(); ++bit)
	{
		RAS_MaterialBucket *bucket = *bit;
		RAS_DisplayArrayBucketList& displayArrayBucketList = (*bit)->GetDisplayArrayBucketList();
		for (RAS_DisplayArrayBucketList::iterator dbit = displayArrayBucketList.begin(), dbend = displayArrayBucketList.end();
		     dbit != dbend; ++dbit)
		{
			RAS_DisplayArrayBucket *displayArrayBucket = *dbit;
			RAS_MeshSlotList& activeMeshSlots = displayArrayBucket->GetActiveMeshSlots();

			// Update deformer and render settings.
			displayArrayBucket->UpdateActiveMeshSlots(rasty);

			for (RAS_MeshSlotList::iterator it = activeMeshSlots.begin(), end = activeMeshSlots.end(); it != end; ++it) {
				slots[i++].set(*it, bucket, pnorm);
			}
			displayArrayBucket->RemoveActiveMeshSlots();
		}
	}

	if (alpha)
		sort(slots.begin(), slots.end(), backtofront());
	else
		sort(slots.begin(), slots.end(), fronttoback());
}
Exemplo n.º 8
0
void RAS_OpenGLLight::BindShadowBuffer(RAS_ICanvas *canvas, KX_Camera *cam, MT_Transform& camtrans)
{
	GPULamp *lamp;
	float viewmat[4][4], winmat[4][4];
	int winsize;

	/* bind framebuffer */
	lamp = GetGPULamp();
	GPU_lamp_shadow_buffer_bind(lamp, viewmat, &winsize, winmat);

	if (GPU_lamp_shadow_buffer_type(lamp) == LA_SHADMAP_VARIANCE) {
		m_rasterizer->SetShadowMode(RAS_IRasterizer::RAS_SHADOW_VARIANCE);
	}
	else {
		m_rasterizer->SetShadowMode(RAS_IRasterizer::RAS_SHADOW_SIMPLE);
	}

	/* GPU_lamp_shadow_buffer_bind() changes the viewport, so update the canvas */
	canvas->UpdateViewPort(0, 0, winsize, winsize);

	/* setup camera transformation */
	MT_Matrix4x4 modelviewmat((float *)viewmat);
	MT_Matrix4x4 projectionmat((float *)winmat);

	MT_Transform trans = MT_Transform((float *)viewmat);
	camtrans.invert(trans);

	cam->SetModelviewMatrix(modelviewmat);
	cam->SetProjectionMatrix(projectionmat);

	cam->NodeSetLocalPosition(camtrans.getOrigin());
	cam->NodeSetLocalOrientation(camtrans.getBasis());
	cam->NodeUpdateGS(0);

	/* setup rasterizer transformations */
	/* SetViewMatrix may use stereomode which we temporarily disable here */
	RAS_IRasterizer::StereoMode stereomode = m_rasterizer->GetStereoMode();
	m_rasterizer->SetStereoMode(RAS_IRasterizer::RAS_STEREO_NOSTEREO);
	m_rasterizer->SetProjectionMatrix(projectionmat);
	m_rasterizer->SetViewMatrix(modelviewmat, cam->NodeGetWorldOrientation(), cam->NodeGetWorldPosition(), cam->NodeGetLocalScaling(), cam->GetCameraData()->m_perspective);
	m_rasterizer->SetStereoMode(stereomode);
}
Exemplo n.º 9
0
/**
 *	Transforms the collision object. A cone is not correctly centered
 *	for usage.  */
void KX_RadarSensor::SynchronizeTransform()
{
    // Getting the parent location was commented out. Why?
    MT_Transform trans;
    trans.setOrigin(((KX_GameObject*)GetParent())->NodeGetWorldPosition());
    trans.setBasis(((KX_GameObject*)GetParent())->NodeGetWorldOrientation());
    // What is the default orientation? pointing in the -y direction?
    // is the geometry correctly converted?

    // a collision cone is oriented
    // center the cone correctly
    // depends on the radar 'axis'
    switch (m_axis)
    {
    case SENS_RADAR_X_AXIS: // +X Axis
    {
        MT_Quaternion rotquatje(MT_Vector3(0,0,1),MT_radians(90));
        trans.rotate(rotquatje);
        trans.translate(MT_Vector3 (0, -m_coneheight/2.0 ,0));
        break;
    };
    case SENS_RADAR_Y_AXIS: // +Y Axis
    {
        MT_Quaternion rotquatje(MT_Vector3(1,0,0),MT_radians(-180));
        trans.rotate(rotquatje);
        trans.translate(MT_Vector3 (0, -m_coneheight/2.0 ,0));
        break;
    };
    case SENS_RADAR_Z_AXIS: // +Z Axis
    {
        MT_Quaternion rotquatje(MT_Vector3(1,0,0),MT_radians(-90));
        trans.rotate(rotquatje);
        trans.translate(MT_Vector3 (0, -m_coneheight/2.0 ,0));
        break;
    };
    case SENS_RADAR_NEG_X_AXIS: // -X Axis
    {
        MT_Quaternion rotquatje(MT_Vector3(0,0,1),MT_radians(-90));
        trans.rotate(rotquatje);
        trans.translate(MT_Vector3 (0, -m_coneheight/2.0 ,0));
        break;
    };
    case SENS_RADAR_NEG_Y_AXIS: // -Y Axis
    {
        //MT_Quaternion rotquatje(MT_Vector3(1,0,0),MT_radians(-180));
        //trans.rotate(rotquatje);
        trans.translate(MT_Vector3 (0, -m_coneheight/2.0 ,0));
        break;
    };
    case SENS_RADAR_NEG_Z_AXIS: // -Z Axis
    {
        MT_Quaternion rotquatje(MT_Vector3(1,0,0),MT_radians(90));
        trans.rotate(rotquatje);
        trans.translate(MT_Vector3 (0, -m_coneheight/2.0 ,0));
        break;
    };
    default:
    {
    }
    }

    //Using a temp variable to translate MT_Point3 to float[3].
    //float[3] works better for the Python interface.
    MT_Point3 temp = trans.getOrigin();
    m_cone_origin[0] = temp[0];
    m_cone_origin[1] = temp[1];
    m_cone_origin[2] = temp[2];

    temp = trans(MT_Point3(0, -m_coneheight/2.0 ,0));
    m_cone_target[0] = temp[0];
    m_cone_target[1] = temp[1];
    m_cone_target[2] = temp[2];


    if (m_physCtrl)
    {
        PHY_IMotionState* motionState = m_physCtrl->GetMotionState();
        const MT_Point3& pos = trans.getOrigin();
        float ori[12];
        trans.getBasis().getValue(ori);
        motionState->setWorldPosition(pos[0], pos[1], pos[2]);
        motionState->setWorldOrientation(ori);
        m_physCtrl->WriteMotionStateToDynamics(true);
    }

}