Questions about how to code RPG

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Steven04
Posts: 5
Joined: Mon Jun 09, 2008 3:27 pm
Contact:

Questions about how to code RPG

Post by Steven04 »

Hello! :-)
I try to make a very small RPG with Irrlicht. But I use BlitzMax, so it's little bit easier. But I can work with C++ Code.
Here is my intermediate.

And so I have and will have many questions. It will be nice, when you try to answer.

1. Is there a way, to color a Mesh with an easy function? And how can I make a Mesh transparent?

2. I wrote a function, which return the MeshY Position back:

Code: Select all

Function MeshY:Float(x:Float, z:Float)
	Local Start_pos:vector3df = _VECTOR3DF(x, + 3500, z)
	Local End_pos:vector3df = _VECTOR3DF(x, - 200, z)
	Local y:Float
	line.getStart().setEq(Start_pos)
	line.getEnd().setEq(End_pos)
	If (smgr.getSceneCollisionManager().getCollisionPoint( ..
		line, selector, intersection, tri))		
		Driver.SetTransform(ETS_WORLD, Matrix4.Create())
	EndIf
	Return intersection.gety()
End Function
But it isn't so fast, because I must use smgr.drawAll() before it. So, is there an easier way?

3. I try to make realistic water. And so I try to use cube mapping, to reflect realtime the environment. But I don't know, how I should past this 6 "Cameras rendered textures" in one.

4. And are there GLSL/HLSL shader examples? I searched a lot, but I don't find anything.

5. And I use a big terrain. And so I use at the moment a very big colormap. Is there a way, that I can texture a mesh terrain, with more colormaps? Then I can use low quality textures for regions, which are far away.


I hope you understand!:-D

Greetings, Steven
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

1)
i got this source from this forum:

Code: Select all


class CFadeMaterial : public IShaderConstantSetCallBack
{
private:
   f32   m_fadeFactor; // Fade factor 0..1
   s32 m_fadeMaterial; // Handle/id of fade material
public:
   CFadeMaterial() {m_fadeFactor = 1.0f; m_fadeMaterial = EMT_SOLID;};
   bool init(ISceneManager* smgr, IVideoDriver* driver);
   virtual void OnSetConstants(IMaterialRendererServices* services, s32 userData);
public:
   s32 getFadeMaterial(void) {return m_fadeMaterial;};
   f32 getFadeFactor(void) {return m_fadeFactor;};
   void setFadeFactor(f32 fadeFactor) {m_fadeFactor = fadeFactor;};
};

void CFadeMaterial::OnSetConstants(IMaterialRendererServices* services, s32 userData)
{
   IVideoDriver* driver = services->getVideoDriver();

   // World/View/Projection matrix
   core::matrix4 worldViewProj;
   worldViewProj = driver->getTransform(ETS_PROJECTION);         
   worldViewProj *= driver->getTransform(ETS_VIEW);
   worldViewProj *= driver->getTransform(ETS_WORLD);
   services->setVertexShaderConstant("mWorldViewProj", worldViewProj.pointer(), 16);

   services->setPixelShaderConstant("fadeFactor", &m_fadeFactor, 1);
};

bool CFadeMaterial::init(ISceneManager* smgr, IVideoDriver* driver)
{
   if (!smgr || ! driver)
      return false;

   IGPUProgrammingServices *gpu = driver->getGPUProgrammingServices();
   if (!gpu) return false;

   E_DRIVER_TYPE edt = driver->getDriverType();

/*   if (edt == EDT_OPENGL) {
      m_fadeMaterial = gpu->addHighLevelShaderMaterialFromFiles(
         "fademesh.vp", "main", EVST_VS_1_1,
         "fademesh.fp", "main", EPST_PS_1_1,
         this, EMT_TRANSPARENT_ALPHA_CHANNEL);
   } else */if (edt == EDT_DIRECT3D9) {
      m_fadeMaterial = gpu->addHighLevelShaderMaterialFromFiles(
         "data\\shaders\\fademesh.hlsl", "vertexMain", EVST_VS_1_1,
         "data\\shaders\\fademesh.hlsl", "pixelMain", EPST_PS_1_1,
         this, EMT_TRANSPARENT_ALPHA_CHANNEL);
   } else {
      m_fadeMaterial = EMT_SOLID;
   }

   return true;
}

