BASIC

Author Topic: need help for my RPG style game  (Read 3604 times)

Offline genbasic

  • Mc. Print
  • *
  • Posts: 13
    • View Profile
need help for my RPG style game
« on: 2010-Jun-18 »
hello all, i newbie here.

i create 3D RPG style game with glbasic.
the style is point n click movement, but still in progress now.
i got some problem with X_SCREEN2WORLD syntax.
i very clear at X_WORLD2SCREEN syntax, n i got right return value with that,
but not from X_SCREEN2WORLD syntax. this syntax give me wrong return value.

i know, X_WORLD2SCREEN syntax is for converts 3D coordinates to 2D screen coordinates, and
X_SCREEN2WORLD syntax for converts 2D screen coordinates to 3D coordinates.

only with X_SCREEN2WORLD syntax i got wrong return value. is that bug or what?
or maybie all of u have sample code for that? or alternative code or something?

pls help me...

thx

( sry for my bad english, i'm from indonesia  =D )

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10682
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: need help for my RPG style game
« Reply #1 on: 2010-Jun-18 »
It should work. Make sure you call that after X_MAKE3D and after X_CAMERA.
Just perform an X_LINE with the coordinated returned to check if it's OK.
If not, make a small example program.

Offline genbasic

  • Mc. Print
  • *
  • Posts: 13
    • View Profile
Re: need help for my RPG style game
« Reply #2 on: 2010-Jun-18 »
It should work. Make sure you call that after X_MAKE3D and after X_CAMERA.
Just perform an X_LINE with the coordinated returned to check if it's OK.
If not, make a small example program.

thx for reply.

here my sample source:

Code: GLBasic [Select]
//== INIT ==
GLOBAL mouse_stat_x,mouse_stat_y,mouse_stat_a,mouse_stat_b,screen_x,screen_y,screen_z
SETCURRENTDIR("Media")
//==========

//== TERRAIN ==
// terrain object
X_OBJSTART 0
        f=RGB(255,255,255)
        X_OBJADDVERTEX -2000,0,-2000,  0 ,0,f
        X_OBJADDVERTEX  2000,0,-2000, 50, 0,f
        X_OBJADDVERTEX -2000,0, 2000,  0,50,f
        X_OBJADDVERTEX  2000,0, 2000, 50,50,f
X_OBJEND
// terrain texture
LOADSPRITE "gras.bmp", 0
//=============


//== MOUSE CURSOR IMAGE ==
LOADSPRITE "cursor.png", 1
//========================

//== 3d object - Sphere ==
CreateSphere(2, 5, 15, RGB(255, 0, 0));
//========================


//== MAIN LOOP ==
WHILE TRUE
        //DRAWRECT 0,0,640,480,RGB(0,255,255)
        X_MAKE3D 1, 1200, 45
        X_CAMERA 100,100,100,0,0,0
        X_DRAWAXES 0,0,0
       
        //-- terrain --
        X_MOVEMENT 0,0,0
        X_SETTEXTURE 0, -1
        X_DRAWOBJ 0,0

        //-- put 3D object sphere for init coordinate
        X_DRAWOBJ 2,0

        //-- move 3D object Sphere at mouse XY [left click event]
//      IF MOUSEAXIS(3)
//      ENDIF

        //-- get mouse stat     --
        MOUSESTATE mouse_stat_x,mouse_stat_y,mouse_stat_a,mouse_stat_b
        //-- convert mouse screen coordinat to 3d world
        X_SCREEN2WORLD mouse_stat_x,mouse_stat_y,0,screen_x,screen_y,screen_z

        //-- 2D part --
        X_MAKE2D
       
        //-- text font output --
        LOADFONT "font.png", 1
        SETFONT 1
        PRINT "Screen XY : " + mouse_stat_x +"/"+mouse_stat_y, 0,  0
        PRINT "3Dworld XY: "+INTEGER(screen_x)+"/"+INTEGER(screen_y)+"/"+INTEGER(screen_z), 0 ,15

        //-- mouse cursor image -> move by mouse stat coordinate
        ZOOMSPRITE 1,mouse_stat_x,mouse_stat_y,0.5,0.5

        SHOWSCREEN
WEND
//===============

END


//== FUNCTION ==
FUNCTION CreateSphere: num, r, n, col
LOCAL i,j, theta1, theta2, theta3, pi
        pi = ACOS(0)*2
        IF r < 0 THEN r = -r
        IF n < 3 THEN n = 3

        X_OBJSTART num
        FOR j=0 TO n/2-1

                theta1 = j * 2*pi / n - pi/2;
                theta2 = (j + 1) * 2*pi / n - pi/2;
                FOR i=0 TO n
                        theta3 = i * 2*pi / n;
                        X_OBJADDVERTEX  r*COS(theta2) * COS(theta3), r*SIN(theta2), _
                                                        r*COS(theta2) * SIN(theta3), i/n, 2*(j+1)/n, col
                        X_OBJADDVERTEX  r*COS(theta1) * COS(theta3), r*SIN(theta1), _
                                                        r*COS(theta1) * SIN(theta3), i/n, 2*j/n, col
                NEXT
                X_OBJNEWGROUP
        NEXT
        X_OBJEND
ENDFUNCTION
//==============
 

picture:


Offline genbasic

  • Mc. Print
  • *
  • Posts: 13
    • View Profile
Re: need help for my RPG style game
« Reply #3 on: 2010-Jun-18 »
now i understand.

with "X_LINE" returned right value, thx for help  :D.

#at my sample above, i was use "print" to show value at 2D text, thats wrong way.

but...
thats coordinate not what i mean. i must get coordinat at 3D terrain, this is for target movement for my char object. maybie i must calc for that ( using Trigonometry, ach..  :'( )
« Last Edit: 2010-Jun-18 by genbasic »

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10682
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: need help for my RPG style game
« Reply #4 on: 2010-Jun-24 »
After the SCREEN2WORLD use the gained vectors and do an X_COLLISIONRAY on the ground. You get the length of the "direction" from that point to the collision point. Then simply do:
mouse_pos_3d + mouse_z_direction * distance_to_collision
and you have the 3D point of the mesh under the mouse.

Offline genbasic

  • Mc. Print
  • *
  • Posts: 13
    • View Profile
Re: need help for my RPG style game
« Reply #5 on: 2010-Jun-25 »
After the SCREEN2WORLD use the gained vectors and do an X_COLLISIONRAY on the ground. You get the length of the "direction" from that point to the collision point. Then simply do:
mouse_pos_3d + mouse_z_direction * distance_to_collision
and you have the 3D point of the mesh under the mouse.

thx for reply..

but i still not get it   :(, can u show sample code for that? ( full sample code if u mind  =D )

btw, here my game:


i used 3D object as mouse picking, but not from mouse XY screen coordinate  ;).
the problem is, how to pick 2D image on screen like inventory list,menu,spell,etc.
that why i realy need how to convert mouse xy screen to 3D world as mouse pick.

thx b4
« Last Edit: 2010-Jun-25 by genbasic »

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1764
    • View Profile
    • Homepage
Re: need help for my RPG style game
« Reply #6 on: 2010-Jun-25 »
You can't just convert 2D to 3D, you need to figure out where in the world your mousepointer is pointing. And this you do with X_COLLISIONRAY. There is an example with code in the help, look up the command X_COLLISIONRAY.