0

私のアプリケーションはベクター描画アプリケーションです。OpenGL で動作します。代わりに Cairo 2D グラフィックス ライブラリを使用するように変更します。問題はズームです。openGL カメラとスケール ファクターを使用すると、次のような作業が行われます。

 float scalediv = Current_Scene().camera.ScaleFactor / 2.0f;
 float cameraX = GetCameraX();
 float cameraY = GetCameraY();
 glMatrixMode(GL_PROJECTION);
 glLoadIdentity();

 float left = cameraX - ((float)controls.MainGlFrame.Dimensions.x) * scalediv;
 float right = cameraX + ((float)controls.MainGlFrame.Dimensions.x) * scalediv;
 float bottom = cameraY - ((float)controls.MainGlFrame.Dimensions.y) * scalediv;
 float top = cameraY + ((float)controls.MainGlFrame.Dimensions.y) * scalediv;

 glOrtho(left,
  right,
  bottom, 
  top,
  -0.01f,0.01f);

 // Set the model matrix as the current matrix
 glMatrixMode(GL_MODELVIEW);
 glLoadIdentity();

 hdc = BeginPaint(controls.MainGlContext.mhWnd,&ps);

マウスの位置は次のように取得されます。

 POINT _mouse = controls.MainGlFrame.GetMousePos();
vector2f mouse = functions.ScreenToWorld(_mouse.x,_mouse.y,GetCameraX(),GetCameraY(),
             Current_Scene().camera.ScaleFactor,
            controls.MainGlFrame.Dimensions.x,
            controls.MainGlFrame.Dimensions.y );

vector2f CGlEngineFunctions::ScreenToWorld(int x, int y, float camx, float camy, float scale, int width, int height)
{
 // Move the given point to the origin, multiply by the zoom factor and
 // add the model coordinates of the center point (camera position)
 vector2f p;


 p.x =  (float)(x - width / 2.0f) * scale +
  camx;

 p.y = -(float)(y - height / 2.0f) * scale +
  camy;

 return p;
}

そこから三角形の VBO を描きます。これにより、パンとズームインが可能になります。Cairo は座標に基づいてしか描画できないため、変換を使用せずに頂点が適切にスケーリングおよびパンされるようにするにはどうすればよいでしょうか。基本的に GlOrtho は通常ビューポートを設定しますが、Cairo でこれを行うことはできないと思います。

GlOrtho は頂点を変更する代わりにビューポート マトリックスを変更できますが、同じ結果を得るために頂点を変更するにはどうすればよいでしょうか?

ありがとう

*ScreenToWorld から取得された頂点 P が与えられた場合、カメラと倍率に従ってスケーリングおよびパンされるように変更するにはどうすればよいでしょうか? 通常、OpenGL は本質的にこれを行うため

4

1 に答える 1

0

カイロはあなたが望むことをできると思います... http://cairographics.org/matrix_transform/を参照してください。それはあなたの問題を解決しますか? そうでない場合は、その理由は?

于 2010-08-28T02:16:27.770 に答える