⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ogre4jroot.cpp

📁 使用stl技术,(还没看,是听说的)
💻 CPP
📖 第 1 页 / 共 2 页
字号:


    // shutdown

    delete eventProcessor;
    delete root;
}

//==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==

bool Ogre4JRoot::checkException() {
    jthrowable exc = jniEnv->ExceptionOccurred();
    
    if (exc) {
        jniEnv->ExceptionDescribe();
        jniEnv->ExceptionClear();

        return true;
    }

    return false;
}

//==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==


/*
 * helper methods
 */

jobject Ogre4JRoot::newJRef(jclass clazz, void* cppRef, MovableObject* movableObjectRef) {    
    static jmethodID midSet = jniEnv->GetMethodID(nativeObjectClass, "set", "(II)V");
    jobject res = jniEnv->AllocObject(clazz);

    //jniEnv->SetIntField(res, fidNativeObject_self, (int)cppRef);
    //jniEnv->SetIntField(res, fidNativeObject_movableObject, (int)movableObjectRef);
    jniEnv->CallVoidMethod(res, midSet, (int)cppRef, (int)movableObjectRef);

    return res;
}

//==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==

void* Ogre4JRoot::getCppRef(jobject obj) {
    return (void*)jniEnv->GetIntField(obj, fidNativeObject_self);    
}

//==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==

MovableObject* Ogre4JRoot::getCppMovableObjectRef(jobject obj) {
    return (MovableObject*)jniEnv->GetIntField(obj, fidNativeObject_movableObject);
}

//==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==

ColourValue Ogre4JRoot::newColourValue(jobject col) {
    return 
        ColourValue(
            jniEnv->GetFloatField(col, fidColourValueR),
            jniEnv->GetFloatField(col, fidColourValueG),
            jniEnv->GetFloatField(col, fidColourValueB),
            jniEnv->GetFloatField(col, fidColourValueA)
        );
}

//==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==

Vector3 Ogre4JRoot::newVector3(jobject vec) {
    return
        Vector3(
            jniEnv->GetFloatField(vec, fidVector3X),
            jniEnv->GetFloatField(vec, fidVector3Y),
            jniEnv->GetFloatField(vec, fidVector3Z)
        );
}

//==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==

Quaternion Ogre4JRoot::newQuaternion(jobject q) {
    return
        Quaternion(
            jniEnv->GetFloatField(q, fidQuaternionW),
            jniEnv->GetFloatField(q, fidQuaternionX),
            jniEnv->GetFloatField(q, fidQuaternionY),
            jniEnv->GetFloatField(q, fidQuaternionZ)
        );
}

//==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==

Plane Ogre4JRoot::newPlane(jobject pln) {
	Vector3 normal = OGRE4J.newVector3(jniEnv->GetObjectField(pln, fidPlaneNormal));
	Real d = jniEnv->GetFloatField(pln, fidPlaneD);

    return
        Plane(
            normal,
            d
        );
}

//==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==

jobject Ogre4JRoot::newVector3(const Vector3& vec) {
    jobject res = jniEnv->AllocObject(vectorClass);    
    jniEnv->CallVoidMethod(res, midVectorSet, vec.x, vec.y, vec.z);
    return res;
}

//==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==

jobject Ogre4JRoot::newColourValue(const ColourValue& col) {
    jobject res = jniEnv->AllocObject(colourValueClass);
    jniEnv->CallVoidMethod(res, midColourValueSet, col.r, col.g, col.b, col.a);
    return res;
}

//==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==

jobject Ogre4JRoot::newQuaternion(const Quaternion& q) {
    jobject res = jniEnv->AllocObject(quaternionClass);
    jniEnv->CallVoidMethod(res, midQuaternionSet, q.w, q.x, q.y, q.z);
    return res;
}

//==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==

jobject Ogre4JRoot::newPlane(const Plane& pln) {
    jobject res = jniEnv->AllocObject(planeClass);
    jniEnv->CallVoidMethod(res, midPlaneSet, pln.normal, pln.d);
    return res;
}

//==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==


/*
 * EVENTS
 */

jobject Ogre4JRoot::newFrameEvent(const FrameEvent& evt) {    
    static jclass    clazz = jniEnv->FindClass("org/ogre4j/event/FrameEvent");
    static jmethodID setMethodMID;

    if(!frameEventRef) {
        frameEventRef = jniEnv->AllocObject(clazz);        
        setMethodMID  = jniEnv->GetMethodID(clazz, "set", "(FF)V");        
    }
    
    jniEnv->CallVoidMethod(
        frameEventRef, setMethodMID,
        evt.timeSinceLastEvent, evt.timeSinceLastFrame
    );

    return frameEventRef;
}

