Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
S3D : the devil's triangle
#1
The Devil's Triangle

           
click each image to zoom in

Question #1
As you may see in the images above, I found a strange thing with the movement of the pyramid.
When I pressed UP or DOWN, the pyramid followed the plane direction.
What should be changed in the code ?

Question #2
The initial value of
plane.y      = 0
pyramid.y  = 6
But why are the plane and the pyramid in the same horizontal line at the beginning of the game ?

Code:
'=====================================================
'The Devil's Triangle
'
'3D Model :
'Voxel Plane assets by maxparata
'https://maxparata.itch.io/voxel-plane?download
'======================================================

'----------------
' INITIALIZATION
'----------------
include "s3d.n7"; S3D_SetView(primary, rad(45), 0.1, 50)

set window "The Devil's Triangle",800,400,false
set redraw off

'color definition
white = [255,255,255]
black = [0,0,0,120]
gray  = [200,200,200]

'plane
plane = []
plane.model = S3D_LoadMesh("plane/Plane01.obj", 0.5,-0.5,0.5, false)
plane.rotate = 30
plane.x = -5 ; plane.y = 0 ; plane.z = 10

'pyramid
pyramid = []
pyramid.rotate = 0
pyramid.x = 20; pyramid.y = 6 ; pyramid.z = 10
pyramid.texture = loadimage("plane/fire.png")
pyramid.mesh =
S3D_BeginMesh()
    S3D_Begin(S3D_TRIANGLES) 'sides
        S3D_Push()
        for i = 0 to 3
            S3D_Vertex(0, -1, 0, 0.5, 0)
            S3D_Vertex(1, 1, -1, 1, 1)
            S3D_Vertex(-1, 1, -1, 0, 1)
            S3D_RotateY(rad(90))
        next
        S3D_Pop()
    S3D_End()
   
    S3D_Begin(S3D_QUADS) 'bottom
        S3D_Vertex(1, 1, -1, 1, 0)
        S3D_Vertex(1, 1, 1, 1, 1)
        S3D_Vertex(-1, 1, 1, 0, 1)
        S3D_Vertex(-1, 1, -1, 0, 0)
    S3D_End()
S3D_EndMesh()


'-----------
' MAIN LOOP
'-----------
while not keydown(KEY_ESCAPE, true)
    set color black; cls; S3D_Clear()

    'information
    set color gray
    cx = width(primary)/2
    cy = height(primary)/2
    draw line cx,0,cx,cy*2
    draw line 0,cy,cx*2,cy

    'plane control   
    if keydown(KEY_UP,true) then
        if plane.y > -5 then
            plane.y = plane.y - 0.08
            plane.rotate = (plane.rotate + 90*0.03)%360
        else
            plane.y = 4
        endif         
    endif       
    if keydown(KEY_DOWN,true) then
        if plane.y < 5 then
            plane.y = plane.y + 0.08
            plane.rotate = (plane.rotate - 90*0.03)%360
        else
            plane.y = -4
        endif
    endif
    S3D_Translate(plane.x, plane.y, plane.z)
    S3D_RotateX(rad(plane.rotate))
    S3D_Mesh(plane.model, 0)   

    'pyramid   
    pyramid.rotate = (pyramid.rotate + 30*0.03)%360
    if pyramid.x < - 5 then
        pyramid.x = 20
    else
        pyramid.x = pyramid.x - 0.01
    endif
    S3D_Push()
        S3D_Translate(pyramid.x, pyramid.y, pyramid.z)
        S3D_RotateX(rad(pyramid.rotate))
        S3D_RotateZ(rad(270))
        S3D_Texture(pyramid.texture)
        S3D_Scale(0.5,0.5,0.5)
        S3D_Mesh(pyramid.mesh, 0)
    S3D_Pop()       

    redraw
    wait 1
wend


