A few questions relating to Y rotation

All topics about ZGameEditor goes here.

Moderator: Moderators

Post Reply
jinxtengu
Posts: 122
Joined: Wed Oct 14, 2009 2:05 pm
Contact:

A few questions relating to Y rotation

Post by jinxtengu »

Hi,
I've started working on a new Z game, using a newer build of Z game editor, which is version 4.0b (previously I was using version 1.9).
Anyhow some code that I was using in the older version is running differently now, and I'm wondering why this is and how I can fix it.

So specifically it is setting the direction of flat 3d objects to always face towards the camera.
The code that I previously used was, on update : CurrentModel.rotation.y=AppCameraRotation.y/-1;

This code still works fine, but when used in conjunction with the code (used on the model spawn event) Currentmodel.rotation.z=random(1,1);
It ends up rotating objects seemingly on the x axis. In previous versions it never behaved like this and visually it looks wrong.
Any ideas whats going on here?

Additionally I've noticed, having converted one of my older projects into the newer build of Z game editor, all of the sound effects (previously saved in raw format) are garbled, thankfully I see that it is now possible to use the .ogg sound format. So I've converted a few of the samples into .ogg and loaded them into the game. Initially this seemed to be working fine but after loading the 3rd sample into the game, and having it play at a certain instance, I notice that the entire global volume goes to zero, effectively silencing all sounds in the game for a few seconds, every time the game attempts to play the sample. I'm also curious as to what might be causing this?

Anyhow, any thoughts feedback or suggestions on these 2 questions would be most welcome!!
:)
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: A few questions relating to Y rotation

Post by VilleK »

Hi,

The default camera axis in ZGE have not changed since version 1.0 as far as I can remember so not sure what is going on in your case. @Kjell is usually the master at these kind of questions so maybe he will come around and help.

OGG-support is included since several years but to my knowledge it has not been used very much so there may still be bugs. Are the OGG-files in stereo or mono?
jinxtengu
Posts: 122
Joined: Wed Oct 14, 2009 2:05 pm
Contact:

Re: A few questions relating to Y rotation

Post by jinxtengu »

Hi,
Thanks for the response!
The .OGG files are in mono. Would it make any difference if they are in stereo?

I will continue to bug test the rotation code and post back here if I discover a solution.
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Re: A few questions relating to Y rotation

Post by Kjell »

Hi guys,
VilleK wrote: Fri Dec 17, 2021 9:08 amThe default camera axis in ZGE have not changed since version 1.0 as far as I can remember so not sure what is going on in your case.
This doesn't have anything to do with the camera, it's because the axis rotation order for models got fixed / reversed in 2010. It used to be ZYX but was changed to XYZ, which is the industry standard for 3D software.

Being able to select which rotation order you want to use for a model would have been nice, but in this specific situation it can be solved quite easily by adding a RenderTransform:

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FileVersion="2">
  <OnLoaded>
    <SpawnModel Model="Sprite" SpawnStyle="1"/>
  </OnLoaded>
  <OnUpdate>
    <ZExpression Comment="Camera">
      <Expression>
<![CDATA[// Animate camera rotation

App.CameraRotation.Y = cos(App.Time/2)/4;

// Set camera position based on rotation

float a = -App.CameraRotation.Y*PI*2;

App.CameraPosition.X = sin(a)*16;
App.CameraPosition.Z = cos(a)*16;]]>
      </Expression>
    </ZExpression>
  </OnUpdate>
  <OnRender>
    <UseMaterial Material="FloorMaterial"/>
    <RenderMesh Mesh="FloorMesh"/>
  </OnRender>
  <Content>
    <Model Name="Sprite">
      <OnUpdate>
        <ZExpression>
          <Expression>
<![CDATA[// Set y-axis rotation to inverse of camera

Sprite.Rotation.Y = -App.CameraRotation.Y;

// Rotate sprite on local z-axis using RenderTransform

SpriteTransform.Rotate.Z = App.Time/8;]]>
          </Expression>
        </ZExpression>
      </OnUpdate>
      <OnRender>
        <RenderTransform Name="SpriteTransform" Rotate="0 0 2.5073"/>
        <UseMaterial Material="SpriteMaterial"/>
        <RenderSprite/>
      </OnRender>
    </Model>
    <Material Name="SpriteMaterial" Shading="1" Light="0"/>
    <Mesh Name="FloorMesh">
      <Producers>
        <MeshBox Scale="8 8 1" XCount="3" YCount="3" Grid2DOnly="255"/>
        <MeshTransform Position="0 -2 0" Rotation="0.75 0 0"/>
      </Producers>
    </Mesh>
    <Material Name="FloorMaterial" Shading="2" Light="0"/>
  </Content>
</ZApplication>
K
jinxtengu
Posts: 122
Joined: Wed Oct 14, 2009 2:05 pm
Contact:

Re: A few questions relating to Y rotation

Post by jinxtengu »

Thanks KJell!
This has helped me alot!
Here I was visualizing the rotation order as ZYX and wondering why is was rotating on the wrong axis.
:D
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: A few questions relating to Y rotation

Post by VilleK »

Can always rely on Kjell to remember things I forgot :D .
Post Reply