Syphius
16-06-2006 16:18:25
Hello!
I use PLSM2 to deform my terrain, but when I click on the terrain to deform it, I have an Acces Violation Exception here in OgrePagingLandScapeTexture.cpp:
in the void PagingLandScapeTexture::computePointColor function !
I use the CVS version of PLSM2, And I send my code for more help:
Maybe I made a mistake :'(, Could you help me please!
Syphius.
I use PLSM2 to deform my terrain, but when I click on the terrain to deform it, I have an Acces Violation Exception here in OgrePagingLandScapeTexture.cpp:
// save changes in textures
unsigned int currChannel = 0;
for (unsigned int k = 0; k < mNumTexture; k++)
{
uchar * const BaseData = mImages[k].getData ();
assert (BaseData && "PagingLandScapeTexture::computePointColor()");
const unsigned int curr_image_pos = imagePos*(static_cast <unsigned int>(mNumChannelperTexture[k]));
assert (mNumChannelperTexture[k] == (mImages[k].getBPP ()/8));
/* EXCEPTION HERE !!! */ BaseData[ curr_image_pos + 0] = static_cast <uchar> (color[k].r * bScale);
BaseData[ curr_image_pos + 1] = static_cast <uchar> (color[k].g * bScale);
BaseData[ curr_image_pos + 2] = static_cast <uchar> (color[k].b * bScale);
currChannel++;
}
in the void PagingLandScapeTexture::computePointColor function !
I use the CVS version of PLSM2, And I send my code for more help:
#ifndef TERRAIN_FRAME_LISTENER
#define TERRAIN_FRAME_LISTENER
#include <ExampleApplication.h>
#include <OgrePagingLandScapeRaySceneQuery.h>
#include "Line3D.h"
#define PI 3.14159265f
#define DEG2RAD(x) (x * (PI / 180.0f))
#define RAD2DEG(x) (x * (180.0f / PI))
enum DeformMode
{
Raise = 0,
Lower,
};
class TerrainFrameListener : public ExampleFrameListener, public MouseListener, public MouseMotionListener{
private:
Ogre::SceneManager * m_SceneMgr;
CEGUI::Renderer *m_Renderer;
const static short AMOUNT_CURSOR_POINTS=360;
unsigned int mCursorSize;
Vector3 mCursorPoints[AMOUNT_CURSOR_POINTS+1];
Line3D* mCursor;
unsigned int mBrushSize;
float mBrushStrength;
RaySceneQuery* mRayQuery;
RaySceneQuery* mRayCursorQuery;
SceneNode* mMainSceneNode;
SceneNode* mCursorNode;
Vector3 mCursorPos;
DeformMode m_dfm;
bool mClickActive;
public:
TerrainFrameListener( Ogre::RenderWindow *mWindow,Ogre::Camera* mCamera, Ogre::SceneManager * SceneManager,CEGUI::Renderer *renderer):ExampleFrameListener(mWindow,mCamera,false,true),m_SceneMgr(SceneManager),m_Renderer(renderer){
mMainSceneNode = m_SceneMgr->getRootSceneNode()->createChildSceneNode();
mCursorNode = mMainSceneNode->createChildSceneNode();
mClickActive = false;
mRayQuery = m_SceneMgr->createRayQuery(Ray(Vector3::ZERO, Vector3::NEGATIVE_UNIT_Y));
mRayCursorQuery = m_SceneMgr->createRayQuery(Ray(Vector3::ZERO, Vector3::NEGATIVE_UNIT_Y));
setBrushSize(10);
setDeformMode(Lower);
setBrushStrength(0.0002f);
// Register this so that we get mouse events.
mEventProcessor->addMouseListener( this );
mEventProcessor->addMouseMotionListener(this);
}
bool frameEnded(const FrameEvent& evt)
{
ExampleFrameListener::frameEnded(evt);
//ExampleFrameListener::
if (mClickActive)
{
std::cout << mBrushStrength<< std::endl;
//BUG HERE
m_SceneMgr->setOption( "DeformationCenter", &mCursorPos);
}
return true;
}
/* MouseListener callbacks. */
virtual void mouseClicked(MouseEvent* e) {}
virtual void mouseEntered(MouseEvent* e) {}
virtual void mouseExited(MouseEvent* e) {}
// This is when the mouse button goes DOWN.
virtual void mousePressed(MouseEvent* e)
{
std::cout << "Mouse Pressed! " << std::endl;
mClickActive= true;
} // mousePressed
// This is when the mouse button is let UP.
virtual void mouseReleased(MouseEvent* e)
{
mClickActive= false;
} // mouseReleased
/* MouseMotionListener callbacks */
virtual void mouseMoved (MouseEvent *e)
{
//std::cout << "Mouse Moved! " << std::endl;
// Update CEGUI with the mouse motion
CEGUI::System::getSingleton().injectMouseMove(e->getRelX() * m_Renderer->getWidth(), e->getRelY() * m_Renderer->getHeight());
const Ray pickRay = mCamera->getCameraToViewportRay(e->getX(), e->getY());
mRayCursorQuery->setRay (pickRay);
mRayCursorQuery->setQueryMask (RSQ_FirstTerrain); //PLSM2 only
RaySceneQueryResult& qryResult = mRayCursorQuery->execute();
RaySceneQueryResult::iterator it = qryResult.begin();
if (it != qryResult.end() && it->worldFragment)
{
mCursorPos = it->worldFragment->singleIntersection;
}
bool doattach = false;
if (!mCursor)
{
mCursor = new Line3D (AMOUNT_CURSOR_POINTS);
doattach = true;
} // if (!mCursor)
//Define the position of the points that form the cursor
Ray cameraRay( Vector3::ZERO, Vector3::NEGATIVE_UNIT_Y );
RaySceneQueryResult result;
RaySceneQueryResult::iterator itr;
mRayCursorQuery->setQueryMask (RSQ_Height); //PLSM2 only
for(uint i = 0; i <= AMOUNT_CURSOR_POINTS; i++)
{
cameraRay.setOrigin (Vector3(mCursorPos.x + mCursorPoints[i].x,
500.0f,
mCursorPos.z + mCursorPoints[i].z));
mRayCursorQuery->setRay( cameraRay );
// Perform the scene query
result = mRayCursorQuery->execute();
itr = result.begin( );
if ( itr != result.end() && itr->worldFragment )
{
const Real terrainHeight = itr->worldFragment->singleIntersection.y;
mCursorPoints[i].y = terrainHeight;
}
else
{
mCursorPoints[i].y = 0.0f;
}
}
//mCursor->updateLine (mCursorPoints);
if (doattach)
{
mCursorNode->detachAllObjects();
mCursorNode->attachObject(mCursor);
}
mCursorNode->setPosition(Vector3(mCursorPos.x, 0.0f, mCursorPos.z));
e->consume();
}
// This is when the mouse is clicked, held and dragged.
virtual void mouseDragged (MouseEvent *e)
{
mouseMoved(e);
//Rotate camera
mCamera->yaw(Radian( -e->getRelX() * mRotateSpeed ));
mCamera->pitch(Radian( -e->getRelY() * mRotateSpeed ));
e->consume();
} // mouseDragged
void setBrushStrength(float value){
mBrushStrength = value;
if(m_dfm == Raise){
float val = mBrushStrength;
m_SceneMgr->setOption("BrushScale", &val);
}else{
float val = -mBrushStrength;
m_SceneMgr->setOption("BrushScale", &val);
}
}
void setDeformMode(DeformMode df){
m_dfm = df;
setBrushStrength(mBrushStrength);
}
void setBrushSize(const int value)
{
mBrushSize = value;
m_SceneMgr->setOption("BrushSize", &mBrushSize);
//Initialise the "cursorPoints"
mCursorPoints[0] = Vector3(mBrushSize*8, 0.0f, 0.0f);
const float pointsangle = 360 / AMOUNT_CURSOR_POINTS;
const Real x = mCursorPoints[0].x;
const Real z = mCursorPoints[0].z;
for(int i=2; i <= AMOUNT_CURSOR_POINTS; i++)
{
const float radAngle = DEG2RAD((i-1)*(pointsangle));
const float cosAngle = cos(radAngle);
const float sinAngle = sin(radAngle);
mCursorPoints[i-1] =
Vector3(x*cosAngle + z*sinAngle, 0.0f, -x*sinAngle + z*cosAngle);
}
mCursorPoints[AMOUNT_CURSOR_POINTS] = mCursorPoints[0];
}
};
#endif
Maybe I made a mistake :'(, Could you help me please!
Syphius.