OpenGL model

Jim Brown

Active Member
Licensed User
Longtime User
See if this method works (Rotate first then Translate) ..

B4X:
gl.PushMatrix
gl.Rotate(0.5 , 0,1,0)
gl.Translate(0,0,-6)
gl.PopMatrix
 
Upvote 0

Mikie

Member
Licensed User
Longtime User
Jim,

Are you trying to create a game?

By the way Jim, thanks for turning me on to b4a.

Mikie
 
Upvote 0

Kamac

Active Member
Licensed User
Longtime User
Yes, it's very helpful, but i know that.

But my problem is different, have a look at the .apk attached, to see what do i mean.

I can rotate properly around player's Y axis, but only on position 0.0,0.0,0.0, after i move forward, he starts to rotate around some circle around the 0.0,0.0,0.0 point.
 
Upvote 0

Jim Brown

Active Member
Licensed User
Longtime User
>> Are you trying to create a game?
Hi Mikie,
I had in mind of creating something similar to My Paper Plane 2 in the Android Market. Its a personal favourite of mine. I still need additional OpenGL functionality though (such as collisions between objects)

@Kamac - No APK attached, but do you have any source code example?
 
Upvote 0

Kamac

Active Member
Licensed User
Longtime User
Sure.

B4X:
Sub glsv_Draw(gl As GL1)
   gl.glClearColor(0.1,0.35,0.6,1)
   gl.glClear(Bit.Or(gl.GL_COLOR_BUFFER_BIT, gl.GL_DEPTH_BUFFER_BIT))
   ' cube - textured
   gl.glLoadIdentity : gl.glScalef(0.5,0.5,0.5)
   gl.glTranslatef(0.0,-1.2,distZ)
   gl.glRotatef(rotX,0.0,0,0.0)
   gl.glRotatef(rotY,0,1,0.0)
   'gl.glRotatef(rotY,0,1,distZ)
   GLObject_Draw(obj1,gl)
   GLObject_Draw(obj2,gl)
   GLObject_Draw(skyboxx,gl)
   
   DrawTrees(gl)
   DrawObjects(gl)
End Sub

I believe here lays the problem.

B4X:
   gl.glLoadIdentity : gl.glScalef(0.5,0.5,0.5)
   gl.glTranslatef(0.0,-1.2,distZ)
   gl.glRotatef(rotX,0.0,0,0.0)
   gl.glRotatef(rotY,0,1,0.0)

These commands "position my camera" in the world (so actually they move the whole world i guess)

Link to the application: http://www.speedyshare.com/files/30290412/scenetest.apk
 
Last edited:
Upvote 0

Jim Brown

Active Member
Licensed User
Longtime User
> Thanks Jim for the conversion tool. Does it support animated .x files?
alwaysbusy,
There is no animation support (yet). I have not looked into how best to implement the frames of animation data

Kamac
I believe this is the sort of thing you are trying to achieve?
I used glGluLookAt to get the desired behaviour. See attached OpenGLRotateExample.zip

> --- Run the demo. You should see a red barrel on the left and green barrel to the right
> --- Slide finger horizontally to rotate around objects

B4X:
Sub glsv_Draw(gl As GL1)
       ......
   ' reset the scene
   gl.glLoadIdentity
   ' ===================
   ' CAMERA
   ' ===================
   ' set camera to 'look' at certain position
   ' EYE 0,6,9   CENTER 0,0,0   VECTOR 0,1,0
   gl.gluLookAt(0,6,9 , 0,0,0 , 0,1,0)
   ' perform rotation in Y axis
   gl.glRotatef(rotY,0,1,0)
   ' ===================
   ' draw first object
   ' ===================
   gl.glPushMatrix
   gl.glTranslatef(1.1,0,distZ)
   gl.glColor4f(0.6,1,0.6 , 1) ' green barrel colour
   GLObject_Draw(obj1,gl)
   gl.glPopMatrix
   ' ===================
   ' draw second object
   ' ===================
   gl.glPushMatrix
   gl.glColor4f(1,0.2,0.2 , 1) ' red barrel colour
   gl.glTranslatef(-1.1,0,distZ)
   GLObject_Draw(obj2,gl)
   gl.glPopMatrix
End Sub
 

Attachments

  • OpenGLRotateExample.zip
    159.4 KB · Views: 342
Last edited:
Upvote 0

Jim Brown

Active Member
Licensed User
Longtime User
Your link is broken

Have a look at my new example though. There are two move methods there which let you move around a scene

Move via sliding in all directions
This is basically a doom-style move (WASD) if you follow me?
Sliding left/right or forward/back moves you around the scene without rotation

Move via rotate Y and slide Z
This moves your around by sliding forward and back but rotating for left/right
If this second method does not behave as you expect swap the order of the commands as indicated ** here:
B4X:
   '   "Move via sliding in all directions"
   If tog_MoveMethod.Checked=False Then
      gl.glTranslatef(mX,yHeight,mY)
   Else
      ' "Move via rotate Y and slide Z"
      gl.glRotatef(-mX,0,1,0)                        <--- Swap these **
      gl.glTranslatef(0,yHeight,mY)                <--- Swap these **
   End If
 

Attachments

  • OpenGLMoveExample.zip
    159.2 KB · Views: 327
Upvote 0

grobi71

Member
Licensed User
Longtime User
converter does not work for me

Hallo,

i tried to make my own 3d model with blender and exported it as directx .x File
i tried to open it in the converter but got the following error:
Mesh index not found in .x model

blender version 2.61
Directx export from Chris Forste Version 2.12

after closing the error Message i can see the cube without texture.

also i tried DeleD 3d Editor version 2.45 CE. After export to Directx format and opening in ModelUtil1.0 it opens without any error, but also without texture.

Also it is only possible to export one Object at a time.If i use a .x file with 2 or more Objects it shows only one Object in ModelUtil1.0

Can i only use Wings3d?
What do i wrong ?

happy new year
Grobi
 
Last edited:
Upvote 0

boten

Active Member
Licensed User
Longtime User
Have NO experience in OpenGL, so I tried the sample you provided. Worked fine.
Then I tried to alter the dicemap.png. Resized it by a factor of 2 (256x256) and it worked fine.
Then I tried a factor of 3 (384x384) and a strange thing happened:
On the emulator it worked fine, but on the phone (SGS) all the surfaces were WHITE! - any explanation?

BTW - Can you provide a model & map for a dice with NO bevels - Just 6 sides?
 
Upvote 0
Top