Author Topic: Is wSetCameraTarget wrong?  (Read 389 times)

0 Members and 1 Guest are viewing this topic.

Offline jepalza

  • Friends
  • Gentleman (Lady)
  • *
  • Posts: 42
  • Reputation 5
  • 3D Crazy
Is wSetCameraTarget wrong?
« on: October 21, 2015, 12:23:34 PM »
In this simple example, ir order to put camera in fixed position, and then change target, at firts time, reading values are wrong. Did will must read "50,70,100", but "50,70,-29" is read back.
When push "1" key to change to new random position, camera position is good, but target position is wrong again and again.

It's a fail or maybe did make anything wring?  :(

Code: [Select]

#include "WorldSim3D.bi"

dim bspmesh as wmesh
Dim bspnode as wnode
Dim camera as wcamera
dim cameranode as wnode

' variables de rotacion de camara
dim xcamrot as single
dim ycamrot as single
dim zcamrot as Single
' variables del objetivo de la camara
dim xcamobj as single
dim ycamobj as single
dim zcamobj as Single
' variables de posicion de camara
dim xcampos as single
dim ycampos as single
dim zcampos as Single
' variables para impresion de informacion en pantalla
Dim nodpos as wstring * 256
dim camrot as wstring * 256
dim camobj as wstring * 256

dim keyevent as wkey_event ptr

wstart( wDT_DIRECT3D9, 320, 240, wbits_per_pixel_32, _
        wwindowed, wshadows , wcapture_events, wvertical_sync_on )

Camera = wAddFPSCamera
cameranode = camera

dim as single x,y,z
x=50:y=70:z=100

' initial position and target
wsetnodeposition( cameranode, x, y, z+10 )
wsetcameratarget( cameranode, x, y, z )
print "initial values:"
print "node position:";x,y,z+10
print "node target  :";x,y,z

dim bitmapfont as wfont
bitmapfont = wgetfont ( "./media/fonthaettenschweiler.bmp" )
  x=1:y=7:z=10
while wrunning

   wbeginscene( 0, 0, 0 )
       
        wgetnodeposition( cameranode, xcampos, ycampos, zcampos )
        wgetnoderotation( cameranode, xcamrot, ycamrot, zcamrot )
        wgetcameratarget( cameranode, xcamobj, ycamobj, zcamobj )
           
        nodpos = "POSICION "+str(xcampos)+" , "+Str(ycampos)+" , "+Str(zcampos)
        camrot = "ANGULOS  "+str(xcamrot)+" , "+Str(ycamrot)+" , "+Str(zcamrot)
        camobj = "OBJETIVO "+str(xcamobj)+" , "+Str(ycamobj)+" , "+Str(zcamobj)

        wdrawscene
       
       w2dfontdraw ( bitmapfont, nodpos , 4,  4, 250, 24 )
       w2dfontdraw ( bitmapfont, camrot , 4, 24, 250, 24 )
       w2dfontdraw ( bitmapfont, camobj , 4, 44, 250, 24 )
       
  wendscene
 
        while wkeyeventavailable
   
            keyevent = wreadkeyevent
            select case as const keyevent->key

               case key_key_1
                  x=int(rnd(1)*256)
                  y=int(rnd(1)*256)
                  z=int(rnd(1)*256)
            PRINT " New position --> ";x;" "; y;" "; z;" "         
                  wsetnodeposition( cameranode, x, y, z+10 )
                  wsetcameratarget( cameranode, x, y, z )   '''''' ARE WRONG VALUES READ????
                     
            case key_escape
                end
               
            end select
        Wend


Wend
wstop

Offline Alec - WS3D Developer

  • Producer
  • Administrator
  • Viscount
  • *
  • Posts: 786
  • Reputation 30
  • Game making is my hobby for life!
Re: Is wSetCameraTarget wrong?
« Reply #1 on: October 21, 2015, 06:33:37 PM »
Ok, I'm not sure I fully understand your code, but the problem can be because of mess with variables. I think you should not use the same variables for positions and targets like in these lines:

dim as single x,y,z
x=50:y=70:z=100

' initial position and target
wsetnodeposition( cameranode, x, y, z+10 )
wsetcameratarget( cameranode, x, y, z )  < here you make the camera point to itself, target to its own position

and also here:

wsetnodeposition( cameranode, x, y, z+10 )
wsetcameratarget( cameranode, x, y, z )

You define a position to the camera and then point it to this position, using the same variables: x, y, z?

 
Quote
camera position is good, but target position is wrong again and again.
How do you know that the camera's target values are wrong? What values do you expect in this case? Which values are correct and which wrong?
« Last Edit: October 21, 2015, 06:36:23 PM by Alec - WS3D Developer »
WorldSim3D = 3D + FreeBasic. Программируй в удовольствие, а не "в тягость"! Make your project with pleasure, not with strain!

