mirror of
https://github.com/bulletphysics/bullet3
synced 2024-12-13 21:30:09 +00:00
fix window resize/width bookkeeping bug in MacOpenGLWindow.mm
This commit is contained in:
parent
612e46614a
commit
8076d5235c
@ -102,11 +102,11 @@ float loop;
|
|||||||
}
|
}
|
||||||
-(void)drawRect:(NSRect)rect
|
-(void)drawRect:(NSRect)rect
|
||||||
{
|
{
|
||||||
|
|
||||||
if (([self frame].size.width != m_lastWidth) || ([self frame].size.height != m_lastHeight))
|
if (([self frame].size.width != m_lastWidth) || ([self frame].size.height != m_lastHeight))
|
||||||
{
|
{
|
||||||
m_lastWidth = [self frame].size.width;
|
m_lastWidth = [self frame].size.width;
|
||||||
m_lastHeight = [self frame].size.height;
|
m_lastHeight = [self frame].size.height;
|
||||||
|
|
||||||
// Only needed on resize:
|
// Only needed on resize:
|
||||||
[m_context clearDrawable];
|
[m_context clearDrawable];
|
||||||
|
|
||||||
@ -114,7 +114,6 @@ float loop;
|
|||||||
float width = [self frame].size.width;
|
float width = [self frame].size.width;
|
||||||
float height = [self frame].size.height;
|
float height = [self frame].size.height;
|
||||||
|
|
||||||
|
|
||||||
// Get view dimensions in pixels
|
// Get view dimensions in pixels
|
||||||
// glViewport(0,0,10,10);
|
// glViewport(0,0,10,10);
|
||||||
|
|
||||||
@ -209,16 +208,12 @@ struct MacOpenGLWindowInternalData
|
|||||||
m_myview = 0;
|
m_myview = 0;
|
||||||
m_pool = 0;
|
m_pool = 0;
|
||||||
m_window = 0;
|
m_window = 0;
|
||||||
m_width = -1;
|
|
||||||
m_height = -1;
|
|
||||||
m_exitRequested = false;
|
m_exitRequested = false;
|
||||||
}
|
}
|
||||||
NSApplication* m_myApp;
|
NSApplication* m_myApp;
|
||||||
TestView* m_myview;
|
TestView* m_myview;
|
||||||
NSAutoreleasePool* m_pool;
|
NSAutoreleasePool* m_pool;
|
||||||
NSWindow* m_window;
|
NSWindow* m_window;
|
||||||
int m_width;
|
|
||||||
int m_height;
|
|
||||||
bool m_exitRequested;
|
bool m_exitRequested;
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -294,8 +289,6 @@ void MacOpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci)
|
|||||||
if (m_internalData)
|
if (m_internalData)
|
||||||
closeWindow();
|
closeWindow();
|
||||||
|
|
||||||
int width = ci.m_width;
|
|
||||||
int height = ci.m_height;
|
|
||||||
const char* windowTitle = ci.m_title;
|
const char* windowTitle = ci.m_title;
|
||||||
|
|
||||||
|
|
||||||
@ -303,9 +296,7 @@ void MacOpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci)
|
|||||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||||
|
|
||||||
m_internalData = new MacOpenGLWindowInternalData;
|
m_internalData = new MacOpenGLWindowInternalData;
|
||||||
m_internalData->m_width = width;
|
|
||||||
m_internalData->m_height = height;
|
|
||||||
|
|
||||||
m_internalData->m_pool = [NSAutoreleasePool new];
|
m_internalData->m_pool = [NSAutoreleasePool new];
|
||||||
m_internalData->m_myApp = [NSApplication sharedApplication];
|
m_internalData->m_myApp = [NSApplication sharedApplication];
|
||||||
//myApp = [MyApp sharedApplication];
|
//myApp = [MyApp sharedApplication];
|
||||||
@ -373,7 +364,7 @@ void MacOpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci)
|
|||||||
[newItem release];
|
[newItem release];
|
||||||
*/
|
*/
|
||||||
|
|
||||||
NSRect frame = NSMakeRect(0., 0., width, height);
|
NSRect frame = NSMakeRect(0., 0., ci.m_width, ci.m_height);
|
||||||
|
|
||||||
m_internalData->m_window = [NSWindow alloc];
|
m_internalData->m_window = [NSWindow alloc];
|
||||||
[m_internalData->m_window initWithContentRect:frame
|
[m_internalData->m_window initWithContentRect:frame
|
||||||
@ -423,9 +414,7 @@ void MacOpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci)
|
|||||||
[m_internalData->m_window makeKeyAndOrderFront: nil];
|
[m_internalData->m_window makeKeyAndOrderFront: nil];
|
||||||
|
|
||||||
[m_internalData->m_myview MakeCurrent];
|
[m_internalData->m_myview MakeCurrent];
|
||||||
m_internalData->m_width = m_internalData->m_myview.GetWindowWidth;
|
|
||||||
m_internalData->m_height = m_internalData->m_myview.GetWindowHeight;
|
|
||||||
|
|
||||||
|
|
||||||
[NSApp activateIgnoringOtherApps:YES];
|
[NSApp activateIgnoringOtherApps:YES];
|
||||||
|
|
||||||
@ -1035,13 +1024,13 @@ void MacOpenGLWindow::startRendering()
|
|||||||
float aspect;
|
float aspect;
|
||||||
//b3Vector3 extents;
|
//b3Vector3 extents;
|
||||||
|
|
||||||
if (m_internalData->m_width > m_internalData->m_height)
|
if (getWidth() > getHeight())
|
||||||
{
|
{
|
||||||
aspect = (float)m_internalData->m_width / (float)m_internalData->m_height;
|
aspect = (float)getWidth() / (float)getHeight();
|
||||||
//extents.setValue(aspect * 1.0f, 1.0f,0);
|
//extents.setValue(aspect * 1.0f, 1.0f,0);
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
aspect = (float)m_internalData->m_height / (float)m_internalData->m_width;
|
aspect = (float)getHeight() / (float)getWidth();
|
||||||
//extents.setValue(1.0f, aspect*1.f,0);
|
//extents.setValue(1.0f, aspect*1.f,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1136,6 +1125,7 @@ int MacOpenGLWindow::getWidth() const
|
|||||||
{
|
{
|
||||||
if (m_internalData && m_internalData->m_myview && m_internalData->m_myview.GetWindowWidth)
|
if (m_internalData && m_internalData->m_myview && m_internalData->m_myview.GetWindowWidth)
|
||||||
return m_internalData->m_myview.GetWindowWidth;
|
return m_internalData->m_myview.GetWindowWidth;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1152,7 +1142,7 @@ void MacOpenGLWindow::setResizeCallback(b3ResizeCallback resizeCallback)
|
|||||||
[m_internalData->m_myview setResizeCallback:resizeCallback];
|
[m_internalData->m_myview setResizeCallback:resizeCallback];
|
||||||
if (resizeCallback)
|
if (resizeCallback)
|
||||||
{
|
{
|
||||||
(resizeCallback)(m_internalData->m_width,m_internalData->m_height);
|
(resizeCallback)(getWidth(), getHeight());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,8 +14,8 @@ static b3MouseButtonCallback sOldMouseButtonCB = 0;
|
|||||||
static b3KeyboardCallback sOldKeyboardCB = 0;
|
static b3KeyboardCallback sOldKeyboardCB = 0;
|
||||||
//static b3RenderCallback sOldRenderCB = 0;
|
//static b3RenderCallback sOldRenderCB = 0;
|
||||||
|
|
||||||
float gWidth = 0 ;
|
float gWidth = 1024;
|
||||||
float gHeight = 0;
|
float gHeight = 768;
|
||||||
|
|
||||||
void MyWheelCallback(float deltax, float deltay)
|
void MyWheelCallback(float deltax, float deltay)
|
||||||
{
|
{
|
||||||
@ -61,7 +61,7 @@ int main(int argc, char* argv[])
|
|||||||
b3CommandLineArgs myArgs(argc,argv);
|
b3CommandLineArgs myArgs(argc,argv);
|
||||||
|
|
||||||
|
|
||||||
SimpleOpenGL3App* app = new SimpleOpenGL3App("SimpleOpenGL3App",1024,768,true);
|
SimpleOpenGL3App* app = new SimpleOpenGL3App("SimpleOpenGL3App",gWidth,gHeight,true);
|
||||||
|
|
||||||
app->m_instancingRenderer->getActiveCamera()->setCameraDistance(13);
|
app->m_instancingRenderer->getActiveCamera()->setCameraDistance(13);
|
||||||
app->m_instancingRenderer->getActiveCamera()->setCameraPitch(0);
|
app->m_instancingRenderer->getActiveCamera()->setCameraPitch(0);
|
||||||
|
Loading…
Reference in New Issue
Block a user