Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hemi-sphere projection, dirty #34

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions StGLWidgets/StGLImageRegion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ StGLImageRegion::StGLImageRegion(StGLWidget* theParent,
: StGLWidget(theParent, 0, 0, StGLCorner(ST_VCORNER_TOP, ST_HCORNER_LEFT)),
myQuad(),
myUVSphere(StGLVec3(0.0f, 0.0f, 0.0f), 1.0f, 64),
myUVHemiSphere(StGLVec3(0.0f, 0.0f, 0.0f), 1.0f, 64, StGLUVSphereTypeHemi),
myTextureQueue(theTextureQueue),
myClickPntZo(0.0, 0.0),
myKeyFlags(ST_VF_NONE),
Expand Down Expand Up @@ -394,6 +395,7 @@ StGLImageRegion::~StGLImageRegion() {
myTextureQueue->getQTexture().release(aCtx);
myQuad.release(aCtx);
myUVSphere.release(aCtx);
myUVHemiSphere.release(aCtx);
myProgram.release(aCtx);

// simplify debugging - nullify pointer to this widget
Expand Down Expand Up @@ -440,6 +442,8 @@ bool StGLImageRegion::stglInit() {
return false;
} else if(!myUVSphere.initVBOs(aCtx)) {
ST_ERROR_LOG("Fail to init StGLUVSphere");
} else if(!myUVHemiSphere.initVBOs(aCtx)) {
ST_ERROR_LOG("Fail to init StGLUVSphere");
}

// setup texture filter
Expand Down Expand Up @@ -868,7 +872,8 @@ void StGLImageRegion::stglDrawView(unsigned int theView) {
aParams->PanCenter = aPanBack;
break;
}
case StViewSurface_Sphere: {
case StViewSurface_Sphere:
case StViewSurface_HemiSphere: {
if(!myProgram.init(aCtx, aTextures.getColorModel(), aTextures.getColorScale(), aColorGetter)) {
break;
}
Expand All @@ -892,7 +897,11 @@ void StGLImageRegion::stglDrawView(unsigned int theView) {
myProgram.getActiveProgram()->setProjMat (aCtx, myProjCam.getProjMatrixMono());
myProgram.getActiveProgram()->setModelMat(aCtx, aModelMat);

myUVSphere.draw(aCtx, *myProgram.getActiveProgram());
if (aViewMode == StViewSurface_Sphere) {
myUVSphere.draw(aCtx, *myProgram.getActiveProgram());
} else {
myUVHemiSphere.draw(aCtx, *myProgram.getActiveProgram());
}

myProgram.getActiveProgram()->unuse(aCtx);
break;
Expand Down Expand Up @@ -980,7 +989,8 @@ bool StGLImageRegion::tryUnClick(const StClickEvent& theEvent,
break;
}
case StViewSurface_Cubemap:
case StViewSurface_Sphere: {
case StViewSurface_Sphere:
case StViewSurface_HemiSphere: {
aParams->moveSphere(getMouseMoveSphere(myClickPntZo, aCursor));
break;
}
Expand Down Expand Up @@ -1060,7 +1070,8 @@ void StGLImageRegion::scaleAt(const StPointD_t& thePoint,
break;
}
case StViewSurface_Cubemap:
case StViewSurface_Sphere: {
case StViewSurface_Sphere:
case StViewSurface_HemiSphere: {
if(theStep < 0.0f
&& aParams->ScaleFactor <= 0.24f) {
break;
Expand Down
2 changes: 2 additions & 0 deletions StImageViewer/StImageViewerGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ void StImageViewerGUI::fillPanoramaMenu(StGLMenu* theMenu) {
myImage->params.ViewMode, StViewSurface_Plain);
theMenu->addItem(tr(MENU_VIEW_SURFACE_SPHERE),
myImage->params.ViewMode, StViewSurface_Sphere);
theMenu->addItem("Hemi Sphere", myImage->params.ViewMode, StViewSurface_HemiSphere);
theMenu->addItem(tr(MENU_VIEW_SURFACE_CUBEMAP),
myImage->params.ViewMode, StViewSurface_Cubemap);
if(myWindow->hasOrientationSensor()) {
Expand Down Expand Up @@ -1461,6 +1462,7 @@ void StImageViewerGUI::setVisibility(const StPointD_t& theCursor,
switch(aViewMode) {
case StViewSurface_Plain: aTrPano = MENU_VIEW_SURFACE_PLANE; break;
case StViewSurface_Sphere: aTrPano = MENU_VIEW_SURFACE_SPHERE; break;
case StViewSurface_HemiSphere: aTrPano = MENU_VIEW_SURFACE_HEMISPHERE; break;
case StViewSurface_Cubemap: aTrPano = MENU_VIEW_SURFACE_CUBEMAP; break;
}
myDescr->setText(tr(MENU_VIEW_PANORAMA) + "\n" + tr(aTrPano));
Expand Down
1 change: 1 addition & 0 deletions StImageViewer/StImageViewerStrings.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ namespace StImageViewerStrings {
MENU_VIEW_STICK_PANORAMA360 = 1288,
MENU_VIEW_FLIPZ_CUBE6x1 = 1291,
MENU_VIEW_FLIPZ_CUBE3x2 = 1292,
MENU_VIEW_SURFACE_HEMISPHERE= 1293,

// Root -> Output -> Change Device menu
MENU_CHANGE_DEVICE = 1400,
Expand Down
2 changes: 2 additions & 0 deletions StMoviePlayer/StMoviePlayerGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ void StMoviePlayerGUI::fillPanoramaMenu(StGLMenu* theMenu) {
myImage->params.ViewMode, StViewSurface_Plain);
theMenu->addItem(tr(MENU_VIEW_SURFACE_SPHERE),
myImage->params.ViewMode, StViewSurface_Sphere);
theMenu->addItem("HemiSphere", myImage->params.ViewMode, StViewSurface_HemiSphere);
theMenu->addItem(tr(MENU_VIEW_SURFACE_CUBEMAP),
myImage->params.ViewMode, StViewSurface_Cubemap);
if(myWindow->hasOrientationSensor()) {
Expand Down Expand Up @@ -1925,6 +1926,7 @@ void StMoviePlayerGUI::setVisibility(const StPointD_t& theCursor) {
switch(aViewMode) {
case StViewSurface_Plain: aTrPano = MENU_VIEW_SURFACE_PLANE; break;
case StViewSurface_Sphere: aTrPano = MENU_VIEW_SURFACE_SPHERE; break;
case StViewSurface_HemiSphere: aTrPano = MENU_VIEW_SURFACE_HEMISPHERE; break;
case StViewSurface_Cubemap: aTrPano = MENU_VIEW_SURFACE_CUBEMAP; break;
}
myDescr->setText(tr(MENU_VIEW_PANORAMA) + "\n" + tr(aTrPano));
Expand Down
1 change: 1 addition & 0 deletions StMoviePlayer/StMoviePlayerStrings.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ namespace StMoviePlayerStrings {
MENU_VIEW_TRACK_HEAD_POOR = 1286,
MENU_VIEW_TRACK_HEAD_AUDIO = 1287,
MENU_VIEW_STICK_PANORAMA360 = 1288,
MENU_VIEW_SURFACE_HEMISPHERE= 1289,

// Root -> Audio menu
MENU_AUDIO = 1300,
Expand Down
4 changes: 2 additions & 2 deletions StOutDistorted/StOutDistorted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ void StOutDistorted::stglDrawVR() {
hasComposError = true;
}

if(myVrTrackedPoses[vr::k_unTrackedDeviceIndex_Hmd].bPoseIsValid) {
if(myVrTrackedPoses[vr::k_unTrackedDeviceIndex_Hmd].bPoseIsValid) {
const vr::HmdMatrix34_t& aHeadPos = myVrTrackedPoses[vr::k_unTrackedDeviceIndex_Hmd].mDeviceToAbsoluteTracking;
double aRotMat[3][3];
for(int aRow = 0; aRow < 3; ++aRow) {
Expand All @@ -937,7 +937,7 @@ void StOutDistorted::stglDrawVR() {
}
}
myVrOrient.setMatrix(aRotMat);
}
}
}

// real screen buffer
Expand Down
4 changes: 2 additions & 2 deletions StShared/StDevILImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

typedef unsigned int ILenum;
typedef unsigned char ILboolean;
typedef int ILint;
typedef int ILint;
typedef size_t ILsizei;
typedef unsigned char ILubyte;
typedef unsigned int ILuint;
Expand Down Expand Up @@ -59,7 +59,7 @@ typedef unsigned int ILuint;
#define IL_BGRA 0x80E1
#define IL_LUMINANCE 0x1909
#define IL_LUMINANCE_ALPHA 0x190A
#define IL_ALPHA 0x190B
#define IL_ALPHA 0x190B

#define IL_UNSIGNED_BYTE 0x1401
#define IL_FLOAT 0x1406
Expand Down
24 changes: 21 additions & 3 deletions StShared/StGLUVSphere.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ namespace {
static const GLfloat ST_PIDIV2 = 1.5707963267948966192313216916397f;
};

StGLUVSphere::StGLUVSphere(const StGLVec3& theCenter,
const GLfloat theRadius,
const size_t theRings,
const StGLUVSphereType theType)
: StGLMesh(GL_TRIANGLE_STRIP),
myPrimCounts(1),
myIndPointers(1),
myCenter(theCenter),
myRadius(theRadius),
myRings(theRings),
myType(theType) {
//
}

StGLUVSphere::StGLUVSphere(const StGLVec3& theCenter,
const GLfloat theRadius,
const size_t theRings)
Expand All @@ -27,7 +41,8 @@ StGLUVSphere::StGLUVSphere(const StGLVec3& theCenter,
myIndPointers(1),
myCenter(theCenter),
myRadius(theRadius),
myRings(theRings) {
myRings(theRings),
myType(StGLUVSphereTypeFull) {
//
}

Expand All @@ -38,7 +53,8 @@ StGLUVSphere::StGLUVSphere(const StBndSphere& theBndSphere,
myIndPointers(1),
myCenter(theBndSphere.getCenter()),
myRadius(theBndSphere.getRadius()),
myRings(theRings) {
myRings(theRings),
myType(StGLUVSphereTypeFull) {
//
}

Expand Down Expand Up @@ -68,12 +84,14 @@ bool StGLUVSphere::computeMesh() {
StGLVec3* aVert = NULL;
StGLVec2 tcrd(0.0f, 0.0f);

GLfloat projections = myType == StGLUVSphereTypeFull ? 1 : 0.5;

for(size_t ringId = 0; ringId <= aRingsCount; ++ringId) {
theta = GLfloat(ringId) * ST_PI / GLfloat(aRingsCount) - ST_PIDIV2;
tcrd.y() = GLfloat(ringId) / GLfloat(aRingsCount);

for(size_t pointId = 0; pointId <= pointPerRing; ++pointId) {
phi = GLfloat(pointId) * ST_TWOPI / GLfloat(pointPerRing);
phi = GLfloat(pointId) * projections * ST_TWOPI / GLfloat(pointPerRing);

tcrd.x() = GLfloat(pointId) / GLfloat(pointPerRing);

Expand Down
11 changes: 10 additions & 1 deletion include/StGL/StParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ enum StViewSurface {
StViewSurface_Plain, //!< normal 2D image
StViewSurface_Cubemap, //!< cubemap texture
StViewSurface_Sphere, //!< spherical panorama
StViewSurface_HemiSphere, //!< hemispherical panorama
//StViewSurface_Cylinder, //!< cylindrical panorama
};

Expand All @@ -35,6 +36,7 @@ class StStereoParams {
switch(theViewMode) {
case StViewSurface_Cubemap: return "cubemap";
case StViewSurface_Sphere: return "sphere";
case StViewSurface_HemiSphere: return "hemisphere";
case StViewSurface_Plain: return "flat";
}
return "flat";
Expand All @@ -43,8 +45,11 @@ class StStereoParams {
static StViewSurface GET_VIEW_MODE_FROM_STRING(const StString& theViewModeStr) {
if(theViewModeStr.isStartsWithIgnoreCase(stCString("cubemap"))) {
return StViewSurface_Cubemap;
} else if(theViewModeStr.isStartsWithIgnoreCase(stCString("sphere"))) {
}
else if (theViewModeStr.isStartsWithIgnoreCase(stCString("sphere"))) {
return StViewSurface_Sphere;
} else if (theViewModeStr.isStartsWithIgnoreCase(stCString("hemisphere"))) {
return StViewSurface_HemiSphere;
} else {
return StViewSurface_Plain;
}
Expand Down Expand Up @@ -272,6 +277,7 @@ class StStereoParams {
void moveToRight(const float theDuration = 0.02f) {
switch(ViewingMode) {
case StViewSurface_Sphere:
case StViewSurface_HemiSphere:
case StViewSurface_Cubemap:
myPanYaw += 100.0f * theDuration;
break;
Expand All @@ -284,6 +290,7 @@ class StStereoParams {
void moveToLeft(const float theDuration = 0.02f) {
switch(ViewingMode) {
case StViewSurface_Sphere:
case StViewSurface_HemiSphere:
case StViewSurface_Cubemap:
myPanYaw -= 100.0f * theDuration;
break;
Expand All @@ -308,6 +315,7 @@ class StStereoParams {
void moveToDown(const float theDuration = 0.02f) {
switch(ViewingMode) {
case StViewSurface_Sphere:
case StViewSurface_HemiSphere:
case StViewSurface_Cubemap:
myPanPitch = clipPitch(myPanPitch - 100.0f * theDuration);
break;
Expand All @@ -320,6 +328,7 @@ class StStereoParams {
void moveToUp(const float theDuration = 0.02f) {
switch(ViewingMode) {
case StViewSurface_Sphere:
case StViewSurface_HemiSphere:
case StViewSurface_Cubemap:
myPanPitch = clipPitch(myPanPitch + 100.0f * theDuration);
break;
Expand Down
11 changes: 11 additions & 0 deletions include/StGLMesh/StGLUVSphere.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

#include "StGLMesh.h"

enum StGLUVSphereType {
StGLUVSphereTypeFull,
StGLUVSphereTypeHemi,
};

class StBndSphere;

/**
Expand All @@ -21,6 +26,11 @@ class StGLUVSphere : public StGLMesh {

public:

ST_CPPEXPORT StGLUVSphere(const StGLVec3& theCenter,
const GLfloat theRadius,
const size_t theRings,
const StGLUVSphereType theType);

/**
* Defines the UV sphere mesh with specified parameters.
*/
Expand Down Expand Up @@ -55,6 +65,7 @@ class StGLUVSphere : public StGLMesh {
StGLVec3 myCenter;
GLfloat myRadius;
size_t myRings;
StGLUVSphereType myType;

};

Expand Down
1 change: 1 addition & 0 deletions include/StGLWidgets/StGLImageRegion.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ class StGLImageRegion : public StGLWidget {

StGLQuads myQuad; //!< flat quad
StGLUVSphere myUVSphere; //!< sphere output helper class
StGLUVSphere myUVHemiSphere;
StGLProjCamera myProjCam; //!< copy of projection camera
StGLImageProgram myProgram; //!< GL program to draw flat image
StHandle<StGLTextureQueue> myTextureQueue; //!< shared texture queue
Expand Down