//-------------------------------------------------------
void handManagerNode::updateCamToScreenCoords(){
	
	GLdouble model_view[16];
	glGetDoublev(GL_MODELVIEW_MATRIX, model_view);

	GLdouble projection[16];
	glGetDoublev(GL_PROJECTION_MATRIX, projection);

	GLint viewport[4];
	glGetIntegerv(GL_VIEWPORT, viewport);
		
	GLdouble X, Y, Z;		
	
	if( seqPin.currentSection.name == "open" || seqPin.currentSection.name == "poke"  ){
		storePersonPosPin = myPerson.pos;
	}
	
	if( seqFan.currentSection.name == "open"  ){
		storePersonPosFan = myPerson.pos;
	}

	if( seqPin.bPlay ){
		gluProject(storePersonPosPin.x - 50, storePersonPosPin.y + 45, storePersonPosPin.z, model_view, projection, viewport, &X, &Y, &Z);
		myPersonScreenPosPin.set(X, ofGetHeight()-Y, Z);
		seqPin.setPosition(myPersonScreenPosPin.x, myPersonScreenPosPin.y, 0);		
	}

	if( seqFan.bPlay ){
		gluProject(storePersonPosFan.x-50, storePersonPosFan.y - 180, storePersonPosFan.z, model_view, projection, viewport, &X, &Y, &Z);
		myPersonScreenPosFan.set(X, ofGetHeight()-Y, Z);
		seqFan.setPosition(myPersonScreenPosFan.x, myPersonScreenPosFan.y, 0);		
	}
		
}
Exemple #2
0
void RDirNode::calcScreenPos(GLint* viewport, GLdouble* modelview, GLdouble* projection) {

    static GLdouble screen_x, screen_y, screen_z;

    gluProject( pos.x, pos.y, 0.0f, modelview, projection, viewport, &screen_x, &screen_y, &screen_z);
    screen_y = (float)viewport[3] - screen_y;
    projected_pos.x = screen_x;
    projected_pos.y = screen_y;

    gluProject( spos.x, spos.y, 0.0f, modelview, projection, viewport, &screen_x, &screen_y, &screen_z);
    screen_y = (float)viewport[3] - screen_y;
    projected_spos.x = screen_x;
    projected_spos.y = screen_y;

    static vec2 selected_offset(5.5f, -2.0f);
    static vec2 unselected_offset(5.5f, -1.0f);

    if(!gGourceSettings.hide_filenames) {

        //first pass - calculate positions of names
        for(std::list<RFile*>::const_iterator it = files.begin(); it!=files.end(); it++) {
            RFile* f = *it;
            f->calcScreenPos(viewport, modelview, projection);
        }
    }

    for(std::list<RDirNode*>::const_iterator it = children.begin(); it != children.end(); it++) {
        RDirNode* node = (*it);
        node->calcScreenPos(viewport, modelview, projection);
    }
}
static void build_pan_jacobian(BotDefaultViewHandler *dvh, double dq[3], double up[3], double left[3], double A[4])
{
    //////////////////////////////////////////
    // How fast do the screen coordinates for dq change when we
    // translate dq in the up and left directions? We compute
    // derivatives numerically with step size eps.
    double eps = 0.00001;

    double PM_dq[3];
    gluProject(dq[0], dq[1], dq[2],
               dvh->model_matrix, dvh->projection_matrix, dvh->viewport,
               &PM_dq[0], &PM_dq[1], &PM_dq[2]);

    double PM_dq_up[3];
    gluProject(dq[0] + up[0]*eps, dq[1] + up[1]*eps, dq[2] + up[2]*eps,
               dvh->model_matrix, dvh->projection_matrix, dvh->viewport,
               &PM_dq_up[0], &PM_dq_up[1], &PM_dq_up[2]);

    double PM_dq_left[3];
    gluProject(dq[0] + left[0]*eps, dq[1] + left[1]*eps, dq[2] + left[2]*eps,
               dvh->model_matrix, dvh->projection_matrix, dvh->viewport,
               &PM_dq_left[0], &PM_dq_left[1], &PM_dq_left[2]);

    //////////////////////////////////////////
    // Compute the Jacobian of screen coordinate changes with respect
    // to translation.
    A[0] = (PM_dq_up[0]   - PM_dq[0]) / eps;
    A[1] = (PM_dq_left[0] - PM_dq[0]) / eps;
    A[2] = (PM_dq_up[1]   - PM_dq[1]) / eps;
    A[3] = (PM_dq_left[1] - PM_dq[1]) / eps;
}
void Gameboard::UpdateSquareScreenCoordinate(){

	GLint viewport[4];
	GLdouble modelview[16];
	GLdouble projection[16];
	GLdouble winX, winY, winZ;
	GLdouble prevwinX, prevwinY, prevwinZ;

	glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
	glGetDoublev(GL_PROJECTION_MATRIX, projection);
	glGetIntegerv(GL_VIEWPORT, viewport);

	for (unsigned i = 0; i < squaresList.size(); i++)
	{
		// attention x correspond aux colonnes (sizez) et y au ligne (sizex...
		int posX = (int)squaresList[i].getX()* 100 + 50;
		int posZ = (int)squaresList[i].getZ() * 100 + 50;
		gluProject(posX, 0, posZ,
			modelview, projection, viewport,
			&winX, &winY, &winZ);

		squaresList[i].setScreencoordX(winX);
		squaresList[i].setScreencoordY(glutGet(GLUT_WINDOW_HEIGHT) - winY);
		/*std::cout << "__________________________________________________" << i << std::endl;
		
		std::cout << "ligne =    " << squaresList[i].getZ() <<  "posx =    " << posX << std::endl;
		std::cout << "colone =    " << squaresList[i].getX() << "posZ =    " << posZ << std::endl;
		
		std::cout << "squareX =    " << squaresList[i].getScreenCoordX() << std::endl;
		std::cout << "squareY =    " << squaresList[i].getScreenCoordY() << std::endl; */

	}
}
Exemple #5
0
inline float gl_project_get_depth(int x,int y,int z)
{
	double		dx,dy,dz;

	gluProject(x,y,z,mod_matrix,proj_matrix,(GLint*)vport,&dx,&dy,&dz);
	return((float)dz);
}
Exemple #6
0
IoObject *IoSeq_glProject(IoSeq *self, IoObject *locals, IoMessage *m)
{
	IoSeq_assertIsVector(self, locals, m);
	{
		float *f = IoSeq_floatPointerOfLength_(self, 3);
		/* Project the receiver from object to window coordinates. */
		GLint viewport[4];
		GLdouble mvmatrix[16];
		GLdouble projmatrix[16];
		GLdouble objx, objy, objz;

		glGetIntegerv(GL_VIEWPORT, viewport);
		glGetDoublev(GL_MODELVIEW_MATRIX, mvmatrix);
		glGetDoublev(GL_PROJECTION_MATRIX, projmatrix);

		gluProject((GLdouble)(f[0]),
				   (GLdouble)(f[1]),
				   (GLdouble)(f[2]),
				   mvmatrix, projmatrix, viewport,
				   &objx, &objy, &objz);

		f[0] = objx;
		f[1] = objy;
		f[2] = objz;
	}
	return self;
}
Exemple #7
0
__Vect3D ms_GetScreenCoords(float SceneX, float SceneY, float SceneZ)
{
	__Vect3D RetVect;
	GLdouble ModelM[16], ProjM[16], Pos[3];
	int Viewp[4];

	glPushMatrix();
		glLoadIdentity();
		gl_SetupScene3D(zProgram.WindowWidth, zProgram.WindowHeight);
		gl_LookAt(zCamera.X, zCamera.Y, zCamera.Z, zCamera.X + zCamera.LX, zCamera.Y + zCamera.LY, zCamera.Z + zCamera.LZ);
		glScalef(0.005, 0.005, 0.005);

		glGetDoublev(GL_MODELVIEW_MATRIX, ModelM);
		glGetDoublev(GL_PROJECTION_MATRIX, ProjM);
		glGetIntegerv(GL_VIEWPORT, (GLint*)Viewp);

		gluProject((GLdouble)SceneX, (GLdouble)SceneY, (GLdouble)SceneZ, ModelM, ProjM, (GLint*)Viewp, &Pos[0], &Pos[1], &Pos[2]);

		Pos[1] = (GLdouble)Viewp[3] - (GLdouble)Pos[1] - 1;

		RetVect.X = (signed int)Pos[0];
		RetVect.Y = (signed int)Pos[1];
		RetVect.Z = (signed int)Pos[2];

		gl_SetupScene2D(zProgram.WindowWidth, zProgram.WindowHeight);
	glPopMatrix();

	return RetVect;
}
void CHapticMouse::Sync3DTo2DCursor()
{
    double X, Y, Z;
    CRect viewSize;
    CPoint point;

    GetClientRect(&viewSize);

    if (QueryCursorPos(&X, &Y, &Z)) {
        GLdouble matModel[16];
        glGetDoublev(GL_MODELVIEW_MATRIX, matModel);
        GLdouble matProj[16];
        glGetDoublev(GL_PROJECTION_MATRIX, matProj);
        GLint viewport[16];
        glGetIntegerv(GL_VIEWPORT, viewport);
        GLdouble x, y, z;
        gluProject(X, Y, Z, matModel, matProj, viewport, &x, &y, &z);
        
        point.x = min(max(0, (int) x), viewSize.Width());
        point.y = min(max(0, viewSize.Height() - (int) y), viewSize.Height());
    } else {
        // Application does not have a current 3D cursor, center the mouse
        // pointer in the window
        point.x = viewSize.Width() / 2;
        point.y = viewSize.Height() / 2;
    }
    
    // Place the mouse cursor at the computed position
    ClientToScreen(&point);
    SetCursorPos(point.x, point.y);
}
Exemple #9
0
/*glu.Project(objx, objy, objz, modelMatrixArray, projMatrixArray, viewportArray) -> error, winx, winy, winz */
static int luaglu_project(lua_State *L)
{
  GLdouble winx, winy, winz;
  GLdouble modelMatrix[16];
  GLdouble projMatrix[16]; 
  GLint viewport[4];
  int error;

  luaglu_load_matrix16d(L, 4, modelMatrix);
  luaglu_load_matrix16d(L, 5, projMatrix);
  luaglu_load_viewport(L, 6, viewport);

  error = gluProject(luaL_checknumber(L, 1), luaL_checknumber(L, 2), luaL_checknumber(L, 3), 
                     modelMatrix, projMatrix, viewport, &winx, &winy, &winz);
  lua_pushnumber(L, error);

  if (error == GL_TRUE)
  {
    lua_pushnumber(L, winx);
    lua_pushnumber(L, winy);
    lua_pushnumber(L, winz);
    return 4;
  }
  else
    return 1;
}
Exemple #10
0
static void hugsprim_gluProject_4(HugsStackPtr hugs_root)
{
    HsDouble arg1;
    HsDouble arg2;
    HsDouble arg3;
    HsPtr arg4;
    HsPtr arg5;
    HsPtr arg6;
    HsPtr arg7;
    HsPtr arg8;
    HsPtr arg9;
    HsInt32 res1;
    arg1 = hugs->getDouble();
    arg2 = hugs->getDouble();
    arg3 = hugs->getDouble();
    arg4 = hugs->getPtr();
    arg5 = hugs->getPtr();
    arg6 = hugs->getPtr();
    arg7 = hugs->getPtr();
    arg8 = hugs->getPtr();
    arg9 = hugs->getPtr();
    res1 = gluProject(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
    hugs->putInt32(res1);
    hugs->returnIO(hugs_root,1);
}
static int mouse_scroll  (BotViewer *viewer, BotEventHandler *ehandler,
                          const double ray_start[3], const double ray_dir[3], const GdkEventScroll *event)
{
    BotDefaultViewHandler *dvh = (BotDefaultViewHandler*) ehandler->user;

    // scrolling = zoom in and out
    if ( event->direction == GDK_SCROLL_UP) {
        zoom_ratio (dvh, 0.9);
    } else if (event->direction == GDK_SCROLL_DOWN) {
        zoom_ratio (dvh, 1.1);
    }

    // how far from XY plane?
    double dist = (ray_start[2] - dvh->lastpos[2]) / ray_dir[2];

    double dq[] = {ray_start[0] - ray_dir[0]*dist,
                   ray_start[1] - ray_dir[1]*dist,
                   ray_start[2] - ray_dir[2]*dist,
                   1
                  };

    double PM_dq[3];
    gluProject(dq[0], dq[1], dq[2],
               dvh->model_matrix, dvh->projection_matrix, dvh->viewport,
               &PM_dq[0], &PM_dq[1], &PM_dq[2]);

    window_space_pan(dvh, dq, event->x - PM_dq[0], -((dvh->viewport[3] - event->y) - PM_dq[1]), 1);

    bot_viewer_request_redraw(viewer);
    return 1;
}
Exemple #12
0
void rgl_user2window(int* successptr, int* idata, double* point, double* pixel, double* model, double* proj, int* view)
{
  int success = RGL_FAIL;
  GLdouble* vertex = pixel;
  int columns = idata[0];
  GLint viewport[4];

  Device* device;

  if (deviceManager && (device = deviceManager->getAnyDevice())) {
  
  	for (int i=0; i<4; i++) viewport[i] = view[i];
  	for (int i=0; i<columns; i++) {
		gluProject(point[0],point[1],point[2],model,proj,viewport,
		vertex,vertex+1,vertex+2);
		vertex[0] /= view[2];
		vertex[1] /= view[3];
		point += 3;
		vertex += 3;
	}
	success = RGL_SUCCESS;
  }

  *successptr = success;
}
void BSplineSurfaceView::NewPickedObject()
{
    int cx = m_pickedName >> 16;
    int cy = m_pickedName & 0xFFFF;

    GLdouble model_view[16];
    glGetDoublev(GL_MODELVIEW_MATRIX, model_view);

    GLdouble projection[16];
    glGetDoublev(GL_PROJECTION_MATRIX, projection);

    GLint viewport[4];
    glGetIntegerv(GL_VIEWPORT, viewport);


    Vertex3d cpWorld = Vertex3d(m_controlPoints[cx][cy]); // control point in world coordinates
    Vertex3d cpScreen = Vertex3d(); // control point in screen coordinates
    gluProject(cpWorld.X(),cpWorld.Y(),cpWorld.Z(),model_view,projection,viewport,cpScreen.XRef(),cpScreen.YRef(),cpScreen.ZRef());

    // Mouse offset to control point to maintain relative distance. - NOT WORKING
    m_dragOffsetX = 0;//m_lastMouseX - cpScreen.X();
    m_dragOffsetY = 0;//(viewport[3]-m_lastMouseY) - cpScreen.Y();

    m_pickedZ = cpScreen.Z();
}
JVector
JXMesaCamera::ModelToScreen
	(
	const JVector& pt
	)
{
	if (!PrepareMesa())
		{
		return pt;
		}

	PrepareTransforms();

	GLdouble modelMatrix[16], projMatrix[16];
	GLint viewport[4];

	glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);
	glGetDoublev(GL_PROJECTION_MATRIX, modelMatrix);
	glGetIntegerv(GL_VIEWPORT, viewport);

	JFloat x,y,z;
	gluProject(pt.GetElement(1), pt.GetElement(2), pt.GetElement(3),
			   modelMatrix, projMatrix, viewport, &x, &y, &z);

	return JVector(3, x, y, z);
}
Exemple #15
0
//===========================================================================
Vector3D gvCamera::objectCoordsToWindowCoords(const Vector3D& pt) const
//===========================================================================
{
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    use();

    int viewport[4];
    double projection[16];
    double modelview[16];
    glGetIntegerv(GL_VIEWPORT, viewport);
    glGetDoublev(GL_PROJECTION_MATRIX, projection);
    glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
    Vector3D winpt;
    int success = gluProject(pt[0], pt[1], pt[2],
			       modelview, projection, viewport,
			       &winpt[0], &winpt[1], &winpt[2]);

    // It seems that the y value is referring to the opposite edge. @@sbr Fix this!
    winpt[1] = viewheight_ - winpt[1];

    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();

    ALWAYS_ERROR_IF(!success, "gluProject() failed!");
    return winpt;
}
Exemple #16
0
//===========================================================================
void gvCamera::moveFocalPointRelative(const Vector3D& eyeptrel)
//===========================================================================
{
    // Compute the window z coordinate of the focal point
    int viewport[4];
    double projection[16];
    double modelview[16];
    glGetIntegerv(GL_VIEWPORT, viewport);
    glGetDoublev(GL_PROJECTION_MATRIX, projection);
    glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
    Vector3D ppp;
    gluProject(focal_point_[0], focal_point_[1], focal_point_[2],
	       modelview, projection, viewport,
	       &ppp[0], &ppp[1], &ppp[2]);
    double winz = ppp[2];
    //    std::cout << "PPP = " << ppp << std::endl;

    // Interpret the third value of eyeptrel as a relative
    // amount to move the viewpoint
//     double objz = eyeptrel[2];

    Vector3D pmiddle(viewx_ + viewwidth_/2,
		       viewy_ + viewheight_/2,
		       winz);//(distance_-near_)/(far_-near_));
    Vector3D pnew = pmiddle + eyeptrel;
    Vector3D trpm = eyeCoordsToObjectCoords(pmiddle);
    Vector3D trpn = eyeCoordsToObjectCoords(pnew);
//      std::cout << "------------------\n" << pmiddle << pnew << trpm << trpn
//  	      << trpn - trpm;
    focal_point_ -= trpn;
    focal_point_ += trpm;
}
tgt::vec3 GeometryRendererBase::getWindowPos(tgt::vec3 pos, tgt::mat4 pModelview, tgt::mat4 pProjection) const {
    GLint viewport[4];
    GLdouble modelview[16];
    GLdouble projection[16];

    tgt::mat4 projection_tgt = camera_.getProjectionMatrix() * pProjection;
    tgt::mat4 modelview_tgt = camera_.getViewMatrix() * pModelview;
    for (int i = 0; i < 4; ++i) {
        modelview[i+0]   = modelview_tgt[i].x;
        modelview[i+4]   = modelview_tgt[i].y;
        modelview[i+8]   = modelview_tgt[i].z;
        modelview[i+12]  = modelview_tgt[i].w;
        projection[i+0]  = projection_tgt[i].x;
        projection[i+4]  = projection_tgt[i].y;
        projection[i+8]  = projection_tgt[i].z;
        projection[i+12] = projection_tgt[i].w;
    }
    viewport[0] = 0;
    viewport[1] = 0;
    viewport[2] = idManager_->getRenderTarget()->getSize().x;
    viewport[3] = idManager_->getRenderTarget()->getSize().y;

    GLdouble pointProjectedGL[3];
    gluProject(pos.x, pos.y, pos.z, modelview, projection, viewport,
               &pointProjectedGL[0], &pointProjectedGL[1], &pointProjectedGL[2]);

    return tgt::vec3(static_cast<float>(pointProjectedGL[0]),
                     static_cast<float>(pointProjectedGL[1]),
                     static_cast<float>(pointProjectedGL[2]));
}
//====================================================drawNameIn3D======================================//
void ccHObject::drawNameIn3D(CC_DRAW_CONTEXT& context)
{
	//绘制窗口
	if (!context._win)return;

	//we display it in the 2D layer in fact!
	ccBBox bBox = getOwnBB();
	if (bBox.isValid()){

		ccGLMatrix trans;
		getAbsoluteGLTransformation(trans); //得到由祖先到当前物体的变换矩阵

		const double* MM = context._win->getModelViewMatd(); //viewMat   //模型视图矩阵
		const double* MP = context._win->getProjectionMatd(); //projMat  //投影矩阵
		int VP[4];
		context._win->getViewportArray(VP); //视口参数

		GLdouble xp,yp,zp;
		CCVector3 C = bBox.getCenter(); //BB的中心为之
		trans.apply(C); //实际的位置和显示的位置不同,将变换矩阵作用到中心位置上
		gluProject(C.x,C.y,C.z,MM,MP,VP,&xp,&yp,&zp); //根据视图矩阵,投影矩阵和视口参数对BB中心点进行投影

		QFont font = context._win->getTextDisplayFont(); //takes rendering zoom into account! //获取字体

		//在2D屏幕上显示文本
		context._win->displayText(	getName(),
									static_cast<int>(xp),
									static_cast<int>(yp),
									ccGenericGLDisplay::ALIGN_HMIDDLE | ccGenericGLDisplay::ALIGN_VMIDDLE,
									0.75f,
									0,
									&font);
	}
}
Exemple #19
0
float kScreenUnitPerWorldUnitAtPos ( const KVector & pos )
{
    GLdouble ox, oy, xx, xy, yx, yy, zx, zy, z, model[16], proj[16]; GLint view[4];
    GLdouble px = pos[X], py = pos[Y], pz = pos[Z];
    
    glGetDoublev(GL_PROJECTION_MATRIX, proj); 
    glGetDoublev(GL_MODELVIEW_MATRIX, model);
    glGetIntegerv(GL_VIEWPORT, (GLint*)view);

    gluProject(px, py, pz, 	 model, proj, view, &ox, &oy, &z);
    gluProject(px + 1.0, py, pz, model, proj, view, &xx, &xy, &z);
    gluProject(px, py + 1.0, pz, model, proj, view, &yx, &yy, &z);
    gluProject(px, py, pz + 1.0, model, proj, view, &zx, &zy, &z);
    
    return (kMax(kMax(kAbs(xx-ox)+kAbs(xy-oy),kAbs(yx-ox)+kAbs(yy-oy)),kAbs(zx-ox)+kAbs(zy-oy)));
}
Exemple #20
0
/**
 * Convert the screen space coordinate (x, y) to the model space coordinate.
 */
