1

(4 replies, posted in General)

put it near your game project file

2

(1 replies, posted in Engine)

Where can i find it ? (i saw somewhere, can't remember where sad )

Petr wrote:

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

(5 replies, posted in Editor)

anael wrote:

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 smile

5

(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 big_smile
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

(5 replies, posted in Editor)

Is there a way to display physic bodies ?
Does fuctions set rotation and else transform bodies ?

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