Attached Files
.zip   devil_triangle.zip (Size: 44.79 KB / Downloads: 2)
Reply
#2
(05-05-2024, 02:12 PM)1micha.elok Wrote: The Devil's Triangle
click each image to zoom in
Question #1
As you may see in the images above, I found a strange thing with the movement of the pyramid.
When I pressed UP or DOWN, the pyramid followed the plane direction.
What should be changed in the code ?
Question #2
The initial value of
plane.y      = 0
pyramid.y  = 6
But why are the plane and the pyramid in the same horizontal line at the beginning of the game ?
Code:
'=====================================================
'The Devil's Triangle
'
'3D Model :
'Voxel Plane assets by maxparata
'https://maxparata.itch.io/voxel-plane?download
'======================================================
'----------------
' INITIALIZATION
'----------------
include "s3d.n7"; S3D_SetView(primary, rad(45), 0.1, 50)
set window "The Devil's Triangle",800,400,false
set redraw off
'color definition
white = [255,255,255]
black = [0,0,0,120]
gray  = [200,200,200]
'plane
plane = []
plane.model = S3D_LoadMesh("plane/Plane01.obj", 0.5,-0.5,0.5, false)
plane.rotate = 30
plane.x = -5 ; plane.y = 0 ; plane.z = 10
'pyramid
pyramid = []
pyramid.rotate = 0
pyramid.x = 20; pyramid.y = 6 ; pyramid.z = 10
pyramid.texture = loadimage("plane/fire.png")
pyramid.mesh =
S3D_BeginMesh()
    S3D_Begin(S3D_TRIANGLES) 'sides
        S3D_Push()
        for i = 0 to 3
            S3D_Vertex(0, -1, 0, 0.5, 0)
            S3D_Vertex(1, 1, -1, 1, 1)
            S3D_Vertex(-1, 1, -1, 0, 1)
            S3D_RotateY(rad(90))
        next
        S3D_Pop()
    S3D_End()
   
    S3D_Begin(S3D_QUADS) 'bottom
        S3D_Vertex(1, 1, -1, 1, 0)
        S3D_Vertex(1, 1, 1, 1, 1)
        S3D_Vertex(-1, 1, 1, 0, 1)
        S3D_Vertex(-1, 1, -1, 0, 0)
    S3D_End()
S3D_EndMesh()
'-----------
' MAIN LOOP
'-----------
while not keydown(KEY_ESCAPE, true)
    set color black; cls; S3D_Clear()
    'information
    set color gray
    cx = width(primary)/2
    cy = height(primary)/2
    draw line cx,0,cx,cy*2
    draw line 0,cy,cx*2,cy
    'plane control   
    if keydown(KEY_UP,true) then
        if plane.y > -5 then
            plane.y = plane.y - 0.08
            plane.rotate = (plane.rotate + 90*0.03)%360
        else
            plane.y = 4
        endif         
    endif       
    if keydown(KEY_DOWN,true) then
        if plane.y < 5 then
            plane.y = plane.y + 0.08
            plane.rotate = (plane.rotate - 90*0.03)%360
        else
            plane.y = -4
        endif
    endif
    S3D_Translate(plane.x, plane.y, plane.z)
    S3D_RotateX(rad(plane.rotate))
    S3D_Mesh(plane.model, 0)  
    'pyramid   
    pyramid.rotate = (pyramid.rotate + 30*0.03)%360
    if pyramid.x < - 5 then
        pyramid.x = 20
    else
        pyramid.x = pyramid.x - 0.01
    endif
    S3D_Push()
        S3D_Translate(pyramid.x, pyramid.y, pyramid.z)
        S3D_RotateX(rad(pyramid.rotate))
        S3D_RotateZ(rad(270))
        S3D_Texture(pyramid.texture)
        S3D_Scale(0.5,0.5,0.5)
        S3D_Mesh(pyramid.mesh, 0)
    S3D_Pop()       
    redraw
    wait 1
wend

You need to push and pop the transformation when drawing the plane, else the pyramid's position will be relative to the plane's position and rotations.

Code:
    ' Move everything 10 units into the screen. This can be seen as setting the camera position,
    ' and it should affect all other drawing, so no push or pop.   
    S3D_Translate(0, 0, 10)

    ' Add push and pop around the code to draw the plane, else the position and rotation will
    ' affect objects drawn afterwards.   
    S3D_Push()
    S3D_Translate(plane.x, plane.y, plane.z)
    S3D_RotateX(rad(plane.rotate))
    S3D_Mesh(plane.model, 0) 
    S3D_Pop()

I added a translate into the screen before drawing the plane and the pyramid so that I could see what the pyramid was up to.
Reply
#3
(05-05-2024, 03:01 PM)Marcus Wrote: You need to push and pop the transformation when drawing the plane, else the pyramid's position will be relative to the plane's position and rotations.
...
I added a translate into the screen before drawing the plane and the pyramid so that I could see what the pyramid was up to.

