Example #1
0
bool DisplayWindow::pick(int x, int y)
{
	GLuint selbuf[1024];
	glSelectBuffer(1024, selbuf);

	SetupView(TRUE,x,y);

	glRenderMode(GL_SELECT);
	render();

	SetupView(FALSE,0,0);
	GLuint hits = glRenderMode(GL_RENDER);
	if (hits > 1000000) hits = 0;
	/* selbuf now contains a number of records (= hits) of the form:
	 * ... 3 znear zfar ps-index particles-index particle-index ...
	 *
	 * need to find the nearest and select it
	 */

	GLuint closest = 0;
	int picked_ps = -1;
	int picked_p = -1;
	int picked_particle = -1;
	for (unsigned int i = 0; i < hits; i++) {
		if (selbuf[6*i + 1] < closest || i == 0) {
			closest = selbuf[6*i + 1];
			picked_ps = selbuf[6*i + 3];
			picked_p = selbuf[6*i + 4];
			picked_particle = selbuf[6*i + 5];
		}
	}

	selected_p = 0;
	selected_particle = -1;

	/* this keeps an empty pick() from resetting the current selection */
	if (!hits) return false;

	ParticleSystems *ps = &(wxGetApp().particlesystems);
	for (unsigned int j = 0; j < ps->size(); j++) {
		for (unsigned int i = 0; i < (*ps)[j]->particles.size(); i++) {
			if (j == picked_ps && i == picked_p) {
				(*ps)[j]->particles[i]->selectedParticle = picked_particle;
				selected_p = (*ps)[j]->particles[i];
				selected_particle = picked_particle;
			} else {
				(*ps)[j]->particles[i]->selectedParticle = -1;
			}
		}
	}
	return true;
}
Example #2
0
void Camera::SetProjTransform( F32 n, F32 f, F32 fv)
{
  if (f <= n)
  {
    f = n + 1.0f;
  }
  isIso = FALSE;

  nearPlane = n;
	farPlane  = f;
	fov		    = fv;
  maxZ      = farPlane * zoom - nearPlane;

	Vid::SetTranBucketMaxZ( farPlane * zoom);
	Vid::SetTranBucketMinZ(0.0f);
  Vid::SetTranMaxBucketCount( TRANMAXBUCKETCOUNT);

  halfHeight = ((F32) rect.Height()) * 0.5f;
  halfWidth  = ((F32) rect.Width())  * 0.5f;
  aspectHW   = halfHeight / halfWidth;

  projMatrix.SetProjection( nearPlane, farPlane * zoom, fov / zoom, aspectHW);

  viewMatrix.Transform( tranMatrix, projMatrix);

  SetupMatrix();
  SetupView();
}
Example #3
0
status_t NotificationView::Load(void) {
	status_t err = LoadAppUsage();
	if (err != B_OK) return err;

	const char *app = "";
	if (fCurrentAppMenu) app = fCurrentAppMenu->Label();
	
	int32 items = fAppMenu->CountItems();
	for (int32 i = 0; i < items; i++) delete fAppMenu->RemoveItem(0L);
		
	appusage_t::iterator aIt;
	for (aIt = fAppUsage.begin(); aIt != fAppUsage.end(); aIt++) {
		fAppMenu->AddItem(new BMenuItem(aIt->first.String(), new BMessage(kAppChanged)));
	};

	fCurrentAppMenu = fAppMenu->FindItem(app);
	if (fCurrentAppMenu == NULL) fCurrentAppMenu = fAppMenu->ItemAt(0);	
	fCurrentAppMenu->SetMarked(true);
	
	fAppMenu->SetTargetForItems(this);
	
	fAppMenu->ResizeToPreferred();
	fAppField->ResizeToPreferred();
	
	SetupView(fCurrentAppMenu);
};
Example #4
0
void Camera::Setup( const Area<S32> & r)
{
  // save the last for clear borders
  //
  if (clearCount == 0)
  {
    last = r;
  }
  rect = r;
  clearCount = 3;

  x0 = (F32) rect.p0.x / (F32) Vid::viewRect.Width();
  x1 = (F32) rect.p1.x / (F32) Vid::viewRect.Width();
  y0 = (F32) rect.p0.y / (F32) Vid::viewRect.Height();
  y1 = (F32) rect.p1.y / (F32) Vid::viewRect.Height();

  SetupView();

#ifdef DOOCCULSION
  if (Occlusion)
  {
	  Occlusion->Setup ();
  }
#endif
}
Example #5
0
void Camera::SetProjTransformIso( F32 n, F32 f, F32 fv, F32 w, F32 h)
{
  if (f <= n)
  {
    f = n + 1.0f;
  }
  isIso = TRUE;

  nearPlane = n;
	farPlane  = f;
	fov		    = fv;
  maxZ      = farPlane * zoom - nearPlane;

  fv *= 0.5f;
	F32 s = (F32) sin(fv);
	F32 qv = s * f / (f - n);
	  
  // set up the isometric projection matrix
	projMatrix.Zero();
  projMatrix.right.x = 2.0f / h;
	projMatrix.up.y    = 2.0f / w;
	projMatrix.front.z = 1.0f;
//	projMatrix.frontw = 1.0f;
	projMatrix.posit.z = -qv * n;
	projMatrix.positw = 1.0f;

  halfHeight = ((F32) rect.Height()) * 0.5f;
  halfWidth  = ((F32) rect.Width())  * 0.5f;
  aspectHW   = halfHeight / halfWidth;

  viewMatrix.Transform( tranMatrix, projMatrix);

  SetupMatrix();
  SetupView();
}
void CWindowClient::OnDrawWindow()
{
    SetupView(GetWindow().GetWindowSize());

    // Активной будет первая программа из очереди.
    m_programQueue.front()->Use();
    m_quadObj.Draw();
}
Example #7
0
TouchpadPrefView::TouchpadPrefView()
	:
	BGroupView()
{
	SetupView();
	// set view values
	SetValues(&fTouchpadPref.Settings());
}
Example #8
0
void Camera::OnModeChange()
{
  rect.p0.x = (S32) (x0 * (F32) Vid::viewRect.Width());
  rect.p1.x = (S32) (x1 * (F32) Vid::viewRect.Width());
  rect.p0.y = (S32) (y0 * (F32) Vid::viewRect.Height());
  rect.p1.y = (S32) (y1 * (F32) Vid::viewRect.Height());   

  SetupView();
}
Example #9
0
void DisplayWindow::resize()
{
    // set GL viewport (not called by wxGLCanvas::OnSize on all platforms...)
    int w, h;
    GetClientSize(&w, &h);
    if (!GetContext()) return;
	SetCurrent();
    glViewport(0, 0, (GLint) w, (GLint) h);
	SetupView(FALSE,0,0);
}
Example #10
0
/*!****************************************************************************
 @Function		InitView
 @Return		bool		true if no error occurred
 @Description	Code in InitView() will be called by PVRShell upon
				initialization or after a change in the rendering context.
				Used to initialize variables that are dependant on the rendering
				context (e.g. textures, vertex buffers, etc.)
******************************************************************************/
bool OGLES3EdgeDetection::InitView()
{
	// Store width and height of the viewport.
	m_i32TexWidth = PVRShellGet(prefWidth);
	m_i32TexHeight = PVRShellGet(prefHeight);

	/*	Get the current frame buffer object. As the program hasn't set it yet, this is the default buffer.
		On most platforms this just gives 0, but there are exceptions.	*/
	glGetIntegerv(GL_FRAMEBUFFER_BINDING, &m_i32OriginalFramebuffer);

	// Create string for error codes.
	CPVRTString ErrorStr;

	// Checks to see if the screen is rotated or not.
    bool bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen);

	// Initialize VBO data
	if(!LoadVbos(&ErrorStr))
	{
		PVRShellSet(prefExitMessage, ErrorStr.c_str());
		return false;
	}

	// Initialise Print3D
	if(m_Print3D.SetTextures(0,m_i32TexWidth,m_i32TexHeight,bRotate) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, "ERROR: Cannot initialise Print3D\n");
		return false;
	}

	// Load external textures and create internal ones.
	if(!LoadTextures(&ErrorStr))
	{
		PVRShellSet(prefExitMessage, ErrorStr.c_str());
		return false;
	}

	// Load and compile the shaders & link programs
	if (!LoadShaders(&ErrorStr))
	{
		PVRShellSet(prefExitMessage, ErrorStr.c_str());
		return false;
	}

	// Creates and checks FBO creation
	if (!CreateFBO(&ErrorStr))
	{
		PVRShellSet(prefExitMessage, ErrorStr.c_str());
		return false;
	}

	SetupView(bRotate);

	return true;
}
void
D3DOverdrawWindow::
SetupDraw(int iViewpoint)
{
    SetupViewport();
    SetupWorld();
    SetupView(iViewpoint);
    SetupProjection();
    SetupTransforms();
    SetupUniforms();
    Clear();
}
Example #12
0
PreviewWindow::PreviewWindow(QWidget *parent)
    :
    QDockWidget(tr("Preview"), parent),
    m_MainWidget(*new QWidget(this)),
    m_Layout(*new QVBoxLayout(&m_MainWidget)),
    m_Preview(new BookViewPreview(this)),
    m_Inspector(new QWebInspector(this)),
    m_Splitter(new QSplitter(this)),
    m_StackedViews(new QStackedWidget(this))
{
    SetupView();
    LoadSettings();
    ConnectSignalsToSlots();
}
Example #13
0
void CWindow::OnDrawWindow(const glm::ivec2 &size)
{
    SetupView(size);

    // Смещаем анимированный единичный куб в другую сторону
    glPushMatrix();
    glTranslatef(-1.5f, 0, 0);
    m_dynamicCube.Draw();
    glPopMatrix();

    // Смещаем статический единичный куб в другую сторону
    glPushMatrix();
    glTranslatef(1.5f, 0, 0);
    m_staticCube.Draw();
    glPopMatrix();
}
Example #14
0
void View2::DrawView()
{
	CKEGIESDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	glPushMatrix();
	UpdateView();
	SetupView();

	//drawAxis(true, &m_Cam1);
	pDoc->m_doc->draw2(m_displayMode);

	glPopMatrix();
	glPopAttrib();
}
Example #15
0
void NotificationView::MessageReceived(BMessage *msg) {
	switch (msg->what) {
		case kAppChanged: {
			int32 index = -1;
			if (msg->FindInt32("index", &index) != B_OK) return;
			
			fCurrentAppMenu = fAppMenu->ItemAt(index);
			
			fAppMenu->ResizeToPreferred();
			fAppField->ResizeToPreferred();
			
			SetupView(fCurrentAppMenu);
		} break;
		
		default: {
			BView::MessageReceived(msg);
		};
	};
};
Example #16
0
void View2::DrawView()
{
	CKEGIESDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc){
		return;
	}

	glPushMatrix();
		UpdateView();	// Set up camera 
		SetupView();	// Set up lighting 

		if (skeletonDisplayMode[SHOW_AXIS]){
			drawAxis(true, &m_Cam1);
		}
		pDoc->document.draw2(skeletonDisplayMode);
	glPopMatrix();

	glPopAttrib();
}
Example #17
0
LRESULT MainFrame::OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
   SetupCmdBar();
   SetupRibbonBar();
   SetupToolbar();
   SetupMRUList();
   SetupStatusBar();
   SetupView();

   // register object for message filtering and idle updates
   CMessageLoop* pLoop = _Module.GetMessageLoop();
   ATLASSERT(pLoop != NULL);
   pLoop->AddMessageFilter(this);
   pLoop->AddIdleHandler(this);

   {
      bool bRibbonUI = RunTimeHelper::IsRibbonUIAvailable();
      ShowRibbonUI(bRibbonUI);
      UISetCheck(ID_VIEW_RIBBON, bRibbonUI);
   }

   if (m_cszFilenameOpenAtStart.IsEmpty())
      DoFileNew();
   else
   {
      CString cszTitle = Path(m_cszFilenameOpenAtStart).FilenameAndExt();
      if (DoFileOpen(m_cszFilenameOpenAtStart, cszTitle))
      {
         m_mru.AddToList(m_cszFilenameOpenAtStart);
         m_mru.WriteToRegistry(c_pszSettingsRegkey);
      }
   }

   UIEnable(ID_SCRIPT_RUN, true);
   UIEnable(ID_SCRIPT_STOP, false);

   return 0;
}
Example #18
0
void Camera::SetZoom( F32 z)
{
  if (isIso)
  {
    return;     // FIXME
  }

  halfHeight = ((F32) rect.Height()) * 0.5f;
  halfWidth  = ((F32) rect.Width())  * 0.5f;
  aspectHW   = halfHeight / halfWidth;

  zoom = z;
  projMatrix.SetProjection( nearPlane, farPlane * zoom, fov / zoom, aspectHW);

	Vid::SetTranBucketMaxZ( farPlane * zoom);
	Vid::SetTranBucketMinZ(0.0f);
  Vid::SetTranMaxBucketCount( TRANMAXBUCKETCOUNT);

  maxZ = farPlane * zoom - nearPlane;

  SetupMatrix();
  SetupView();
}
Example #19
0
void CGUIDialogSettingsBase::OnInitWindow()
{
  m_confirmed = false;
  SetupView();
  CGUIDialog::OnInitWindow();
}
Example #20
0
void DisplayWindow::OnMouseEvent(wxMouseEvent& event)
{
	static int rot_dragging = 0;
	static int particle_dragging = 0;
	static float last_x, last_y;

	//printf("%f %f %d\n", event.GetX(), event.GetY(), (int)event.LeftIsDown());
	if (event.GetWheelRotation() != 0) {
		zoom += event.GetWheelRotation() / 300.0f;
		SetupView(FALSE,0,0);
		Refresh(TRUE);
	}
	if (event.MiddleIsDown())
	{
		zoom += (event.GetY() - last_y)/100;
		SetupView(FALSE,0,0);
		Refresh(TRUE);
	}
	else if(event.LeftIsDown()) {
		SetFocus();

		if (rot_dragging) {
			xrot += (event.GetY() - last_y)*1.0;
			yrot += (event.GetX() - last_x)*1.0;
			SetupView(FALSE,0,0);
			Refresh(TRUE);
		} else if (particle_dragging) {
			if (!selected_p || selected_particle == -1) {
				particle_dragging = 0;
				return;
			}

			float dx = event.GetX() - last_x;
			float dy = last_y - event.GetY();
			//pick(event.GetX(),event.GetY());

			GLdouble modelview[16];
			GLdouble projection[16];
			GLint viewport[4];
			glGetDoublev(GL_MODELVIEW_MATRIX,modelview);
			glGetDoublev(GL_PROJECTION_MATRIX,projection);
			glGetIntegerv(GL_VIEWPORT,viewport);

//			ParticlePosition *posattr = selected_p->getAttribute<ParticlePosition>(std::string("ParticlePosition"));
			ParticlePosition *posattr;
			if (selected_p->findAttribute(posattr)) {
				gmVector3 pos = posattr->getPosition(selected_particle);

				GLdouble objx = pos[0], objy = pos[1], objz = pos[2];
				GLdouble winx,winy,winz;

				gluProject(objx,objy,objz,
							modelview,projection,viewport,
							&winx,&winy,&winz);

				winx += dx;
				winy += dy;

				gluUnProject(winx,winy,winz,
							modelview,projection,viewport,
							&objx,&objy,&objz);

				pos.assign(objx,objy,objz);
				posattr->setPosition(selected_particle, pos);
				//[tk 6.01.05] added this code to try to update the particle positions when I move a particle
				//[tk 6.01.05] seems to have done the trick - now particles moved with the mouse tell their ParticlePosition attribute that they have been updated
				// This is useful for RBF control particles.  I don't know why the regular Witkin-Heckbert control particles didn't require this kind of feedback.  Perhaps they are
				// updated like this at every frame regardless of movement.
				// It might be better to implement this the same way as the regular Witkin-Heckbert control particles - to update RBF centers the same way, I will have to find out how they are actually
				// implemented.
				posattr->changed = true;
			}

		} else {
			if (pick(event.GetX(),event.GetY()))
				particle_dragging = 1;
			else
				rot_dragging = 1;
		}
	} else if (event.LeftUp() && rot_dragging) {
		// clicked on a non-particle, clear selection
		rot_dragging = 0;
		selected_p = 0;
		selected_particle = -1;

		ParticleSystems *ps = &(wxGetApp().particlesystems);
		for (unsigned int j = 0; j < ps->size(); j++) {
			for (unsigned int i = 0; i < (*ps)[j]->particles.size(); i++) {
				(*ps)[j]->particles[i]->selectedParticle = -1;
			}
		}

	} else {
		rot_dragging = 0;
		particle_dragging = 0;
	}

	int e = 0;
	if (event.LeftDown()) {
		e = WB_CLICK;
	} else if (event.LeftDClick()) {
		e = WB_DOUBLECLICK;
	} else if (event.LeftUp()) {
		e = WB_DRAG;
	} else if (event.RightDown()) {
		e = WB_RIGHTCLICK;
	}
	if (event.ShiftDown()) e |= WB_SHIFT;
	if (event.ControlDown()) e |= WB_CTRL;
	if (event.AltDown()) e |= WB_ALT;

	ParticleSystems *ps = &(wxGetApp().particlesystems);

	if(wxGetApp().logWindow){
		(wxGetApp().mainframe)->cerrbuforig = std::cerr.rdbuf();
		std::cerr.rdbuf((wxGetApp().logWindow)->logTxtControl);
		(wxGetApp().mainframe)->coutbuforig = std::cout.rdbuf();
		std::cout.rdbuf((wxGetApp().logWindow)->logTxtControl);
	}

	for (unsigned int j = 0; j < ps->size(); j++){
		//pass the Euler angles and the zoom factor
		(*ps)[j]->setEulerAnglesAndZoom(xrot,yrot,zoom);
		for(unsigned int i = 0; i < (*ps)[j]->particles.size(); i++)
			(*ps)[j]->particles[i]->event(e);
	}

	if(wxGetApp().logWindow){
		std::cerr.rdbuf((wxGetApp().mainframe)->cerrbuforig);
		std::cout.rdbuf((wxGetApp().mainframe)->coutbuforig);
	}
	
	//update to new position
	last_x = event.GetX();
	last_y = event.GetY();

}
int
D3DOverdrawWindow::
Loop(int iClusterA, int iClusterB)
{
    int nOverdraw = 0;
    DWORD numberOfPixelsDrawn;
    int j = 0;
    SetupDraw(0);

    for (unsigned int iViewpoint = 0; iViewpoint < m_nViewpointCount; iViewpoint++)
    {
        SetupView(iViewpoint);
        m_iTested++;

        if (!CheckIsect(iClusterA, iClusterB))
        {
            continue;
        }

        m_iRendered++;
        SetupTransforms();
        d3d->Clear(0, NULL,  D3DCLEAR_ZBUFFER,
                   D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

        //Add this to remove triple dependencies
        //DrawComplement(iClusterA, iClusterB);

        // Add an end marker to the command buffer queue.
        m_pOcclusionQuery[j]->Issue(D3DISSUE_BEGIN);
        // Draw scene
        DrawCluster(iClusterA);
        DrawCluster(iClusterB);
        // Add an end marker to the command buffer queue.
        m_pOcclusionQuery[j]->Issue(D3DISSUE_END);
        // Force the driver to execute the commands from the command buffer.
        // Empty the command buffer and wait until the GPU is idle.
        j++;

        if (j == NUM_QUERIES)
        {
            for (j = 0; j < NUM_QUERIES; j++)
            {
                while (S_FALSE == m_pOcclusionQuery[j]->GetData(&numberOfPixelsDrawn,
                                                                sizeof(DWORD), D3DGETDATA_FLUSH))
                    ;

                nOverdraw += numberOfPixelsDrawn;
            }

            j = 0;
        }
    }

    int jnum = j;

    for (int j = 0; j < jnum; j++)
    {
        while (S_FALSE == m_pOcclusionQuery[j]->GetData(&numberOfPixelsDrawn,
                                                        sizeof(DWORD), D3DGETDATA_FLUSH))
            ;

        nOverdraw += numberOfPixelsDrawn;
    }

    return nOverdraw;
}
bool
D3DOverdrawWindow::
NormalizedLoop(float& fOverdraw, float& fOverdrawMax)
{
    int nOverdraw = 0;
    int nOverdrawPix = 0;
    fOverdrawMax = 0;
    DWORD numberOfPixelsDrawn;
    DWORD numberOfPixelsDrawnPix;
    SetupDraw(0);

    for (unsigned int iViewpoint = 0; iViewpoint < m_nViewpointCount; iViewpoint += NUM_QUERIES)
    {
        for (unsigned int j = 0; j < NUM_QUERIES && iViewpoint + j < m_nViewpointCount; j++)
        {
            SetupView(iViewpoint + j);
            SetupTransforms();
            d3d->Clear(0, NULL,  D3DCLEAR_ZBUFFER,
                       D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
            // Add an end marker to the command buffer queue.
            m_pOcclusionQuery[j]->Issue(D3DISSUE_BEGIN);

            // Draw scene
            if (FAILED(DrawModel()))
            {
                return false;
            }

            // Add an end marker to the command buffer queue.
            m_pOcclusionQuery[j]->Issue(D3DISSUE_END);

            // Add an end marker to the command buffer queue.
            d3d->SetRenderState(D3DRS_ZFUNC, D3DCMP_EQUAL);
            m_pOcclusionQueryPix[j]->Issue(D3DISSUE_BEGIN);

            // Draw scene
            if (FAILED(DrawModel()))
            {
                return false;
            }

            // Add an end marker to the command buffer queue.
            m_pOcclusionQueryPix[j]->Issue(D3DISSUE_END);
            d3d->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESS);
        }

        for (unsigned int j = 0; j < NUM_QUERIES && iViewpoint + j < m_nViewpointCount; j++)
        {
            // Force the driver to execute the commands from the command buffer.
            // Empty the command buffer and wait until the GPU is idle.
            while (S_FALSE == m_pOcclusionQuery[j]->GetData(&numberOfPixelsDrawn,
                                                            sizeof(DWORD), D3DGETDATA_FLUSH))
                ;

            nOverdraw += numberOfPixelsDrawn;

            while (S_FALSE == m_pOcclusionQueryPix[j]->GetData(&numberOfPixelsDrawnPix,
                                                               sizeof(DWORD), D3DGETDATA_FLUSH))
                ;

            nOverdrawPix += numberOfPixelsDrawnPix;

            if (numberOfPixelsDrawnPix > 0)
            {
                fOverdrawMax = max(fOverdrawMax, numberOfPixelsDrawn / (float)numberOfPixelsDrawnPix);
            }
        }
    }

    if (nOverdrawPix > 0)
    {
        fOverdraw = nOverdraw / (float)nOverdrawPix;
    }
    else
    {
        fOverdraw = 0;
    }

    return true;
}