put it near your game project file
2 2012-10-03 16:00:11
Topic: TODO List (1 replies, posted in Engine)
Where can i find it ? (i saw somewhere, can't remember where )
3 2012-09-25 16:56:57
Re: Use of lua in maratis3d iOS project for hit testing (8 replies, posted in Scripting)
Thank you for sharing!
there was i bug, i updated post
P.S.
changed
MVector3 rayD = camera->getUnProjectedPoint(MVector3(x * float(width), y * float(height), 1));
to
MVector3 rayD = camera->getUnProjectedPoint(MVector3(x * float(width), (1 - y) * float(height), 1));
4 2012-09-25 16:55:42
Re: Physics (5 replies, posted in Editor)
I think the y mouse needs to be inverted :
Your camera is not in ortho mode ?MVector3 cameraPos = camera->getTransformedPosition(); MVector3 mousePos3d = camera->getUnProjectedPoint(MVector3(x*width, height - y*height, 1)); MVector3 vec = (mousePos3d - cameraPos).getNormalized(); MVector3 rayO = pos + vec*camera->getClippingNear(); MVector3 rayD = pos + vec*camera->getClippingFar();
Perspective. Thanks for hint, i missed about y axis
5 2012-09-25 12:14:51
Re: Physics (5 replies, posted in Editor)
Thanks for fast response, when i tried to pick objects (with function i wrote in my plugin) i faced the problem that after rotation the body is not rotated, so
The rotation/scale etc transform the bodies yes.
so, i think i have a problem with my function below
can you look at this function and say whats wrong ? (I use only perspective projection)
int pickObject(void)
{
MEngine * engine = MEngine::getInstance();
MScriptContext * script = engine->getScriptContext();
if (script->getArgsNumber() == 3)
{
MOCamera * camera = (MOCamera *)script->getPointer(0);
float x = script->getFloat(1);
float y = script->getFloat(2);
MPhysicsContext * physics = engine->getPhysicsContext();
unsigned int width, height;
engine->getSystemContext()->getScreenSize(&width, &height);
MVector3 rayO = camera->getTransformedPosition();
MVector3 rayD = camera->getUnProjectedPoint(MVector3(x * float(width), y * float(height), 1));
rayD = rayO + ((rayD - rayO).getNormalized() * (camera->getClippingFar() - camera->getClippingNear()));
unsigned int objId;
if (physics->isRayHit(rayO, rayD, &objId))
{
MLevel * level = engine->getLevel();
MScene * scene = level->getCurrentScene();
unsigned int entCount = scene->getEntitiesNumber();
for (unsigned int i = 0; i < entCount; ++i)
{
MOEntity * entity = scene->getEntityByIndex(i);
MPhysicsProperties * phyProps = entity->getPhysicsProperties();
if (phyProps)
{
if (phyProps->getCollisionObjectId() == objId)
{
script->pushPointer(entity);
return 1;
}
}
}
}
}
return 0;
}
sometimes if works wrong (don't detect collision)
6 2012-09-25 11:23:22
Topic: Physics (5 replies, posted in Editor)
Is there a way to display physic bodies ?
Does fuctions set rotation and else transform bodies ?
7 2012-09-23 16:09:15
Re: Use of lua in maratis3d iOS project for hit testing (8 replies, posted in Scripting)
here is the function i created to pick objects :
int pickObject(void)
{
MEngine * engine = MEngine::getInstance();
MScriptContext * script = engine->getScriptContext();
if (script->getArgsNumber() == 3)
{
MOCamera * camera = (MOCamera *)script->getPointer(0);
float x = script->getFloat(1);
float y = script->getFloat(2);
MPhysicsContext * physics = engine->getPhysicsContext();
unsigned int width, height;
engine->getSystemContext()->getScreenSize(&width, &height);
MVector3 rayO = camera->getTransformedPosition();
MVector3 rayD = camera->getUnProjectedPoint(MVector3(x * float(width), (1 - y) * float(height), 1));
rayD = rayO + ((rayD - rayO).getNormalized() * (camera->getClippingFar() - camera->getClippingNear()));
unsigned int objId;
if (physics->isRayHit(rayO, rayD, &objId))
{
MLevel * level = engine->getLevel();
MScene * scene = level->getCurrentScene();
unsigned int entCount = scene->getEntitiesNumber();
for (unsigned int i = 0; i < entCount; ++i)
{
MOEntity * entity = scene->getEntityByIndex(i);
MPhysicsProperties * phyProps = entity->getPhysicsProperties();
if (phyProps)
{
if (phyProps->getCollisionObjectId() == objId)
{
script->pushPointer(entity);
return 1;
}
}
}
}
}
return 0;
}
Usage :
obj = pickObject(Camera, x, y)
if obj then
...
end