이게 몇년만의 서브클래싱이냐?
win32 API 들이 아직도 기억나는게 신기하다.
그럴듯한 창모드 어플을 만드려면 리사이징이 자연스러워야 하는데 ogre 쪽에선 이걸 해주는 코드를 못찾았다. 윈도이벤트리스너 라고 리스너를 달아서 windowMoved, windowResized 등을 받는게 가능하긴 한데 리사이즈 된 뒤의 이벤트를 받는 거라 내가 원하는 동작을 하기엔 좀 무리가 있었다. 하지만 이 놈은 windowClosed 등 유용한 이벤트들이 떨어지니 어차피 코딩을 해야할놈이긴 하다.. 이쪽 코드는 블로그에 적어두진 않겠지만 필요하면 WindowEventUtilities 와 WindowEventListener 클래스를 참고해보자.
결국 내가 원하는 WM_SIZING 처리를 위해서는.. 서브클래싱을 해야했다. 헐 추억의 서브클래싱. WindowEventUtilities 가 wndProc 을 들고있으니 적절히 참고하면서 아래 코드를 만들었다. 아래 코드는 아직 리사이징이 좀 어색한게 남아있는데.. 일단 여기 적어둔다.
아 리사이징 가장 어색한게 window7 에서 사이징을 하면 모서리에 붙어버리는듯한 동작이 나오던데.. 간만에 msdn 좀 뒤져봐야겠다.
[code cpp]
typedef LRESULT (*WindowProcType)(HWND,UINT,WPARAM,LPARAM);
WindowProcType oldWndProc;
static void subclassRenderWindow(RenderWindow* w);
static LRESULT wndProc(HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam);
void subclassRenderWindow(RenderWindow* w)
{
if(oldWndProc) return;
HWND handle;
w->getCustomAttribute("WINDOW", &handle);
oldWndProc = (WindowProcType)SetWindowLong(handle, GWL_WNDPROC, (DWORD)&wndProc);
};
LRESULT wndProc(HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
// WindowEventUtilities::_WndProc 에 의하면 WM_CREATE 보다 WM_SIZE
// 가 먼저 떨어질수도 있다네. 그랬던가? 어쨌건 저놈이 관련처리를
// 해주고 있으니 나도 그코드를 퍼올렸다.
// RenderWindow* w = (RenderWindow*)GetWindowLongPtr(wnd,GWLP_USERDATA);
// if(!w) return oldWndProc(wnd, msg, wparam, lparam);
switch(msg)
{
// 최소 사이즈 지정
case WM_GETMINMAXINFO:
{
MINMAXINFO* mmi = (MINMAXINFO*)lparam;
mmi->ptMinTrackSize.x = 800;
mmi->ptMinTrackSize.y = 600;
return 0;
}
// 아 씨댕 생각보다 복잡한 코드를 만들어야 하네.
// 어느위치로 땡기는지에 따라 달리 계산해줘야 한다.
// 조건을 좀더 합치는것도 되겠지만 아직 부자연스러운 움직임이 있어 그냥 둬본다.
case WM_SIZING:
{
const double ratio = 1.33333;
RECT* rc = (RECT*)lparam;
int width = rc->right - rc->left;
int height = rc->bottom - rc->top;
if(wparam == WMSZ_LEFT || wparam == WMSZ_RIGHT)
{
int h = static_cast<int>(width / ratio);
rc->bottom = rc->top + h;
}
else if(wparam == WMSZ_TOP || wparam == WMSZ_BOTTOM)
{
int w = static_cast<int>(height * ratio);
rc->right = rc->left + w;
}
else if(wparam == WMSZ_TOPLEFT || wparam == WMSZ_BOTTOMLEFT)
{
int w = static_cast<int>(height * ratio);
rc->left = rc->right - w;
}
else if(wparam == WMSZ_TOPRIGHT || wparam == WMSZ_BOTTOMRIGHT)
{
int w = static_cast<int>(height * ratio);
rc->right = rc->left + w;
}
return FALSE;
}
default:
break;
}
return oldWndProc(wnd, msg, wparam, lparam);
}
[/code]
2010/07/08 추가.
와.. 이게 생각보다 빡치는 문제였네.
이전 코드는 비율만 맟춰본 거였고.. 사실상 크기를 정확히 맟추려면 약간의 보정을 해줘야 한다. WM_SIZING 시 떨어지는 rect 는 스크린좌표이기 때문에 내가 원하는 크기가 800*600 이라고 해서 800*600 으로 맟춰버리면 윈도우가 그려주는 넌클라이언트 영역들때문에 800*600 에서 조금씩 짤린 크기가 되버린다. 이런 경우를 위해 AdjustWindwRect(Ex) 함수가 있는데.. CreateWindow 가 오우거안에 숨어있어서 ( D3DRenderWindow::create 참고 ).. 내가 원하던 클라이언트 사이즈와 만들어진 윈도우의 스크린 사이즈의 차이를 기억해뒀다가 sizing 시 보정해주는 방법을 썼다.
아래는 코드 일부, 내가 원했던 크기와 실제 만들어진 크기의 차이를 기억해 두는 함수
[code cpp]
void FerrariApp::prepareSizing()
{
HWND handle;
getRenderWindow()->getCustomAttribute("WINDOW", &handle);
int wantedWidth = config.getVideoWidth();
int wantedHeight = config.getVideoHeight();
RECT rc;
GetWindowRect(handle, &rc);
int realWidth = rc.right - rc.left;
int realHeight = rc.bottom - rc.top;
adjustSize_.first = realWidth - wantedWidth;
adjustSize_.second = realHeight - wantedHeight;
trace("adjustSize_ %d %d\n", adjustSize_.first, adjustSize_.second);
}
[/code]
다시 코드 일부, 처음 적었던 코드에 위에서 기억해둔 사이즈를 보정해주는 코드를 추가한것
[code cpp]
LRESULT FerrariApp::onSizing(HWND hwnd, WPARAM wparam, LPARAM lparam)
{
const double ratio = static_cast<double>(config.getVideoWidth()) / static_cast<double>(config.getVideoHeight());
RECT* rc = (RECT*)lparam;
rc->left += adjustSize_.first / 2;
rc->top += adjustSize_.second / 2;
rc->right -= adjustSize_.first / 2;
rc->bottom -= adjustSize_.second / 2;
double width = rc->right - rc->left;
double height = rc->bottom - rc->top;
if(wparam == WMSZ_LEFT || wparam == WMSZ_RIGHT)
{
int h = static_cast<int>(width / ratio);
rc->bottom = rc->top + h;
}
else if(wparam == WMSZ_TOP || wparam == WMSZ_BOTTOM)
{
int w = static_cast<int>(height * ratio);
rc->right = rc->left + w;
}
else if(wparam == WMSZ_TOPLEFT || wparam == WMSZ_BOTTOMLEFT)
{
int w = static_cast<int>(height * ratio);
rc->left = rc->right - w;
}
else if(wparam == WMSZ_TOPRIGHT || wparam == WMSZ_BOTTOMRIGHT)
{
int w = static_cast<int>(height * ratio);
rc->right = rc->left + w;
}
rc->left -= adjustSize_.first / 2;
rc->top -= adjustSize_.second / 2;
rc->right += adjustSize_.first / 2;
rc->bottom += adjustSize_.second / 2;
return FALSE;
}
[/code]
아직도 좀 어색하게 돌아가는데 천천히 잡아보자.
헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤헤
2010년 3월 5일 금요일
ogre, archive 관련 작업을 시작하기위한 테스트 코드
예를들어 foo 라는 포맷을 정의하고 이를 ogre 가 처리하도록 하려면 아래 세개의 클래스를 구현하고
리소스매니저를 통해 리소스에 접근이 가능하다.
아직 파일포맷에 대해서 생각하지는 않았지만 위와 같은 과정을 테스트해보기 위한 코드를 만들어보고 적어둔다.
fooarchive.hpp 는 위 세 클래스의 선언을 모두 담았다.
fooarchive.cpp 는 FooArchive 클래스의 구현만 담았다.
fooarchivefactory.cpp 는 FooArchvieFactory 클래스의 구현만 담았다.
foodatastream.cpp 는 FooDataStream 클래스의 구현만 담았다. 이쪽은 대강 구현한거라 버그가 많을듯. 어차피 내용 붙이면 모두 새로구현해야한다.
archive.cpp 는 위 세 클래스를 써먹는 예제를 담았다. 등록하는 코드도 봐두자..
- FooArchive : 디렉토리 처리? 뭐 그런거라고 보자
- FooArchiveFactory : 보일러플레이트
- FooDataStream : 파일스트림 처리? 그렇게 생각하면 굳
리소스매니저를 통해 리소스에 접근이 가능하다.
아직 파일포맷에 대해서 생각하지는 않았지만 위와 같은 과정을 테스트해보기 위한 코드를 만들어보고 적어둔다.
fooarchive.hpp 는 위 세 클래스의 선언을 모두 담았다.
펼쳐두기..
[code cpp]
// 예를들어 foo 타입의 아카이브를 지원하려면
// 아래 세개의 클래스를 만들고
// 1. FooArchive
// 2. FooArchiveFactory
// 3. FooDataStream
//
// FooArchiveFactory 를 ArchiveManager 에 등록한후
// 리소스매니저를 통해 쓰면 된다.
#pragma once
#ifndef _FOOARCHIVE_H_
#define _FOOARCHIVE_H_
#include <OgrePrerequisites.h>
#include <OgreArchive.h>
#include <OgreArchiveFactory.h>
class FooArchive : public Ogre::Archive
{
public:
FooArchive(const Ogre::String name, const Ogre::String& archType);
~FooArchive();
bool isCaseSensitive() const { return true; }
void load();
void unload();
bool isReadOnly() const { return true; }
Ogre::DataStreamPtr open(const Ogre::String& filename) const;
Ogre::StringVectorPtr list(bool recursive=true, bool dirs=false);
Ogre::FileInfoListPtr listFileInfo(bool recursive = true, bool dirs = false);
Ogre::StringVectorPtr find(const Ogre::String& pattern, bool recursive = true, bool dirs = false);
Ogre::FileInfoListPtr findFileInfo(const Ogre::String& pattern, bool recursive = true, bool dirs = false);
bool exists(const Ogre::String& filename);
time_t getModifiedTime(const Ogre::String& filename);
};
class FooArchiveFactory : public Ogre::ArchiveFactory
{
public:
virtual ~FooArchiveFactory();
const Ogre::String& getType() const;
Ogre::Archive *createInstance(const Ogre::String& name);
void destroyInstance(Ogre::Archive* arch);
};
class FooDataStream : public Ogre::DataStream
{
public:
FooDataStream(const Ogre::String& name);
size_t read(void* buf, size_t count);
void skip(long count);
void seek(size_t pos);
size_t tell() const;
bool eof() const;
void close();
private:
size_t idx_;
char buf_[26];
};
#endif /* _FOOARCHIVE_H_ */
[/code]
// 예를들어 foo 타입의 아카이브를 지원하려면
// 아래 세개의 클래스를 만들고
// 1. FooArchive
// 2. FooArchiveFactory
// 3. FooDataStream
//
// FooArchiveFactory 를 ArchiveManager 에 등록한후
// 리소스매니저를 통해 쓰면 된다.
#pragma once
#ifndef _FOOARCHIVE_H_
#define _FOOARCHIVE_H_
#include <OgrePrerequisites.h>
#include <OgreArchive.h>
#include <OgreArchiveFactory.h>
class FooArchive : public Ogre::Archive
{
public:
FooArchive(const Ogre::String name, const Ogre::String& archType);
~FooArchive();
bool isCaseSensitive() const { return true; }
void load();
void unload();
bool isReadOnly() const { return true; }
Ogre::DataStreamPtr open(const Ogre::String& filename) const;
Ogre::StringVectorPtr list(bool recursive=true, bool dirs=false);
Ogre::FileInfoListPtr listFileInfo(bool recursive = true, bool dirs = false);
Ogre::StringVectorPtr find(const Ogre::String& pattern, bool recursive = true, bool dirs = false);
Ogre::FileInfoListPtr findFileInfo(const Ogre::String& pattern, bool recursive = true, bool dirs = false);
bool exists(const Ogre::String& filename);
time_t getModifiedTime(const Ogre::String& filename);
};
class FooArchiveFactory : public Ogre::ArchiveFactory
{
public:
virtual ~FooArchiveFactory();
const Ogre::String& getType() const;
Ogre::Archive *createInstance(const Ogre::String& name);
void destroyInstance(Ogre::Archive* arch);
};
class FooDataStream : public Ogre::DataStream
{
public:
FooDataStream(const Ogre::String& name);
size_t read(void* buf, size_t count);
void skip(long count);
void seek(size_t pos);
size_t tell() const;
bool eof() const;
void close();
private:
size_t idx_;
char buf_[26];
};
#endif /* _FOOARCHIVE_H_ */
[/code]
fooarchive.cpp 는 FooArchive 클래스의 구현만 담았다.
펼쳐두기..
[code cpp]
#include "fooarchive.hpp"
#include <OgreStringVector.h>
using namespace Ogre;
FooArchive::FooArchive(const Ogre::String name, const Ogre::String& archType) : Archive(name, archType)
{
}
FooArchive::~FooArchive()
{
}
void FooArchive::load()
{
}
void FooArchive::unload()
{
}
DataStreamPtr FooArchive::open(const String& filename) const
{
return DataStreamPtr(new FooDataStream(filename));
}
StringVectorPtr FooArchive::list(bool recursive, bool dirs)
{
// 걍 적당히 파일 두개를 가지고 있는셈 친다.
StringVectorPtr v(new StringVector);
v->push_back("1.foo");
v->push_back("2.foo");
return v;
}
FileInfoListPtr FooArchive::listFileInfo(bool recursive, bool dirs)
{
// 음 채울 정보가 많네. 그냥 빈거 줘본다.
// 원래는 이놈을 먼저 구현하고 list 를 구현해야 겠구나.
FileInfoListPtr fil(new FileInfoList);
return fil;
}
StringVectorPtr FooArchive::find(const String& pattern, bool recursive, bool dirs)
{
return StringVectorPtr(new StringVector);
}
FileInfoListPtr FooArchive::findFileInfo(const String& pattern, bool recursive, bool dirs)
{
return FileInfoListPtr(new FileInfoList);
}
bool FooArchive::exists(const String& filename)
{
return filename == "1.foo" || filename == "2.foo";
}
time_t FooArchive::getModifiedTime(const String& filename)
{
return 0;
}
[/code]
#include "fooarchive.hpp"
#include <OgreStringVector.h>
using namespace Ogre;
FooArchive::FooArchive(const Ogre::String name, const Ogre::String& archType) : Archive(name, archType)
{
}
FooArchive::~FooArchive()
{
}
void FooArchive::load()
{
}
void FooArchive::unload()
{
}
DataStreamPtr FooArchive::open(const String& filename) const
{
return DataStreamPtr(new FooDataStream(filename));
}
StringVectorPtr FooArchive::list(bool recursive, bool dirs)
{
// 걍 적당히 파일 두개를 가지고 있는셈 친다.
StringVectorPtr v(new StringVector);
v->push_back("1.foo");
v->push_back("2.foo");
return v;
}
FileInfoListPtr FooArchive::listFileInfo(bool recursive, bool dirs)
{
// 음 채울 정보가 많네. 그냥 빈거 줘본다.
// 원래는 이놈을 먼저 구현하고 list 를 구현해야 겠구나.
FileInfoListPtr fil(new FileInfoList);
return fil;
}
StringVectorPtr FooArchive::find(const String& pattern, bool recursive, bool dirs)
{
return StringVectorPtr(new StringVector);
}
FileInfoListPtr FooArchive::findFileInfo(const String& pattern, bool recursive, bool dirs)
{
return FileInfoListPtr(new FileInfoList);
}
bool FooArchive::exists(const String& filename)
{
return filename == "1.foo" || filename == "2.foo";
}
time_t FooArchive::getModifiedTime(const String& filename)
{
return 0;
}
[/code]
fooarchivefactory.cpp 는 FooArchvieFactory 클래스의 구현만 담았다.
펼쳐두기..
[code cpp]
#include "fooarchive.hpp"
#include <iostream>
using namespace Ogre;
using namespace std;
FooArchiveFactory::~FooArchiveFactory()
{
}
const String& FooArchiveFactory::getType() const
{
static const String s = "foo";
return s;
}
Archive* FooArchiveFactory::createInstance(const String& name)
{
// OGRE_NEW 등을 제공하는 모양인데 그냥 new 썼다.
return new FooArchive(name, "foo");
}
void FooArchiveFactory::destroyInstance(Ogre::Archive* arch)
{
delete arch;
}
[/code]
#include "fooarchive.hpp"
#include <iostream>
using namespace Ogre;
using namespace std;
FooArchiveFactory::~FooArchiveFactory()
{
}
const String& FooArchiveFactory::getType() const
{
static const String s = "foo";
return s;
}
Archive* FooArchiveFactory::createInstance(const String& name)
{
// OGRE_NEW 등을 제공하는 모양인데 그냥 new 썼다.
return new FooArchive(name, "foo");
}
void FooArchiveFactory::destroyInstance(Ogre::Archive* arch)
{
delete arch;
}
[/code]
foodatastream.cpp 는 FooDataStream 클래스의 구현만 담았다. 이쪽은 대강 구현한거라 버그가 많을듯. 어차피 내용 붙이면 모두 새로구현해야한다.
펼쳐두기..
[code cpp]
#include "fooarchive.hpp"
#include <algorithm>
using namespace std;
FooDataStream::FooDataStream(const Ogre::String& name) : DataStream(name)
{
// 어차피 예제 아닌가 그냥 적당히 고정 버퍼를 박았다.
mSize = sizeof(buf_);
idx_ = 0;
for(size_t i = 0; i < mSize; ++i)
{
buf_[i] = 'a'+i;
}
}
size_t FooDataStream::read(void* buf, size_t count)
{
int readlen = min(count, mSize - idx_);
memcpy(buf, buf_ + idx_, readlen);
idx_ += readlen;
return readlen;
}
void FooDataStream::skip(long count)
{
idx_ += count;
idx_ = min(idx_, mSize);
}
void FooDataStream::seek(size_t pos)
{
if(pos < mSize)
idx_ = pos;
}
size_t FooDataStream::tell() const
{
return idx_;
}
bool FooDataStream::eof() const
{
return idx_ == mSize;
}
void FooDataStream::close()
{
}
[/code]
#include "fooarchive.hpp"
#include <algorithm>
using namespace std;
FooDataStream::FooDataStream(const Ogre::String& name) : DataStream(name)
{
// 어차피 예제 아닌가 그냥 적당히 고정 버퍼를 박았다.
mSize = sizeof(buf_);
idx_ = 0;
for(size_t i = 0; i < mSize; ++i)
{
buf_[i] = 'a'+i;
}
}
size_t FooDataStream::read(void* buf, size_t count)
{
int readlen = min(count, mSize - idx_);
memcpy(buf, buf_ + idx_, readlen);
idx_ += readlen;
return readlen;
}
void FooDataStream::skip(long count)
{
idx_ += count;
idx_ = min(idx_, mSize);
}
void FooDataStream::seek(size_t pos)
{
if(pos < mSize)
idx_ = pos;
}
size_t FooDataStream::tell() const
{
return idx_;
}
bool FooDataStream::eof() const
{
return idx_ == mSize;
}
void FooDataStream::close()
{
}
[/code]
archive.cpp 는 위 세 클래스를 써먹는 예제를 담았다. 등록하는 코드도 봐두자..
펼쳐두기..
[code cpp]
#include "fooarchive.hpp"
#include <Ogre.h>
#include <iostream>
using namespace Ogre;
using namespace std;
class OgreApp
{
public:
OgreApp()
{
// root 를 만들기 전에는 ArchiveFactory 등록이 불가?
root_ = new Root("", "");
// 이제 등록가능하겠지
//
// 등록이 포인터를 등록하는 스타일이라 이걸 언제 delete 해줘야
// 하는지 애매한데 코드를 읽어보니 (1.6.4) delete 는 불러주지
// 않는다. 따라서 밖에서 포인터를 들고있다가 때되면(root
// 지운후가 되겠지) 지워주는 수고를 해줘야 한다.
faf_ = new FooArchiveFactory;
ArchiveManager& am = ArchiveManager::getSingleton();
am.addArchiveFactory(faf_);
// foo 타입을 처리하는 아카이브팩토리를 등록했으니 이제 foo 타입 리소스 추가가 가능할것이다
ResourceGroupManager& rgm = ResourceGroupManager::getSingleton();
rgm.addResourceLocation("noname", "foo", "nogroup");
rgm.initialiseAllResourceGroups();
// loadResourceGroup 을 하면 리소스를 완전히
// 로딩한다는데.. 지금 예제에선 별 의미가 없긴 하군.
rgm.loadResourceGroup("nogroup");
// 이제 리소스이름들을 읽어보자
// FooArchive 의 list 정도가 불리겠지?
StringVectorPtr v = rgm.listResourceNames("nogroup");
for(StringVector::const_iterator i = v->begin(); i != v->end(); ++i)
{
cout << "name: " << *i << endl;
}
// 이제 실제로 리소스에 접근을 해보자
for(StringVector::const_iterator i = v->begin(); i != v->end(); ++i)
{
cout << *i << " ==> " << rgm.openResource(*i, "nogroup")->getAsString() << endl;
}
}
~OgreApp()
{
delete root_;
delete faf_;
}
private:
Root* root_;
FooArchiveFactory* faf_;
};
int main()
{
OgreApp app;
}
[/code]
위 소스들을 빌드하는데 쓰인 CMakeLists.txt 의 일부. 아래 언급된 link_ogre3d_all() 매크로는 다른 파일에 있는데 적지 않았다.#include "fooarchive.hpp"
#include <Ogre.h>
#include <iostream>
using namespace Ogre;
using namespace std;
class OgreApp
{
public:
OgreApp()
{
// root 를 만들기 전에는 ArchiveFactory 등록이 불가?
root_ = new Root("", "");
// 이제 등록가능하겠지
//
// 등록이 포인터를 등록하는 스타일이라 이걸 언제 delete 해줘야
// 하는지 애매한데 코드를 읽어보니 (1.6.4) delete 는 불러주지
// 않는다. 따라서 밖에서 포인터를 들고있다가 때되면(root
// 지운후가 되겠지) 지워주는 수고를 해줘야 한다.
faf_ = new FooArchiveFactory;
ArchiveManager& am = ArchiveManager::getSingleton();
am.addArchiveFactory(faf_);
// foo 타입을 처리하는 아카이브팩토리를 등록했으니 이제 foo 타입 리소스 추가가 가능할것이다
ResourceGroupManager& rgm = ResourceGroupManager::getSingleton();
rgm.addResourceLocation("noname", "foo", "nogroup");
rgm.initialiseAllResourceGroups();
// loadResourceGroup 을 하면 리소스를 완전히
// 로딩한다는데.. 지금 예제에선 별 의미가 없긴 하군.
rgm.loadResourceGroup("nogroup");
// 이제 리소스이름들을 읽어보자
// FooArchive 의 list 정도가 불리겠지?
StringVectorPtr v = rgm.listResourceNames("nogroup");
for(StringVector::const_iterator i = v->begin(); i != v->end(); ++i)
{
cout << "name: " << *i << endl;
}
// 이제 실제로 리소스에 접근을 해보자
for(StringVector::const_iterator i = v->begin(); i != v->end(); ++i)
{
cout << *i << " ==> " << rgm.openResource(*i, "nogroup")->getAsString() << endl;
}
}
~OgreApp()
{
delete root_;
delete faf_;
}
private:
Root* root_;
FooArchiveFactory* faf_;
};
int main()
{
OgreApp app;
}
[/code]
펼쳐두기..
[code]
project(archive)
link_ogre3d_all()
add_library(fooarchive fooarchive.cpp fooarchivefactory.cpp foodatastream.cpp)
add_executable(archive archive.cpp)
target_link_libraries(archive fooarchive)
[/code]
project(archive)
link_ogre3d_all()
add_library(fooarchive fooarchive.cpp fooarchivefactory.cpp foodatastream.cpp)
add_executable(archive archive.cpp)
target_link_libraries(archive fooarchive)
[/code]
2010년 2월 21일 일요일
ogre3d 창모드일때 마우스 처리에 대해서 조금 적어둔다
OIS 를 non exclusive 모드로 돌리는것은 아래 링크대로 코드 추가
http://www.ogre3d.org/wiki/index.php/Using_OIS#Non-exclusive_input
[code cpp]
paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_FOREGROUND" )));
paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_NONEXCLUSIVE")));
paramList.insert(std::make_pair(std::string("w32_keyboard"), std::string("DISCL_FOREGROUND")));
paramList.insert(std::make_pair(std::string("w32_keyboard"), std::string("DISCL_NONEXCLUSIVE")));
[/code]
그리고 기존 MouseMoved 에서 상대좌표로 마우스무브 인젝션 하던것을 절대좌표로 포지션 인젝션. 흠. 애초에 왜 상대좌표 썼는지는 원코드 쓴이에게 물어봐야 겠는데 분위기 보니 오우거 샘플이 원래 저걸 쓴모양인듯.
[code cpp]
OgreFramework::getSingletonPtr()->m_pGUISystem->injectMousePosition(evt.state.X.abs, evt.state.Y.abs);
[/code]
아 그리고 시스템 마우스 커서가 남아있으니 숨기는 코드도 필요. 적당히 ShowCursor 불러주면 끝. 이거 그다기 깔끔한 처리는 아닌데 다른 방법을 찾지 못했다.
[code cpp]
::ShowCursor(FALSE);
[/code]
http://www.ogre3d.org/wiki/index.php/Using_OIS#Non-exclusive_input
[code cpp]
paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_FOREGROUND" )));
paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_NONEXCLUSIVE")));
paramList.insert(std::make_pair(std::string("w32_keyboard"), std::string("DISCL_FOREGROUND")));
paramList.insert(std::make_pair(std::string("w32_keyboard"), std::string("DISCL_NONEXCLUSIVE")));
[/code]
그리고 기존 MouseMoved 에서 상대좌표로 마우스무브 인젝션 하던것을 절대좌표로 포지션 인젝션. 흠. 애초에 왜 상대좌표 썼는지는 원코드 쓴이에게 물어봐야 겠는데 분위기 보니 오우거 샘플이 원래 저걸 쓴모양인듯.
[code cpp]
OgreFramework::getSingletonPtr()->m_pGUISystem->injectMousePosition(evt.state.X.abs, evt.state.Y.abs);
[/code]
아 그리고 시스템 마우스 커서가 남아있으니 숨기는 코드도 필요. 적당히 ShowCursor 불러주면 끝. 이거 그다기 깔끔한 처리는 아닌데 다른 방법을 찾지 못했다.
[code cpp]
::ShowCursor(FALSE);
[/code]
피드 구독하기:
글 (Atom)