bool worldCoordToScreen(Vector3 objPos, Camera* cam, Vector2 screenRect,  Vector2& screenPos)
{
Matrix4 viewMatrix = cam->getViewMatrix();
Matrix4 projMatrix = cam->getProjectionMatrix();
 
Vector4 in = Vector4(objPos.x, objPos.y, objPos.z, 1.0);
Vector4 out = viewMatrix * in;
out = projMatrix * out;
 
if(out.w <= 0.0) return false;    // out.w<0时,objPos 在摄像机背面
 
out.x /= out.w;
out.y /= out.w;
out.z /= out.w;
 
// Map x, y and z to range 0-1
out.x = out.x * 0.5 + 0.5;
out.y = out.y * 0.5 + 0.5;
out.z = out.z * 0.5 + 0.5;
 
// Map x,y to viewport
out.x = out.x * screenRect.x;
out.y = (1-out.y) * screenRect.y;
 
screenPos.x = out.x;
screenPos.y = out.y;
 
return true;
}

virtual void mousePressed(MouseEvent* e)
    {
        // Left mouse button down
        if (e->getButtonID() & MouseEvent::khyJh"@BUTTON0_MASK)
        {
            // Setup the ray scene query
            Ray mouseRay = mCamera->getCameraToViewportRay( e->getX(), e->getY() );
            mRaySceneQuery->setRay( mouseRay );

// Execute query
            RaySceneQueryResult &result = mRaySceneQuery->execute();
            RaySceneQueryResult::iterator itr = result.begin( );

// Get results, create a node/entity on the position
            if ( itr != result.end() && itr-&gkhyJh"@t;worldFragment )
            {
                char name[16];
                sprintf( name, "Robot%d", mCount++ );

Entity *ent = mSceneMgr->createEntity( name, "robot.mesh" );
                mCurrentObject = mSceneMgr->getRootSceneNode( )->createChildSceneNode( String(name) + "Node", itr->worldFragment->singleIntersection );
                mCurrentObject->attachObject( ent );
                mCurrekhyJh"@ntObject->setScale( 0.1f, 0.1f, 0.1f );
            } // if

mLMouseDown = true;
        } // if

// Right mouse button down
        else if (e->getButtonID() & MouseEvent::BUTTON1_MASK)
        {
            mRMouseDown = true;
            CEGUI::MouseCursor::getSingleton().hide( );
        } // else if
    } // mousePressed

ogre世界坐标鱼屏幕坐标相互转换的更多相关文章

  1. threejs 世界坐标与屏幕坐标相互转换

    屏幕坐标转世界坐标: let pX = (screenPoint.x / this.scene.renderer.domElement.clientWidth) * 2 - 1; let pY = - ...

  2. OSG世界坐标转屏幕坐标(转载)

    OSG世界坐标转屏幕坐标 #define M(row,col) m[col * 4 + row] void Transform_Point(double out[4], const double m[ ...

  3. Unity 坐标 转换 详解 World世界坐标 Screen屏幕坐标 View视口坐标 GUI坐标 NGUI坐标 localPosition相对父级坐标

    在制作游戏中我们经常会遇到这样一个需求: 在人物模型的上面显示 名字.称号 一类的文字或者图片 如下图 人物模型属于是Camera1   UI Title信息属于NGUI Camera2 如下图 这时 ...

  4. Layabox 世界坐标和屏幕坐标互转

    最近在入坑Layabox,花了几天时间做世界坐标和屏幕坐标的互转,由于Layabox没有现成的代码所以只能自己手动写,大概就是模仿unity里面的ScreenToWorldPoint和WorldToS ...

  5. NGUI系列教程五(角色信息跟随)

    在一些网络游戏中,我们常常可以看到角色的上方显示着角色的名称,等级,血量等信息.它们可以跟随角色移动,并且可以显示和隐藏.今天我们就来学习一下这些功能的实现方法.1. 新建unity工 程,导入NGU ...

  6. three.js cannon.js物理引擎之约束

    今天郭先生继续说cannon.js,主演内容就是点对点约束和2D坐标转3D坐标.仍然以一个案例为例,场景由一个地面.若干网格组成的约束体和一些拥有初速度的球体组成,如下图.线案例请点击博客原文. 下面 ...

  7. threejs 世界坐标转化为屏幕坐标

    网站: http://www.yanhuangxueyuan.com/Three.js_course/screen.html 方法.project 通过Vector3对象的方法project,方法的参 ...

  8. Cesium中的几种坐标和相互转换【转】

    几个重要的坐标对象:1.世界坐标 Cartesian3:笛卡尔空间直角坐标系 new Cesium.Cartesian3(x, y, z) 可以看作,以椭球中心为原点的空间直角坐标系中的一个点的坐标. ...

  9. u3d 楼梯,圆环,椭圆,直线运动。世界坐标。点击。U3d stair, ring, ellipse, linear motion.World coordinates.Click .

    u3d 楼梯,圆环,椭圆,直线运动.世界坐标.点击. U3d stair, ring, ellipse, linear motion.World coordinates.Click . 作者:韩梦飞沙 ...

随机推荐

  1. MySQL 5.7 虚拟列 (virtual columns)

    参考资料: Generated Columns in MySQL 5.7.5 MySQL 5.7新特性之Generated Column(函数索引) MySQL 5.7原生JSON格式支持 Gener ...

  2. MyEclipse提示键配置、提示快捷键、提示背景色、关键字颜色、代码显示、编...

    1.提示键配置 一般默认情况下,Eclipse ,MyEclipse 的代码提示功能是比Microsoft Visual Studio的差很多的,主要是Eclipse ,MyEclipse本身有很多选 ...

  3. 常用的CSSreset整理

    说道CSSreset,大家又爱又恨,cssreset好处是,覆盖了浏览器的默认样式,使前端攻城狮能更加精确的添加样式,各个浏览器中的界面效果都相同.可是大量的.固定的CSSreset也给网页加载带来一 ...

  4. ASP.NET运行机制之一般处理程序(ashx)

    一. 概述 新建一个ashx文件  代码如下 <%@ WebHandler Language="C#" Class="TestHandler" %> ...

  5. 使用Assetbundle时可能遇到的坑

    原地址:http://www.cnblogs.com/realtimepixels/p/3652128.html 一 24 十一郎未分类 No Comments 转自 http://www.unity ...

  6. POJ 2484

    A Funny Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3861   Accepted: 2311 Desc ...

  7. IDEA开发spark本地运行

    1.建立spakTesk项目,建立scala对象Test 2.Tesk对象的代码如下 package sparkTest /** * Created by jiahong on 15-8-2. */ ...

  8. 【poj3208-Apocalypse Someday】数位DP

    题意:问你在所有包含666的数中,第n大的是多少.(1 ≤ n ≤ 50,000,000) .开头几个是666, 1666, 2666, 3666, 4666, 5666… 题解: 这题可以用AC自动 ...

  9. C#遍历打印机

    #region 获取本机默认打印机名称 ArrayList al1=new ArrayLIst(); private static PrintDocument fPrintDocument = new ...

  10. linux 中permission denied的问题:

    执行安装命令的时候 ./install 遇到 permission denied, bash: ./install: Permission denied另外,在 root下也是同样的问题, 请教该如何 ...