Offline jepalza

  • Friends
  • Gentleman (Lady)
  • *
  • Posts: 42
  • Reputation 5
  • 3D Crazy
Re: Is wSetCameraTarget wrong?
« Reply #2 on: October 21, 2015, 10:33:13 PM »
 
Quote
How do you know that the camera's target values are wrong? What values do you expect in this case? Which values are correct and which wrong?
It's easy: if X=100;Y=100;Z=100, when make setnode position XYZ, and setcameratarget XYZ (sames values), when read it, it MUST be X=100;Y=100;Z=100   or not?

But goes to probe with different variables for target and position. I'm Testing it

--------------------------------------------------------------------------------------------
Edit: Something is wrong, not run .
Look, very easy to explain:
x=100:Y=100:Z=100
x2=100:Y2=100:Z2=200
nodepostion X,Y,Z
cameratarget X2,Y2,Z2
At this point, all ok.
Then read back values (without move or rotate mouse position)
getnodeposition --> x=100, y=100, z=100 (OK)
gettargetposition --> x2=100, y2=100, z2=random value!!! (Z2 is not correct)

Try this new example:
Code: [Select]
#include "WorldSim3D.bi"

Dim camera as wcamera
dim cameranode as wnode

' rotacion
dim xcamrot as single
dim ycamrot as single
dim zcamrot as Single
' objetivo
dim xcamobj as single
dim ycamobj as single
dim zcamobj as Single
' posicion
dim xcampos as single
dim ycampos as single
dim zcampos as Single
' string
Dim nodpos as wstring * 256
dim camrot as wstring * 256
dim camobj as wstring * 256

dim keyevent as wkey_event ptr

wstart( wDT_DIRECT3D9, 320, 240, wbits_per_pixel_32, _
        wwindowed, wshadows , wcapture_events, wvertical_sync_on )

Camera = wAddFPSCamera
cameranode = camera

' example values
dim as single x,y,z
dim as single x2,y2,z2
x=100:y=100:z=100
x2=100:y2=100:z2=110

' initial position and target (OUT TO CONSOLE)
wsetnodeposition( cameranode, x, y, z )
wsetcameratarget( cameranode, x2, y2, z2 )
print "initial values:"
print "node position:";x,y,z
print "node target  :";x2,y2,z2

dim bitmapfont as wfont
bitmapfont = wgetfont ( "../../media/fonts/bitmapfont.bmp" )

while wrunning

   wbeginscene( 0, 0, 0 )
       
        wgetnodeposition( cameranode, xcampos, ycampos, zcampos )
        wgetnoderotation( cameranode, xcamrot, ycamrot, zcamrot )
        wgetcameratarget( cameranode, xcamobj, ycamobj, zcamobj )
           
        nodpos = "POSICION "+str(xcampos)+" , "+Str(ycampos)+" , "+Str(zcampos)
        camrot = "ANGULOS  "+str(xcamrot)+" , "+Str(ycamrot)+" , "+Str(zcamrot)
        camobj = "OBJETIVO "+str(xcamobj)+" , "+Str(ycamobj)+" , "+Str(zcamobj)

        wdrawscene
       
       w2dfontdraw ( bitmapfont, nodpos , 4,  4, 250, 24 )
       w2dfontdraw ( bitmapfont, camrot , 4, 24, 250, 24 )
       w2dfontdraw ( bitmapfont, camobj , 4, 44, 250, 24 )
       
  wendscene
 
        while wkeyeventavailable
   
            keyevent = wreadkeyevent
            select case as const keyevent->key

               case key_key_1
                  x+=1 'int(rnd(1)*256)
                  y+=1 'int(rnd(1)*256)
                  z+=1 'int(rnd(1)*256)
                  x2+=1
                  y2+=1
                  z2+=1
            PRINT " New position --> ";x;" "; y;" "; z;" "         
                  wsetnodeposition( cameranode, x, y, z )
                  wsetcameratarget( cameranode, x2, y2, z2 )   '''''' ARE WRONG VALUES READ????
                     
            case key_escape
                end
               
            end select
        Wend


Wend
wstop

Compile it with "windows console" ir order to view in cosole out some values, and in graphics screen nodes values.
And compare it. Push "1" key on keyboard to increase values by 1, and look results.
Maybe i'm wrong in anything, but don't know where.

Input and output (write and read( values MUST be same, no diferences. (note, without move mouse)
« Last Edit: October 21, 2015, 11:03:21 PM by jepalza »