Skip to content

Commit

Permalink
V1.4.2.2 fix the out of shape when using translate matrix again;
Browse files Browse the repository at this point in the history
  • Loading branch information
ChillingVan committed Aug 22, 2019
1 parent 5b1017a commit 2aa552e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README-en.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ allprojects {
// module build.gradle
dependencies {
implementation 'com.github.ChillingVan:android-openGL-canvas:v1.4.2.1'
implementation 'com.github.ChillingVan:android-openGL-canvas:v1.4.2.2'
}
```

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ allprojects {
// module build.gradle
dependencies {
implementation 'com.github.ChillingVan:android-openGL-canvas:v1.4.2.1'
implementation 'com.github.ChillingVan:android-openGL-canvas:v1.4.2.2'
}
```

Expand Down
4 changes: 2 additions & 2 deletions canvasgl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
group='com.github.ChillingVan'
def VERSION_NAME="1.4.2.1"
def VERSION_NAME="1.4.2.2"

android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
minSdkVersion 14
targetSdkVersion 28
versionCode 104021
versionCode 104022
versionName VERSION_NAME
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,13 @@ public float[] obtainResultMatrix(int viewportW, int viewportH, float x, float y
GLES20Canvas.printMatrix("model rotated:", mModelMatrix, 0);


// Compare to viewport, the real viewport is different
float viewportRatioW = (viewPortRatio*(float)viewportW / realViewportW);
float viewportRatioH = (viewPortRatio*(float)viewportH / realViewportH);
// Translate to the middleZ of the projection
// realW,realH are the w,h in the middleZ of the projection
// the viewport may be not square, so (realViewPortRatio/ratio) is needed
float realW = (ratio * drawW / viewportW * Z_RATIO * 2 / 2) / (realViewPortRatio/ratio);
float realH = drawH / viewportH * Z_RATIO * 2 / 2;
float realW = (ratio * drawW / viewportW * Z_RATIO * 2 / 2) * viewportRatioW;
float realH = (drawH / viewportH * Z_RATIO * 2 / 2) * viewportRatioH;
// Need to make X, Y to the middleZ of the plane, too. The middleZ of the plane is (0, 0, -Z_RATIO + EYEZ)
Matrix.translateM(tempMultiplyMatrix4, 0, mModelMatrix, 0, -realW/2, -realH/2, -Z_RATIO + EYEZ);
GLES20Canvas.printMatrix("model translated:", tempMultiplyMatrix4, 0);
Expand Down
2 changes: 1 addition & 1 deletion canvasglsample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ android {
applicationId "com.chillingvan.canvasglsample"
minSdkVersion 15
targetSdkVersion 28
versionCode 7
versionCode 8
versionName "1.4"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ protected void init() {
protected void onGLDraw(ICanvasGL canvas) {
canvas.drawBitmap(baboon, 0, 0);
drawBitmapTranslate(canvas);
drawBitmapTranslateY(canvas);
drawBitmapTranslateRotate(canvas);
drawBitmapTranslateRotateY(canvas);
drawBitmapTranslateRotateZ(canvas);
Expand All @@ -60,6 +61,12 @@ private void drawBitmapTranslate(ICanvasGL canvas) {
canvas.drawBitmap(baboon, matrix);
}

private void drawBitmapTranslateY(ICanvasGL canvas) {
ICanvasGL.BitmapMatrix matrix = new ICanvasGL.BitmapMatrix();
matrix.translate(0, 1000);
canvas.drawBitmap(baboon, matrix);
}

private void drawBitmapTranslateRotate(ICanvasGL canvas) {
ICanvasGL.BitmapMatrix matrix = new ICanvasGL.BitmapMatrix();
matrix.translate(250, 0);
Expand Down

0 comments on commit 2aa552e

Please sign in to comment.