Skip to content

Commit

Permalink
Add Text hotspot support
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin20150405 committed Apr 6, 2017
1 parent f7910ad commit bd35f2e
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.en.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Pano360
[![Build Status](https://travis-ci.org/Martin20150405/Pano360.svg?branch=master)](https://travis-ci.org/Martin20150405/Pano360) [![license](https://img.shields.io/github/license/mashape/apistatus.svg)](LECENSE) ![progress](http://progressed.io/bar/60?title=Progress)
[![Build Status](https://travis-ci.org/Martin20150405/Pano360.svg?branch=master)](https://travis-ci.org/Martin20150405/Pano360) [![license](https://img.shields.io/github/license/mashape/apistatus.svg)](LECENSE) ![progress](http://progressed.io/bar/61?title=Progress)

Pure Java library to play 360 degree panorama video (VR video) on Android. Using OpenGL ES 2.0

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Pano360
[![Build Status](https://travis-ci.org/Martin20150405/Pano360.svg?branch=master)](https://travis-ci.org/Martin20150405/Pano360) [![license](https://img.shields.io/github/license/mashape/apistatus.svg)](LECENSE) ![progress](http://progressed.io/bar/60?title=Progress)
[![Build Status](https://travis-ci.org/Martin20150405/Pano360.svg?branch=master)](https://travis-ci.org/Martin20150405/Pano360) [![license](https://img.shields.io/github/license/mashape/apistatus.svg)](LECENSE) ![progress](http://progressed.io/bar/61?title=Progress)

Pure Java library to play 360 degree panorama video (VR video) on Android. Using OpenGL ES 2.0

Expand Down
Binary file modified app/app-release.apk
Binary file not shown.
Binary file added panolibrary/src/main/assets/fonts/font_26.ttf
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.content.Context;
import android.opengl.GLES20;

import com.example.panolibrary.R;
import com.martin.ads.vrlib.filters.base.AbsFilter;
import com.martin.ads.vrlib.object.Plain;
import com.martin.ads.vrlib.programs.GLTwoInputProgram;
Expand Down Expand Up @@ -56,7 +55,7 @@ public void init() {

mMixLocation = GLES20.glGetUniformLocation(twoInputProgram.getProgramId(), "mixturePercent");

bitmapTexture.load(context,"filter/imgs/texture_360_n.jpg");
bitmapTexture.loadWithFile(context,"filter/imgs/texture_360_n.jpg");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public DrawImageFilter(Context context, String imagePath,int adjustingMode) {
@Override
public void init() {
super.init();
bitmapTexture.load(context,imagePath);
bitmapTexture.loadWithFile(context,imagePath);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package com.martin.ads.vrlib.filters.vr;

import android.content.Context;
import android.graphics.Bitmap;
import android.opengl.GLES20;
import android.opengl.Matrix;
import android.util.Log;

import com.martin.ads.vrlib.constant.AdjustingMode;
import com.martin.ads.vrlib.filters.base.AbsFilter;
import com.martin.ads.vrlib.math.PositionOrientation;
import com.martin.ads.vrlib.object.Plain;
import com.martin.ads.vrlib.programs.GLPassThroughProgram;
import com.martin.ads.vrlib.textures.BitmapTexture;
import com.martin.ads.vrlib.utils.MatrixUtils;
import com.martin.ads.vrlib.utils.TextureUtils;

/**
Expand All @@ -23,26 +25,40 @@ public class HotSpot extends AbsFilter{

private float[] hotSpotModelMatrix = new float[16];
private float[] tmpMatrix = new float[16];
private float[] resultMatrix = new float[16];
private float[] modelMatrix = new float[16];
private float[] viewMatrix = new float[16];
private float[] projectionMatrix = new float[16];
private float[] hotspotOrthoProjectionMatrix = new float[16];
private float[] modelViewMatrix = new float[16];
private float[] mMVPMatrix = new float[16];

private BitmapTexture bitmapTexture;
private String imagePath;
private Bitmap bitmap;
private PositionOrientation positionOrientation;

private HotSpot(Context context) {
this.context = context;
bitmapTexture=new BitmapTexture();
imagePlain=new Plain(false).scale(4.5f);
glPassThroughProgram=new GLPassThroughProgram(context);
Matrix.setIdentityM(hotspotOrthoProjectionMatrix,0);
}

public void init(){
glPassThroughProgram.create();
bitmapTexture.load(context,imagePath);
if(imagePath!=null)
bitmapTexture.loadWithFile(context,imagePath);
else bitmapTexture.loadBitmap(bitmap);
int minSize=Math.min(bitmapTexture.getImageWidth(),bitmapTexture.getImageHeight());
MatrixUtils.updateProjection(
bitmapTexture.getImageWidth(),
bitmapTexture.getImageHeight(),
minSize,
minSize,
AdjustingMode.ADJUSTING_MODE_FIT_TO_SCREEN,
hotspotOrthoProjectionMatrix);
}

@Override
Expand All @@ -60,7 +76,8 @@ public void onDrawFrame(int textureId) {
imagePlain.uploadVerticesBuffer(glPassThroughProgram.getPositionHandle());

positionOrientation.updateModelMatrix(hotSpotModelMatrix);
Matrix.multiplyMM(tmpMatrix, 0,modelMatrix , 0,hotSpotModelMatrix , 0);
Matrix.multiplyMM(resultMatrix,0,hotSpotModelMatrix,0,hotspotOrthoProjectionMatrix,0);
Matrix.multiplyMM(tmpMatrix, 0,modelMatrix , 0,resultMatrix , 0);
Matrix.multiplyMM(modelViewMatrix, 0, viewMatrix, 0, tmpMatrix, 0);
Matrix.multiplyMM(mMVPMatrix, 0, projectionMatrix, 0, modelViewMatrix, 0);

Expand All @@ -69,11 +86,21 @@ public void onDrawFrame(int textureId) {
GLES20.glDisable(GLES20.GL_BLEND);
}

/**
* if you have set imagePath, the bitmap will not be used.
* @param imagePath
* @return
*/
public HotSpot setImagePath(String imagePath) {
this.imagePath = imagePath;
return this;
}

public HotSpot setBitmap(Bitmap bitmap) {
this.bitmap = bitmap;
return this;
}

public HotSpot setPositionOrientation(PositionOrientation positionOrientation) {
this.positionOrientation = positionOrientation;
return this;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.martin.ads.vrlib.filters.vr;

import android.graphics.Color;
import android.graphics.Typeface;
import android.opengl.GLES20;
import android.opengl.Matrix;

Expand All @@ -11,6 +13,7 @@
import com.martin.ads.vrlib.programs.GLPassThroughProgram;
import com.martin.ads.vrlib.utils.OrientationHelper;
import com.martin.ads.vrlib.utils.StatusHelper;
import com.martin.ads.vrlib.utils.TextImageGenerator;
import com.martin.ads.vrlib.utils.TextureUtils;

import java.util.ArrayList;
Expand Down Expand Up @@ -90,6 +93,24 @@ public void updateSensorMatrix(float[] sensorMatrix) {
)
.setImagePath("imgs/hotspot_logo.png")
);

hotSpotList.add(HotSpot.with(statusHelper.getContext())
.setPositionOrientation(
PositionOrientation.newInstance()
.setY(15).setAngleX(90).setAngleY(-90)
)
.setBitmap( TextImageGenerator.newInstance()
.setPadding(25)
.setTextColor(Color.parseColor("#FFCE54"))
.setBackgroundColor(Color.parseColor("#22000000"))
.setTypeface(Typeface.createFromAsset(
statusHelper.getContext().getAssets(),
"fonts/font_26.ttf")
)
.setTextSize(55)
.addTextToImage("I'm a text hotspot~")
)
);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public BitmapTexture() {
imageSize=new int[2];
}

public BitmapTexture load(Context context,String filePath){
public BitmapTexture loadWithFile(Context context, String filePath){
return loadBitmap(BitmapUtils.loadBitmapFromAssets(context,filePath));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package com.martin.ads.vrlib.utils;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;

/**
* Created by Ads on 2017/4/6.
*/

/**
TextImageGenerator.newInstance()
.setPadding(25)
.setTextColor(Color.WHITE)
.setBackgroundColor(Color.TRANSPARENT)
.setTypeface(Typeface.createFromAsset(context.getAssets(), "fonts/font_26.ttf"))
.setTextSize(25)
.addTextToImage("I'm text. 我是文字")
*/
public class TextImageGenerator {
private int textSize;
private int textColor;
private int padding;
private int backgroundColor;
private Typeface typeface;

private TextImageGenerator() {
textSize=15;
textColor= Color.TRANSPARENT;
padding=15;
backgroundColor=Color.BLACK;
typeface=null;
}

public static TextImageGenerator newInstance(){
return new TextImageGenerator();
}

public Bitmap addTextToImage(String text) {
Paint paint = new Paint();
paint.setColor(textColor);
paint.setTypeface(typeface);
paint.setAntiAlias(true);
paint.setFilterBitmap(true);
paint.setTextSize(textSize);

float textWidth=getTextWidth(paint,text);
float textHeight=getTextHeight(paint);
int imgWidth=(int)Math.ceil(textWidth)+padding;
int imgHeight=(int)Math.ceil(textHeight)+padding;
Bitmap resultBmp = Bitmap.createBitmap(imgWidth, imgHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(resultBmp);
canvas.drawColor(backgroundColor);

float tX = (imgWidth-textWidth)/2;
float tY = (imgHeight - textHeight)/2+getFontLeading(paint);
canvas.drawText(text,tX,tY,paint);
return resultBmp;
}

public static float getTextWidth(Paint paint, String str) {
return paint.measureText(str);
}

public static float getTextHeight(Paint paint) {
Paint.FontMetrics fm = paint.getFontMetrics();
return fm.descent - fm.ascent;
}

public static float getFontLeading(Paint paint) {
Paint.FontMetrics fm = paint.getFontMetrics();
return fm.leading- fm.ascent;
}

public TextImageGenerator setTextSize(int textSize) {
this.textSize = textSize;
return this;
}

public TextImageGenerator setTextColor(int textColor) {
this.textColor = textColor;
return this;
}

public TextImageGenerator setPadding(int padding) {
this.padding = padding;
return this;
}

public TextImageGenerator setBackgroundColor(int backgroundColor) {
this.backgroundColor = backgroundColor;
return this;
}

public TextImageGenerator setTypeface(Typeface typeface) {
this.typeface = typeface;
return this;
}
}

0 comments on commit bd35f2e

Please sign in to comment.