Bugfix: [#13619] Transform Rotate and Scale Strange

view: noclip version of int and float projection. Also project from behind the view's position and return coherent values for near clipping

transform: use the above functions for 2d center and helpline drawing

NOTE: the result for centers behind the camera (in perspective) isn't 100% perfect in the case of rotations because they always use the centered view vector as rotation axis and not the one aligned with the 2d center. Changing this would not be desirable anyway. At least it's predictible now.
This commit is contained in:
Martin Poirier 2008-06-05 14:49:12 +00:00
parent 6757b759ea
commit 172fe6ed2f
3 changed files with 70 additions and 24 deletions

@ -63,7 +63,9 @@ void window_to_3d(float *vec, short mx, short my);
void project_short(float *vec, short *adr);
void project_short_noclip(float *vec, short *adr);
void project_int(float *vec, int *adr);
void project_int_noclip(float *vec, int *adr);
void project_float(float *vec, float *adr);
void project_float_noclip(float *vec, float *adr);
int boundbox_clip(float obmat[][4], struct BoundBox *bb);
void fdrawline(float x1, float y1, float x2, float y2);

@ -135,24 +135,23 @@ static void helpline(TransInfo *t, float *vec)
getmouseco_areawin(mval);
projectFloatView(t, vecrot, cent); // no overflow in extreme cases
if(cent[0]!=IS_CLIPPED) {
persp(PERSP_WIN);
glDrawBuffer(GL_FRONT);
BIF_ThemeColor(TH_WIRE);
setlinestyle(3);
glBegin(GL_LINE_STRIP);
glVertex2sv(mval);
glVertex2fv(cent);
glEnd();
setlinestyle(0);
persp(PERSP_VIEW);
bglFlush(); // flush display for frontbuffer
glDrawBuffer(GL_BACK);
}
persp(PERSP_WIN);
glDrawBuffer(GL_FRONT);
BIF_ThemeColor(TH_WIRE);
setlinestyle(3);
glBegin(GL_LINE_STRIP);
glVertex2sv(mval);
glVertex2fv(cent);
glEnd();
setlinestyle(0);
persp(PERSP_VIEW);
bglFlush(); // flush display for frontbuffer
glDrawBuffer(GL_BACK);
}
@ -354,8 +353,9 @@ void convertViewVec(TransInfo *t, float *vec, short dx, short dy)
void projectIntView(TransInfo *t, float *vec, int *adr)
{
if (t->spacetype==SPACE_VIEW3D)
project_int(vec, adr);
if (t->spacetype==SPACE_VIEW3D) {
project_int_noclip(vec, adr);
}
else if(t->spacetype==SPACE_IMAGE) {
float aspx, aspy, v[2];
@ -376,8 +376,9 @@ void projectIntView(TransInfo *t, float *vec, int *adr)
void projectFloatView(TransInfo *t, float *vec, float *adr)
{
if (t->spacetype==SPACE_VIEW3D)
project_float(vec, adr);
if (t->spacetype==SPACE_VIEW3D) {
project_float_noclip(vec, adr);
}
else if(t->spacetype==SPACE_IMAGE) {
int a[2];

@ -228,6 +228,29 @@ void project_int(float *vec, int *adr)
}
}
void project_int_noclip(float *vec, int *adr)
{
float fx, fy, vec4[4];
VECCOPY(vec4, vec);
vec4[3]= 1.0;
Mat4MulVec4fl(G.vd->persmat, vec4);
if( fabs(vec4[3]) > BL_NEAR_CLIP ) {
fx = (curarea->winx/2)*(1 + vec4[0]/vec4[3]);
fy = (curarea->winy/2)*(1 + vec4[1]/vec4[3]);
adr[0] = floor(fx);
adr[1] = floor(fy);
}
else
{
adr[0] = curarea->winx / 2;
adr[1] = curarea->winy / 2;
}
}
void project_short_noclip(float *vec, short *adr)
{
float fx, fy, vec4[4];
@ -264,8 +287,28 @@ void project_float(float *vec, float *adr)
Mat4MulVec4fl(G.vd->persmat, vec4);
if( vec4[3]>BL_NEAR_CLIP ) {
adr[0]= (curarea->winx/2.0)+(curarea->winx/2.0)*vec4[0]/vec4[3];
adr[1]= (curarea->winy/2.0)+(curarea->winy/2.0)*vec4[1]/vec4[3];
adr[0] = (curarea->winx/2.0)+(curarea->winx/2.0)*vec4[0]/vec4[3];
adr[1] = (curarea->winy/2.0)+(curarea->winy/2.0)*vec4[1]/vec4[3];
}
}
void project_float_noclip(float *vec, float *adr)
{
float vec4[4];
VECCOPY(vec4, vec);
vec4[3]= 1.0;
Mat4MulVec4fl(G.vd->persmat, vec4);
if( fabs(vec4[3]) > BL_NEAR_CLIP ) {
adr[0] = (curarea->winx/2.0)+(curarea->winx/2.0)*vec4[0]/vec4[3];
adr[1] = (curarea->winy/2.0)+(curarea->winy/2.0)*vec4[1]/vec4[3];
}
else
{
adr[0] = curarea->winx / 2.0f;
adr[1] = curarea->winy / 2.0f;
}
}