void GLWidget::mouseTo2D(int x,int y, QVector2D &result) {
	GLint viewport[4];
	GLdouble modelview[16];
	GLdouble projection[16];

	// retrieve the matrices
	glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
	glGetDoublev(GL_PROJECTION_MATRIX, projection);
	glGetIntegerv(GL_VIEWPORT, viewport);

	// retrieve the projected z-buffer of the origin
	GLdouble origX, origY, origZ;
	gluProject(0, 0, 0, modelview, projection, viewport, &origX, &origY, &origZ);

	// set up the projected point
	GLfloat winX = (float)x;
	GLfloat winY = (float)viewport[3] - (float)y;
	GLfloat winZ = origZ;
	
	// unproject the image plane coordinate to the model space
	GLdouble posX, posY, posZ;
	gluUnProject(winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ);

	result.setX(posX);
	result.setY(posY);
}
Exemple #21
0
static Bool
facing_screen_p (ModeInfo *mi)
{
  Bool facing_p;
  GLdouble m[16], p[16], x, y, z;
  GLint v[4];
  glGetDoublev (GL_MODELVIEW_MATRIX, m);
  glGetDoublev (GL_PROJECTION_MATRIX, p);
  glGetIntegerv (GL_VIEWPORT, v);
	
  /* See if a coordinate 5 units in front of the door is near the
     center of the screen. */
  gluProject (0, -5, 0, m, p, v, &x, &y, &z);
  x = (x / MI_WIDTH(mi))  - 0.5;
  y = (y / MI_HEIGHT(mi)) - 0.5;

  facing_p = (z < 0.9 &&
              x > -0.15 && x < 0.15 &&
              y > -0.15 && y < 0.15);

# ifdef DEBUG_MODE
  glBindTexture(GL_TEXTURE_2D, 0);
  glDisable (GL_LIGHTING);
  glColor3f (1, (facing_p ? 1 : 0), 0);
  glBegin (GL_LINES);
  glVertex3f (0, 0, 0);
  glVertex3f (0, -5, 0);
  glEnd();
  if (!MI_IS_WIREFRAME(mi)) glEnable (GL_LIGHTING);
# endif /* DEBUG_MODE */

  return facing_p;
}
Exemple #22
0
  vec3 Camera::project(ivec2 vp, vec3 point) const {
    GLint viewport[4];
    GLdouble modelview[16];
    GLdouble projection[16];

    mat4 projection_glm = getProjectionMatrix(vp);
    mat4 modelview_glm = getViewMatrix();
    for (int i = 0; i < 4; ++i) {
      modelview[i + 0] = modelview_glm[i].x;
      modelview[i + 4] = modelview_glm[i].y;
      modelview[i + 8] = modelview_glm[i].z;
      modelview[i + 12] = modelview_glm[i].w;
      projection[i + 0] = projection_glm[i].x;
      projection[i + 4] = projection_glm[i].y;
      projection[i + 8] = projection_glm[i].z;
      projection[i + 12] = projection_glm[i].w;
    }
    viewport[0] = 0;
    viewport[1] = 0;
    viewport[2] = vp.x;
    viewport[3] = vp.y;

    GLdouble pointProjectedGL[3];
    gluProject(point.x, point.y, point.z, modelview, projection, viewport,
      &pointProjectedGL[0], &pointProjectedGL[1], &pointProjectedGL[2]);

    return vec3(static_cast<float>(pointProjectedGL[0]),
      static_cast<float>(pointProjectedGL[1]),
      static_cast<float>(pointProjectedGL[2]));
  }