//==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==

jobject Ogre4JRoot::newKeyEvent(KeyEvent* e) {    
    static jclass    clazz = jniEnv->FindClass("org/ogre4j/event/KeyEvent"); 
    static jmethodID setMethodMID;

    if(!keyEventRef) {
        keyEventRef  = jniEnv->AllocObject(clazz);        
        setMethodMID = jniEnv->GetMethodID(clazz, "set", "(II)V");
    }

    jniEnv->CallVoidMethod(
        keyEventRef, setMethodMID, e->getKey(), e->getModifiers()
    );

    return keyEventRef;
}

//==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==

jobject Ogre4JRoot::newMouseEvent(MouseEvent* e) {    
    static jclass  clazz = jniEnv->FindClass("org/ogre4j/event/MouseEvent");    
    static jmethodID setMethodMID;
    if(!mouseEventRef) {
        mouseEventRef = jniEnv->AllocObject(clazz);
        setMethodMID  = jniEnv->GetMethodID(clazz, "set", "(IFFFFFFI)V");
    }    

    jniEnv->CallVoidMethod(
        mouseEventRef,
        setMethodMID,
        e->getButtonID(),
        e->getX(),
        e->getY(),
        e->getZ(),
        e->getRelX(),
        e->getRelY(),
        e->getRelZ(),
        e->getModifiers()
    );

    return mouseEventRef;
}

//==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==


/*
 * OGRE LISTENERS
 */

bool Ogre4JRoot::frameStarted(const FrameEvent& evt) {        

    eventProcessor->frameStarted(evt);

    jniEnv->CallVoidMethod(
        eventHub,
        frameStartedMethodId,
        newFrameEvent(evt)
    );
    
    return !quitRenderLoop && !checkException();
}

//==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==

bool Ogre4JRoot::frameEnded(const FrameEvent& evt) {

    eventProcessor->frameEnded(evt);

    jniEnv->CallVoidMethod(
        eventHub,
        frameEndedMethodId,
        newFrameEvent(evt)
    );
    
    return !quitRenderLoop;
}

//==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==

void Ogre4JRoot::keyClicked     (KeyEvent *e) {
    jniEnv->CallVoidMethod(
        eventHub,
        keyClickedMethodId,
        newKeyEvent(e)
    );
}  

//==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==

void Ogre4JRoot::keyPressed     (KeyEvent *e) {
    jniEnv->CallVoidMethod(
        eventHub,
        keyPressedMethodId,
        newKeyEvent(e)
    );
}  

//==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==

void Ogre4JRoot::keyReleased    (KeyEvent *e) {
    jniEnv->CallVoidMethod(
        eventHub,
        keyReleasedMethodId,
        newKeyEvent(e)
    );
}

//==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==

void Ogre4JRoot::mouseClicked   (MouseEvent *e) {
    jniEnv->CallVoidMethod(
        eventHub,
        mouseClickedMethodId,
        newMouseEvent(e)
    );
}

//==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==

void Ogre4JRoot::mouseEntered   (MouseEvent *e) {
    jniEnv->CallVoidMethod(
        eventHub,
        mouseEnteredMethodId,
        newMouseEvent(e)
    );
}

//==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==

void Ogre4JRoot::mouseExited    (MouseEvent *e) {
    jniEnv->CallVoidMethod(
        eventHub,
        mouseExitedMethodId,
        newMouseEvent(e)
    );
}

//==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==

void Ogre4JRoot::mousePressed   (MouseEvent *e) {
    jniEnv->CallVoidMethod(
        eventHub,
        mousePressedMethodId,
        newMouseEvent(e)
    );
}

//==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==

void Ogre4JRoot::mouseReleased  (MouseEvent *e) {
    jniEnv->CallVoidMethod(
        eventHub,
        mouseReleasedMethodId,
        newMouseEvent(e)
    );
}

//==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==

void Ogre4JRoot::mouseMoved     (MouseEvent *e) {
    jniEnv->CallVoidMethod(
        eventHub,
        mouseMovedMethodId,
        newMouseEvent(e)
    );
}

//==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==

void Ogre4JRoot::mouseDragged   (MouseEvent *e) {
    jniEnv->CallVoidMethod(
        eventHub,
        mouseDraggedMethodId,
        newMouseEvent(e)
    );
}

//==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==~==

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -