About Store Forum Documentation Contact



Post Reply 
Interresting By Engine
Author Message
Hirogens Offline
Member

Post: #76
Re: Interresting By Engine
Hi,

Can you help me for translate a LUA Script in C with your lib?

regards

Code:
-- local matrix = dofile (HYP_GetBaseDir() .. "matrix.lua")

Rmax=4000 -- radius of galaxy
Rbar=2000 -- radius of bar
Rker=500 -- radius of kernel

eratio=.8
etwist=7.5
speed = 200

ellipse={}
function update()
   for r=1,Rmax do
      local b=etwist*r/Rmax
      ellipse[r]={}
      ellipse[r].s=r*math.sin(b)
      ellipse[r].c=r*math.cos(b)
      ellipse[r].v=speed/r
      ellipse[r].e=eratio
   end
end

update()

stars = {}
total=0

function init_stars(j,n,size,damp)
   total=total+n
   stars[j]={}
   stars[j].n=n
   stars[j].vp=HYP_VertexPool.Create( n, "pool"..j )
   HYP_Object.SetMaterial( stars[j].vp, "mat"..j )
   HYP_Object.AttachTexture( stars[j].vp, "tex"..j, "mat"..j, 0 )
   HYP_Object.SetTexturingState( stars[j].vp, 1 )
  
   HYP_VertexPool.SetVerticesSize( stars[j].vp, size )
   if not damp then damp={} end
   if not damp[1] then damp[1]=0 end
   if not damp[2] then damp[2]=0.001 end
   if not damp[3] then damp[3]=0 end
  
   HYP_VertexPool.SetPointSpriteDistAtt( stars[j].vp, damp[1],damp[2],damp[3] )
  
   HYP_Object.SetBlendingState( stars[j].vp , 1 );
   HYP_Object.SetBlendingFactors( stars[j].vp, 1, 1 )
   stars[j].data= {}
   for i = 1, n do
      local a=2.0*math.pi*math.random()
      local r=math.random(Rmax)
      stars[j].data[i]={a=a,r=r}
      local e= 30 -- thickness
      if r<Rker then e=e+math.sqrt(Rker*Rker-r*r)/2 end
      HYP_VertexPool.SetVertexPosition( stars[j].vp, i-1 , 0,0,2*e*math.random()-e )
   end
end

init_stars(1,8000,128);
init_stars(2,1000,16);
init_stars(3,1000,16);
init_stars(4,1000,16);
init_stars(5,1000,16);
init_stars(6,1000,16);
init_stars(7,1000,16);
init_stars(8,1000,16);

function frame()
   local time_step = HYP_GetTimeStep();
   for j,v in ipairs(stars) do
      for i,star in ipairs(v.data) do
         local x, y, z = HYP_VertexPool.GetVertexPosition_Fast( v.vp, i-1);
         local e=ellipse[star.r]
         star.a=star.a+time_step*e.v
         x = math.sin(star.a)
         y = e.e*math.cos(star.a)
         HYP_VertexPool.SetVertexPosition_Fast( v.vp, i-1 , e.s*x+e.c*y,e.c*x-e.s*y,z )
      end
   end
   for i=1,10 do -- cycle stars in the vertex pools to mimic star evolution
      local start=1
      local i1=math.random(stars[start].n)
      local a=stars[start].data[i1].a
      local r=stars[start].data[i1].r
      local x, y, z = HYP_VertexPool.GetVertexPosition_Fast( stars[start].vp, i1-1);
      for j=start+1,#stars do
          local i2=math.random(stars[j].n) -- star to swap with
          local x, y, z = HYP_VertexPool.GetVertexPosition_Fast( stars[j].vp, i2-1);
         stars[j-1].data[i1]=stars[j].data[i2]
         HYP_VertexPool.SetVertexPosition_Fast( stars[j-1].vp, i1-1 , x,y,z )
         i1=i2
      end
      stars[#stars].data[i1]={a=a,r=r} -- add a supernova here one day
      HYP_VertexPool.SetVertexPosition_Fast( stars[#stars].vp, i1-1 , x,y,z )
   end
   HYP_DrawText( 60, 25, 1.0, .5, .1, total);
   HYP_DrawText( 100, 45, 1.0, .5, .1, string.format("%.3f", eratio) );
   HYP_DrawText( 100, 65, 1.0, .5, .1, string.format("%.3f", etwist) );
end
11-29-2008 10:11 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #77
Re: Interresting By Engine
Hello,

The engine doesn't support natively LUA scripts,
the easiest way would be to rewrite the lines into c++ commands, or manually add support for LUA
11-29-2008 04:42 PM
Find all posts by this user Quote this message in a reply
Hirogens Offline
Member

Post: #78
Re: Interresting By Engine
Esenthel Wrote:Hello,

The engine doesn't support natively LUA scripts,
the easiest way would be to rewrite the lines into c++ commands, or manually add support for LUA

No, just convert in C.
I hate LUA...

One question,

Can you explain me the "MyImage2D.draw(x,y,w,h);"
just x,y,w,h ?!! what the limits ?

I want draw many 2d Images...

Example of my game layers

Layer 1 : 2D Background,
Layer 2 : some 2D GFX
Layer 3 : some 2D GFX
Layer 4 : some Viewport 3D
Layer 5 : some 2D GFX
Layer 6 : some Viewport 3D
Layer 7 : some 2D GFX
Layer 8 : some Gui interface
Layer 9 : some 2D GFX
Layer 10 : some Viewport 3D
Layer 11 : some 2D GFX
Layer 12 : some Gui interface
Layer 13 : some 2D GFX

Regards
11-29-2008 08:20 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #79
Re: Interresting By Engine
Hi,

What limits do you have in mind?
X,Y are the screen coordinates,
W,H are the image width and height,
there are lots of other drawing functions, you can check the Gfx.h header file for more info.

Let me know if that helps.
11-30-2008 02:31 PM
Find all posts by this user Quote this message in a reply
Hirogens Offline
Member

Post: #80
Re: Interresting By Engine
Esenthel Wrote:Hi,

What limits do you have in mind?
X,Y are the screen coordinates,
W,H are the image width and height,
there are lots of other drawing functions, you can check the Gfx.h header file for more info.

Let me know if that helps.

Gfx BackGroung;
BackGroung.Import("./TitleBack.jpg",-1,GFX_2D);

BackGroung.drawFs(); // Work perfect

But

BackGroung.draw(0,0,1024,768); // don't Work.. no image drawing

regards
11-30-2008 04:46 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #81
Re: Interresting By Engine
Hi,

2D coordinates are not in pixel coordinates, but in screen coordinates.
x range from -D.w() to D.w()
y range from -D.h() to D.h()

these ranges are approximately:
x from -1.3 to 1.3 (this changes due to different aspect ratios)
y from -1.0 to 1.0 (this range is constant unless you specify a different aspect ratio mode calculations)

you should use something like this : gfx.draw(0.0,0.0, 1.0,1.0);
11-30-2008 05:08 PM
Find all posts by this user Quote this message in a reply
Hirogens Offline
Member

Post: #82
Re: Interresting By Engine
Esenthel Wrote:Hi,

2D coordinates are not in pixel coordinates, but in screen coordinates.
x range from -D.w() to D.w()
y range from -D.h() to D.h()

these ranges are approximately:
x from -1.3 to 1.3 (this changes due to different aspect ratios)
y from -1.0 to 1.0 (this range is constant unless you specify a different aspect ratio mode calculations)

you should use something like this : gfx.draw(0.0,0.0, 1.0,1.0);

My JPG => 1024/768

gfx.draw(0.0,0.0, 1.0,1.0) => Draw only 1/8 screen size, any position..


regards
11-30-2008 06:45 PM
Find all posts by this user Quote this message in a reply
Hirogens Offline
Member

Post: #83
Re: Interresting By Engine
Original
<!-- m --><a class="postlink" href="http://www.wormhole-the-game.com/TitleBack.jpg">http://www.wormhole-the-game.com/TitleBack.jpg</a><!-- m -->

Result
<!-- m --><a class="postlink" href="http://www.wormhole-the-game.com/TEST.jpg">http://www.wormhole-the-game.com/TEST.jpg</a><!-- m -->

regards
11-30-2008 06:52 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #84
Re: Interresting By Engine
Hi,
if you want to manually stretch into fullscreen you should use following code:

gfx.draw(-D.w(), D.h(), D.w()*2, D.h()*2);
11-30-2008 08:32 PM
Find all posts by this user Quote this message in a reply
Hirogens Offline
Member

Post: #85
Re: Interresting By Engine
Esenthel Wrote:Hi,
if you want to manually stretch into fullscreen you should use following code:

gfx.draw(-D.w(), D.h(), D.w()*2, D.h()*2);

Ok work,

but my probleme for make position for a 2D Gfx.

if my JPG make for example 200/100 px

and position on screen 354/132 (just for example)

how do make this

regards
12-01-2008 12:40 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #86
Re: Interresting By Engine
you can use pixel<->screen coordinates transformations using these functions

struct Display
{
static VecI2 screenToPixel(Vec2 &screen); // from screen to pixel ( 0 .. D.x, 0 .. D.y)
static RectI screenToPixel(Rect &screen); // from screen to pixel ( 0 .. D.x, 0 .. D.y)
static Vec2 pixelToScreen(VecI2 &pixel ); // from pixel to screen (-D.w .. D.w, -D.h .. D.h)
static Rect pixelToScreen(RectI &pixel ); // from pixel to screen (-D.w .. D.w, -D.h .. D.h)
}D;
12-01-2008 01:07 AM
Find all posts by this user Quote this message in a reply
Hirogens Offline
Member

Post: #87
Re: Interresting By Engine
I have make this procedure, but don't work,
can you explain me the coordiante systeme ?


Code:
void DrawImage(Gfx *MyGFX, Int PosX, Int PosY)
{
    Vec2 w_MyGFXPosConvert;
    Vec2 w_MyGFXSizeConvert;  
    VecI2 w_PosPixel;
    VecI2 w_SizePixel;

    w_PosPixel.x = PosX;
    w_PosPixel.y = PosY;
    w_MyGFXPosConvert = D.pixelToScreen( w_PosPixel );
    w_SizePixel.x = MyGFX->x();
    w_SizePixel.y = MyGFX->y();
    w_MyGFXSizeConvert = D.pixelToScreen( w_SizePixel );

    MyGFX->draw(w_MyGFXPosConvert.x, w_MyGFXPosConvert.y, w_MyGFXSizeConvert.x, w_MyGFXSizeConvert.y);
}
12-01-2008 10:13 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #88
Re: Interresting By Engine
Hi,

The D.pixelToScreen is ok for positions:
Code:
w_PosPixel.x = PosX;
   w_PosPixel.y = PosY;
   w_MyGFXPosConvert = D.pixelToScreen( w_PosPixel );

but it's not ok for sizes:
Code:
w_SizePixel.x = MyGFX->x();
   w_SizePixel.y = MyGFX->y();
   w_MyGFXSizeConvert = D.pixelToScreen( w_SizePixel );

for converting sizes (widths/heights) you should use this function
Code:
Vec2 DPixelToScreenSize(VecI2 &pixel) // in the next version I'll put it into D.pixelToScreenSize
{
   return Vec2(pixel.x * (D.w()*2) / D.x(),
               pixel.y * (D.h()*2) / D.y());
}

Final code would be:

Code:
void DrawImage(Gfx *MyGFX, Int PosX, Int PosY)
{
   Vec2 w_MyGFXPosConvert;
   Vec2 w_MyGFXSizeConvert;
   VecI2 w_PosPixel;
   VecI2 w_SizePixel;

   w_PosPixel.x = PosX;
   w_PosPixel.y = PosY;
   w_MyGFXPosConvert = D.pixelToScreen( w_PosPixel );
   w_SizePixel.x = MyGFX->x();
   w_SizePixel.y = MyGFX->y();
   w_MyGFXSizeConvert = DPixelToScreenSize( w_SizePixel );

   MyGFX->draw(w_MyGFXPosConvert.x, w_MyGFXPosConvert.y, w_MyGFXSizeConvert.x, w_MyGFXSizeConvert.y);
}

For coding practices I would suggest either using reference to Gfx : draw(Gfx &gfx,int posx,int posy), or if using pointer version draw(Gfx *gfx,...) do a check at function start:

Code:
void draw(Gfx *gfx,..)
{
   if(gfx) // this will prevent NULL cases
  {
   ...  
  }
}

However I strongly suggest you shouldn't use pixel coordinates, because it'll all go wrong when you'll change the resolution.
If you're making your graphics in 640x480 screen res, it's ok, and then you'll switch into 1280x960 res, all the graphics will be 2x2 smaller.
You should use screen coordinates (floating point values) which will look the same in each resolution.
12-01-2008 12:06 PM
Find all posts by this user Quote this message in a reply
Hirogens Offline
Member

Post: #89
Re: Interresting By Engine
Hi,

Why can't I add "#include <windows.h>" in my source ?

Many compile error..

I want use the http://www.chilkatsoft.com/downloadVC9.asp Library
(very good lib)

Regards
12-01-2008 02:02 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #90
Re: Interresting By Engine
Hi,

I'll add support for the windows.h in the next engine version, and upload it in 30 minutes
12-01-2008 02:43 PM
Find all posts by this user Quote this message in a reply
Post Reply