Exemple #23
0
void ccHObject::drawNameIn3D(CC_DRAW_CONTEXT& context)
{
	if (!context._win)
		return;

	//we display it in the 2D layer in fact!
	ccBBox bBox = getBB(false,false,m_currentDisplay);
	if (bBox.isValid())
	{
		const double* MM = context._win->getModelViewMatd(); //viewMat
		const double* MP = context._win->getProjectionMatd(); //projMat
		int VP[4];
		context._win->getViewportArray(VP);

		GLdouble xp,yp,zp;
		CCVector3 C = bBox.getCenter();
		gluProject(C.x,C.y,C.z,MM,MP,VP,&xp,&yp,&zp);

		QFont font = context._win->getTextDisplayFont(); //takes rendering zoom into account!
		context._win->displayText(	getName(),
									static_cast<int>(xp),
									static_cast<int>(yp),
									ccGenericGLDisplay::ALIGN_HMIDDLE | ccGenericGLDisplay::ALIGN_VMIDDLE,
									0.75f,
									0,
									&font);
	}
}
Exemple #24
0
void Scene::GetOrthoPosition(void)
{
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(-m_width / 2.f, m_width / 2.f, m_height / 2.f, -m_height / 2.f, m_zNear, m_zFar);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	GLint viewport[4];
	glGetIntegerv(GL_VIEWPORT, viewport);

	GLdouble modelview[16];
	glGetDoublev(GL_MODELVIEW_MATRIX, modelview);

	GLdouble projection[16];
	glGetDoublev(GL_PROJECTION_MATRIX, projection);

	GLdouble winX = 0, winY = 0, winZ = 0;

	gluProject(0, 0, 0, modelview, projection, viewport, &winX, &winY, &winZ);

	winX = (float)InputManager::GetInstance().GetRawMousePosition().x;
	winY = (float)InputManager::GetInstance().GetRawMousePosition().y;
	winY = (float)viewport[3] - winY;

	GLdouble posX = 0, posY = 0, posZ = 0;

	gluUnProject(winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ);

	InputManager::GetInstance().SetOrthoMouse(vec3((float)posX, -(float)posY, 0.f));
}
Exemple #25
0
void ccSphere::drawNameIn3D(CC_DRAW_CONTEXT& context)
{
	if (!context._win)
		return;

	//we display it in the 2D layer in fact!
    ccBBox bBox = getBB(true,false,m_currentDisplay);
	if (bBox.isValid())
	{
		const double* MM = context._win->getModelViewMatd(); //viewMat
		const double* MP = context._win->getProjectionMatd(); //projMat
		int VP[4];
		context._win->getViewportArray(VP);

		GLdouble xp,yp,zp;
		CCVector3 C = bBox.getCenter();
		gluProject(C.x,C.y,C.z,MM,MP,VP,&xp,&yp,&zp);

		//we want to display this name next to the sphere, and not above it!
		const ccViewportParameters& params = context._win->getViewportParameters();
		int dPix = (int)ceil(params.zoom * m_radius/params.pixelSize);

		int bkgBorder = QFontMetrics(context._win->getTextDisplayFont()).height()/4+4;
		context._win->displayText(getName(),(int)xp+dPix+bkgBorder,(int)yp,ccGenericGLDisplay::ALIGN_HLEFT | ccGenericGLDisplay::ALIGN_VMIDDLE,75);
	}
}
Exemple #26
0
void
mouse(int button, int state, int x, int y)
{
    GLdouble model[4*4];
    GLdouble proj[4*4];
    GLint view[4];
    
    /* fix for two-button mice -- left mouse + shift = middle mouse */
    if (button == GLUT_LEFT_BUTTON && glutGetModifiers() & GLUT_ACTIVE_SHIFT)
        button = GLUT_MIDDLE_BUTTON;
    
    gltbMouse(button, state, x, y);
    
    mouse_state = state;
    mouse_button = button;
    
    if (state == GLUT_DOWN && button == GLUT_MIDDLE_BUTTON) {
        glGetDoublev(GL_MODELVIEW_MATRIX, model);
        glGetDoublev(GL_PROJECTION_MATRIX, proj);
        glGetIntegerv(GL_VIEWPORT, view);
        gluProject((GLdouble)x, (GLdouble)y, 0.0,
            model, proj, view,
            &pan_x, &pan_y, &pan_z);
        gluUnProject((GLdouble)x, (GLdouble)y, pan_z,
            model, proj, view,
            &pan_x, &pan_y, &pan_z);
        pan_y = -pan_y;
    }
    
    glutPostRedisplay();
}
Exemple #27
0
bool Screen::Project(const vector3d &in, vector3d &out)
{
	GLint o = gluProject(in.x, in.y, in.z, modelMatrix, projMatrix, viewport, &out.x, &out.y, &out.z);
	out.x = out.x * width * invRealWidth;
	out.y = GetHeight() - out.y * height * invRealHeight;
	return (o == GL_TRUE);
}
void NavMeshTesterTool::handleRenderOverlay(double* proj, double* model, int* view)
{
	GLdouble x, y, z;
	
	// Draw start and end point labels
	if (m_sposSet && gluProject((GLdouble)m_spos[0], (GLdouble)m_spos[1], (GLdouble)m_spos[2],
								model, proj, view, &x, &y, &z))
	{
		imguiDrawText((int)x, (int)(y-25), IMGUI_ALIGN_CENTER, "Start", imguiRGBA(0,0,0,220));
	}
	if (m_eposSet && gluProject((GLdouble)m_epos[0], (GLdouble)m_epos[1], (GLdouble)m_epos[2],
								model, proj, view, &x, &y, &z))
	{
		imguiDrawText((int)x, (int)(y-25), IMGUI_ALIGN_CENTER, "End", imguiRGBA(0,0,0,220));
	}
}
void drawDetailOverlay(const dtTileCache* tc, const int tx, const int ty, double* proj, double* model, int* view)
{
    dtCompressedTileRef tiles[MAX_LAYERS];
    const int ntiles = tc->getTilesAt(tx,ty,tiles,MAX_LAYERS);
    if (!ntiles)
        return;

    const int rawSize = calcLayerBufferSize(tc->getParams()->width, tc->getParams()->height);

    char text[128];

    for (int i = 0; i < ntiles; ++i)
    {
        const dtCompressedTile* tile = tc->getTileByRef(tiles[i]);

        float pos[3];
        pos[0] = (tile->header->bmin[0]+tile->header->bmax[0])/2.0f;
        pos[1] = tile->header->bmin[1];
        pos[2] = (tile->header->bmin[2]+tile->header->bmax[2])/2.0f;

        GLdouble x, y, z;
        if (gluProject((GLdouble)pos[0], (GLdouble)pos[1], (GLdouble)pos[2],
                       model, proj, view, &x, &y, &z))
        {
            snprintf(text,128,"(%d,%d)/%d", tile->header->tx,tile->header->ty,tile->header->tlayer);
            imguiDrawText((int)x, (int)y-25, IMGUI_ALIGN_CENTER, text, imguiRGBA(0,0,0,220));
            snprintf(text,128,"Compressed: %.1f kB", tile->dataSize/1024.0f);
            imguiDrawText((int)x, (int)y-45, IMGUI_ALIGN_CENTER, text, imguiRGBA(0,0,0,128));
            snprintf(text,128,"Raw:%.1fkB", rawSize/1024.0f);
            imguiDrawText((int)x, (int)y-65, IMGUI_ALIGN_CENTER, text, imguiRGBA(0,0,0,128));
        }
    }
}
Exemple #30
0
int tiledRenderer_get2DCenter(void * trConf ,
                              unsigned int column, unsigned int row ,
                              float * x2D , float *y2D , float * z2D)
{
      GLint viewport[4];
      GLdouble modelview[16];
      GLdouble projection[16];


      float x3D , y3D , z3D , angleX , angleY , angleZ;
      tiledRenderer_get3DCenterForTile(trConf , column, row ,&x3D , &y3D , &z3D , &angleX , &angleY , &angleZ);
      GLdouble posX = x3D , posY = y3D , posZ = z3D;
      GLdouble winX, winY, winZ=0.0;

      glGetDoublev( GL_MODELVIEW_MATRIX, modelview );
      glGetDoublev( GL_PROJECTION_MATRIX, projection );
      glGetIntegerv( GL_VIEWPORT, viewport );

      gluProject( posX, posY, posZ , modelview, projection, viewport, &winX, &winY, &winZ);

      //fprintf(stderr,"Column/Row %u/%u ( %0.2f,%0.2f,%0.2f ) -> %0.2f %0.2f %0.2f\n",column, x3D , y3D , z3D , row , winX , winY , winZ);

      struct tiledRendererConfiguration * trConfPTR = (struct tiledRendererConfiguration *) trConf;
      *x2D = winX;
      *y2D = winY;
      *z2D = winZ;
      return 0;
}