It's very exciting to learn S3D, ... "one small step for man, one giant leap for humankind" ....  Big Grin Big Grin Big Grin
Next, I plan to make a very simple game "The Devil's Triangle"
Reply
#4
Quick question(s): Can S3D handle animated models? If so, how is that done? Just curious...
Logic is the beginning of wisdom.
Reply
#5
(05-06-2024, 07:56 AM)johnno56 Wrote: Quick question(s): Can S3D handle animated models? If so, how is that done? Just curious...

It's just a quick answer(s)
  Big Grin Big Grin Big Grin

   
click image to zoom in

Code:
model = S3D_LoadMesh("assets/funchum/funchum.obj", 3, -3, 3, false)

' Add two frames.
S3D_LoadMeshFrame(model, "assets/funchum/funchum_walk_1.obj", 3, -3, 3)
S3D_LoadMeshFrame(model, "assets/funchum/funchum_walk_2.obj", 3, -3, 3)

' Blend to frames of the mesh.
S3D_BlendMesh(model, anim.frame0, anim.frame1, anim.blend)
Please refer to  ex5_adding_mesh_frames.n7  

For further details, Marcus has better explanation regarding frame by frame animation for sure.
Reply
#6
1micha.elok's answer is correct, and currently that's the only way to do it.

I'm using a homemade modelling tool that I wrote (thinking ...) 23 years ago. The model in micha's image (and the s3d example) was created using that tool. It supports hierarchical models. I recently wrote a program to convert from its fileformat to OBJ. So I save a model in different poses and convert these "frames" to separate OBJ files that I can load and animate in s3d. It's just as non-fun as it sounds.

[Image: glom.jpg]
(This, https://youtu.be/4M8LW6es8Gs?si=LiGOWJxQjt9Y1Loc, game only contains models created in that tool.)

But I plan to write a loader for quake 2 models, MD2 format. I've done that before, wasn't hard. Those files support frames and animation.

However, 3d modelling is boring and hard as hell. In the 3d thing I'm working on you can use sprites (as in wolfenstein and doom) instead if you want to.
Reply
#7
Thank you. I know what you mean... Many years back, I dabbled - only for a short time - in making models using Blender, so that I could add my own characters to the game engine Cube2 (sauerbratten). Once the models (and the textures) were made, it was then saved as an OBJ, then imported into Cube2. That was as far as I got. I had no idea as to how, or even if I had to, code/script Cube2 to manipulate the model. The model imported just fine... but that was it... no movement etc... Your editor looks WAY simpler to use than Blender... Oh, the learning curve for Blender... Migraine central... I have done nothing with 3D since...

By the way ex5 example runs very smoothly... I should have viewed the examples before asking... *doh*

Thank you for the explanation...

J
Logic is the beginning of wisdom.
Reply
#8
The Devil's Triangle
Coming Soon Friday, May 10th, 2024

           
click each image to zoom in

In December 1945, Flight 19 - Avenger Torpedo Bombers
disappeared over the Bermuda Triangle.
The Bermuda Triangle is known as The Devil's Triangle
It is on an area bounded by Florida,Bermuda and Puerto Rico.
And now, you are assigned to investigate the area.
Beware, it is a dangerous area !



Press ESCAPE to continue
Reply
#9
Looks very interesting Smile

The plane is made of cubes right? They call it voxels, but for me "voxel graphics" will always be what it was in the Amiga days. It was a fast way to draw cool 3d stuff. But you rendered rectangles, fast, rather than cubes. Here's an old Amiga game that uses a voxel engine: https://youtu.be/jV6rKWph5nk?si=bcJomX7ezA7P1vbv
Reply
#10
(05-07-2024, 07:19 PM)Marcus Wrote: Looks very interesting Smile

The plane is made of cubes right? They call it voxels, but for me "voxel graphics" will always be what it was in the Amiga days. It was a fast way to draw cool 3d stuff. But you rendered rectangles, fast, rather than cubes. Here's an old Amiga game that uses a voxel engine: https://youtu.be/jV6rKWph5nk?si=bcJomX7ezA7P1vbv

The 3D model of the plane is available in several different format such as .obj and .vox (voxel ) 
I chose .obj which is compatible with s3d library.

Amiga Game, The Shadow of the Third Moon looks very interesting ... it makes me think to make a stage 2 of the upcoming release The Devil's Triangle ... 

I may create the Stage 2 with some similar (more or less) elements found in The Shadow of the Third Moon such as :
- enemies' plane
- pilot's dashboard
- heightmap

... let me check whether it is possible or not ...  Rolleyes
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)