Exemplo n.º 1
0
void TilemapComponent::onRender(RenderingContext* context)
{
    Matrix worldInverse = Matrix::makeInverse(worldObject()->worldMatrix());
    Matrix viewLocal = context->viewPoint()->worldMatrix * worldInverse;

    Matrix viewMatrix = Matrix::makeLookAtLH(viewLocal.position(), viewLocal.position() + viewLocal.front(), viewLocal.up());
    ViewFrustum frustum(viewMatrix * context->viewPoint()->projMatrix);

    // ひとまず、 Z- を正面とする
    Plane plane(transrom()->position(), -transrom()->getFront());

    // TODO: 原点と正面方向
    Vector3 corners[8];
    Vector3 pt;
    frustum.getCornerPoints(corners);

    // TileMap の平面とカメラの視錐台から描画するべき範囲を求める
    detail::TilemapBounds bounds;
    for (int i = 0; i < 4; ++i)
    {
        if (plane.intersects(corners[i], corners[i + 4], &pt))
        {
            // pt をそのまま使う
        }
        else
        {
            // XY 平面上での最遠点を求める
            Vector2 pt2 = Vector2::normalize(corners[i + 4].xy() - corners[i].xy()) * context->viewPoint()->farClip;
            pt = Vector3(pt2, 0);
        }

        if (i == 0)
        {
            bounds.l = pt.x;
            bounds.t = pt.y;
            bounds.r = pt.x;
            bounds.b = pt.y;
        }
        else
        {
            bounds.l = std::min(bounds.l, pt.x);
            bounds.r = std::max(bounds.r, pt.x);
            bounds.t = std::max(bounds.t, pt.y);
            bounds.b = std::min(bounds.b, pt.y);
        }
    }

    
    m_tilemap->render(context, worldObject()->worldMatrix(), bounds);

    //context->drawSprite(Matrix::Identity, Size(5, 5), Vector2::Zero, Rect(0, 0, 1, 1), Color::White, SpriteBaseDirection::ZMinus, BillboardType::None, m_material);
}
DWORD CCoordinateToolManager::OnRemoveAxis(DWORD size, void *params)
{
	VERIFY_MESSAGE_SIZE(sizeof(REMOVEAXISPARAMS), size);
	REMOVEAXISPARAMS *rx = (REMOVEAXISPARAMS*)params;
	
	// Set the coordinate tool's parent to the world
	CHashString typeName = _T("CCoordinateTool");
	CHashString worldObject( _T("World") );
	static DWORD msg_SetParent = CHashString(_T("SetParent")).GetUniqueID();
	if (m_ToolBox->SendMessage(msg_SetParent, sizeof(IHashString), &worldObject, m_CoordinateToolName, &m_hszCoordinateToolClass) != MSG_HANDLED)
	{
		m_ToolBox->Log(LOGERROR, _T("CCoordinateToolManager: Failed to set coordinate tool parent!\n"));
		return MSG_HANDLED_STOP;
	}

	return MSG_HANDLED_PROCEED;
}
Exemplo n.º 3
0
 void runScript(const std::string & module, const std::string & func){
     Platformer::Script::Runnable runnable(module, func);
     Platformer::Script::AutoRef worldObject(PyCapsule_New((void *) world, "world", NULL));
     if (worldObject.getObject() == NULL){
         PyErr_Print();
     }
     
     Platformer::Script::AutoRef engine(PyCapsule_New((void *) this, "engine", NULL));
     if (engine.getObject() == NULL){
         PyErr_Print();
     }
     
     // Execute
     Platformer::Script::AutoRef function = runnable.getFunction();
     PyObject * result = PyObject_CallFunction(function.getObject(), (char*) "OO", worldObject.getObject(), engine.getObject());
     if (result == NULL){
         PyErr_Print();
     }
     Py_DECREF(result);
 }
Exemplo n.º 4
0
 void render(const Platformer::Camera & camera){
     Platformer::Script::AutoRef worldObject(PyCapsule_New((void *) world, "world", NULL));
     Platformer::Script::AutoRef engine(PyCapsule_New((void *) this, "engine", NULL));
     Platformer::Script::AutoRef bitmap(PyCapsule_New((void *) &camera.getWindow(), "bitmap", NULL));
     if (worldObject.getObject() == NULL || engine.getObject() == NULL || bitmap.getObject() == NULL){
         PyErr_Print();
     } else {
          Platformer::Script::RunMap::iterator render = scripts.find("render");
         if (render != scripts.end()){
             const Platformer::Script::Runnable renderFunction = render->second;
             // run render
             Platformer::Script::AutoRef function = renderFunction.getFunction();
             PyObject * result = PyObject_CallFunction(function.getObject(), (char *)"OOO", worldObject.getObject(), engine.getObject(), bitmap.getObject());
             if (result == NULL){
                 PyErr_Print();
             }
             Py_DECREF(result);
         }
     }
 }