/// and in the shader:

uniform float4x4 mWorldViewProj;
uniform float fadeFactor;
sampler2D diffuseTexture : register(s0);

struct VS_OUT {
   float4 Pos : POSITION;
   float2 TexCoord0 : TEXCOORD0;
};

VS_OUT vertexMain(float3 Pos : POSITION, float2 Tex0 : TEXCOORD0)
{
   VS_OUT o = (VS_OUT)0;
   o.Pos = mul(float4(Pos,1), mWorldViewProj);
   o.TexCoord0 = Tex0;
   return o;
}

float4 pixelMain(VS_OUT i) : COLOR
{
   float4 gl_FragColor;
   gl_FragColor.rgb = tex2D(diffuseTexture, i.TexCoord0.xy);
   gl_FragColor.a = fadeFactor;
   return gl_FragColor;
} 
hope it helps.
2) what are you using for terrain? arras' tiled terrain?
if so, i have source for that.

3) don't know, but are you sure you want to use that? if you're making an RPG, you have to make a big world, and with a realistic water, the FPS will be low..

5)for a big terrain, i suggest you to scale your character, then a smaller is terrrain is good too :P
i'm doing in that way, but i dunno is it good or bad.

dunno the others xD
bye
Steven04
Posts: 5
Joined: Mon Jun 09, 2008 3:27 pm
Contact:

Post by Steven04 »

Thank you, for your answer!
1. Is ok, thx!
2. I use a mesh terrain.
3. Yes, but it should be look a little like real water. ;-)


And I have a new question:
6. How can I move something relative. Because I want turn the Cam and then I should always move front. I know, there is a CameraFPS but it isn't so nice.

Greetings,
Steven
Gogolian
Posts: 32
Joined: Sat May 17, 2008 10:49 pm

Post by Gogolian »

you can always somenode->setParent(someanother) so child node will move with the parent node. If this is not what you want maybe you should try to write your own movement.
And the darkness begun...
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

yeah i think so too.
you have to make your own camera.
i have a movement source, but it isn't perfect, i have to fix it, but if you want i can past here the code.
Steven04
Posts: 5
Joined: Mon Jun 09, 2008 3:27 pm
Contact:

Post by Steven04 »

Yes, it willl be very nice, when you post the code! :-)
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

Code: Select all

	core::position2d<f32> cursorPos = Game.device->getCursorControl()->getRelativePosition();
	scene::ICameraSceneNode* camera = Game.device->getSceneManager()->getActiveCamera();
	core::vector3df cameraPos = camera->getAbsolutePosition();
     
	float xf,yf,zf;
	core::vector3df playerPos = lower->getPosition();
	float change_x = (float)(( cursorPos.X - 0.5 ) * 256.0f);
	float change_y = (float)(( cursorPos.Y - 0.5 ) * 256.0f);
	direction += change_x;
	zdirection -= change_y;
	if( zdirection <- 90 )
		zdirection = -90;
	else
	if( zdirection > 0 )
		zdirection = 0;
    
	Game.device->getCursorControl()->setPosition( 0.5f, 0.5f );
	xf = playerPos.X - cos( (direction+90) * PI / 180.0f ) * zoom/10;
	yf = playerPos.Y - sin( zdirection * PI / 180.0f ) * zoom/10;
	zf = playerPos.Z + sin( (direction+90) * PI / 180.0f ) * zoom/10;
	if (yf < Game.map.getHeight(xf,zf))
		yf = Game.map.getHeight(xf,zf);
	     
	camera->setPosition( core::vector3df( xf, yf, zf ) );
	lower->setRotation( core::vector3df( 0, direction, 0 ) );
here
Steven04
Posts: 5
Joined: Mon Jun 09, 2008 3:27 pm
Contact:

Post by Steven04 »

Ok, it works. Thank you! :)

And I've an other question beacause of texturing the Terrain:
7. I want for example that the top of the terrain is textured by a gras texture and the bottom by a sand texture. Like that. But I want to use min 6 textures. How can I make this? I don't want to work, with a colormap, because it's not sharp enough.

I hope you understand it. ;-)
Thank you for your answers.

Greetings, Steven
Post Reply