Jump to content

[SOLVED] getIntersection


photo

Recommended Posts

Posted

on ObjectMesh & ObjectDynamic objects getIntersection does not work, mask and setintersection flags = 1

Posted

ObjectDynamic doesn't have intersection code.

You have to provide invisible intersection mesh inside ObjectMesh.

Posted

i only want to create custom mesh with Unigine-pick system and modify it anytime

 

ObjectMesh o = add_editor(new ObjectMesh(0));
 
o.addEmptySurface("surf0", 4, 6);
 
o.setVertex(0,vec3(-1.5f,8,0),0);
o.setVertex(1,vec3(-1.5f,1.5f,0),0);
o.setVertex(2,vec3(-11,8,0),0);
o.setVertex(3,vec3(-11,1.5f,0),0);
 
o.setTexCoord(0,vec4(10,-6,0,0),0);
o.setTexCoord(1,vec4(10,1,0,0),0);
o.setTexCoord(2,vec4(0,-6,0,0),0);
o.setTexCoord(3,vec4(0,1,0,0),0);
 
o.setTangent(0,vec4(1,0,0.000015f,-1),0);
o.setTangent(1,vec4(1,0,0.000015f,-1),0);
o.setTangent(2,vec4(1,0,0.000015f,-1),0);
o.setTangent(3,vec4(1,0,0.000015f,-1),0);
 
vec3 norm = vec3(-0.000015f,-0.000015f,1);
o.setNormal(0,norm,0);
o.setNormal(1,norm,0);
o.setNormal(2,norm,0);
o.setNormal(3,norm,0);
 
o.setIndex(0,2,0);
o.setIndex(1,3,0);
o.setIndex(2,0,0);
 
o.setIndex(3,1,0);
o.setIndex(4,0,0);
o.setIndex(5,3,0);
 
o.setMaterial("mesh_base","*");
o.setProperty("surface_base","*");
 
o.setEnabled(1,0);
o.setIntersectionMask(1,0);
o.setIntersection(1,0);
 
 
 
and then i use:
Vec3 p0,p1;
Unigine::getPlayerMouseDirection(p0,p1);
 
int ret[0];
Object o = engine.world.getIntersection(p0,p1,1,ret);
 
but unigine does not detect my custom mesh
Posted

i did it :D "unknown ObjectMesh class member updateSurfaces();"

Posted

"ObjectMesh::updateSurfaces" method should exist in the latest SDK update.

Posted

how set bounds of ObjectMesh? it is not itersecting by getIntersection,

how get intersection by Unigine on Custom ObjectMesh? or some other mesh, i need construct one mesh and get intersection by Unigine getIntersection, or i have to write own intersector for custom meshes?

Posted

ok, i know what is my problem: need to update bounds of custom mesh, but what i need to do for that?

Posted

ok, i`l use ObjectMeshDynamic - it works fine , because it consists updateBounds();

Posted

Call "o.setSurfaceTransform(mat4_identity,0);" to recalculate bounds.

ObjectMesh is much more effective for intersection and collision than ObjectMeshDynamic.

Posted

bounds recalced, but still no intersection :D , something else? on ObjectMeshDynamic it works

  • 5 weeks later...
Posted

Hi Sergey!

 

Sorry for late reply, have you still issuing this problem?

 

I've modified mesh_01 example in samples/objects folder and added intersection test so it might help you.

/*
 */
void update_scene() {
	
	while(1) {
		
		float ifps = engine.game.getIFps() * 0.1f;
		
		foreach(ObjectMesh mesh, i = 0; meshes; i++) {
			mesh.setWorldTransform(Mat4(mesh.getTransform() * quat(1.0f,1.0f,1.0f,ifps * i)));
		}
		
		vec3 p0,p1;
		Unigine::getPlayerMouseDirection(p0,p1);
		
		int ret[0];
		Object o = engine.world.getIntersection(p0,p1,1,ret);
		
		if(o != NULL) {
			forloop(int i = 0; o.getNumSurfaces()) {
				o.setMaterialParameter("diffuse_color",vec4(1.0f,0.0f,0.0f,1.0f),i);
				o.setMaterialTexture("diffuse","",i);
			}
		}
		
		wait;
	}
}
×
×
  • Create New...