It is currently Sat Aug 19, 2017 4:19 am

All times are UTC - 5 hours




 Page 1 of 1 [ 8 posts ] 
Author Message
 Post subject: Caligari VMK 5 Model Editing
PostPosted: Tue Feb 13, 2007 7:06 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
This video shows how to add the ability to jump to the player class. Jumping is a key press type event.


Offline
 Profile  
 
 Post subject: Re: GameDev VMK 12 - Adding Jump Ability
PostPosted: Tue Nov 06, 2007 6:20 am 

Joined: Tue May 01, 2007 2:55 pm
Posts: 96
Location: Behind you
Excuse my rudeness, but this VMK seems like it is not structural. Though it is nice to be able to jump and it gives some result you can actually view and show, it appears to me it would be better to wait with adding a jump ability until I you have got "solid" objects and thus a sense of a "floor". Then you can have your character fall - which means jumping is just launching in the air and leaving the rest to itself.



That's how I would approach such a thing, because these jumps are nice, but they are really a jump simulation, one that you'll probably be taking out later anyway.


Offline
 Profile  
 
 Post subject:
PostPosted: Mon Sep 08, 2008 5:33 am 

Joined: Sat Jun 23, 2007 7:56 pm
Posts: 145
Hi Marek,
In this video, the K value is calculated as
K = 4 * (jumpHieght) / (jumpLen * jumpLen)

Can you explain why you calculated K like that?
What is the effect of multiplying by 4?


Offline
 Profile  
 
 Post subject:
PostPosted: Tue Sep 09, 2008 5:07 am 

Joined: Wed Aug 06, 2008 7:53 pm
Posts: 182
Location: Russia
It seems Marek on a vacation or something. ;)

Quote:
Can you explain why you calculated K like that?


Jump-function is obviously a cubic parabola. We are interested only in its OY projection.

K = 4 is a natural coefficient which you get if you thoroughly calculate quadric equation { a*x^2 + b*x + c } for our case. Here is the general idea.


The axe OX is taken for time.

The OY-centered parabola with “branchesâ€


Offline
 Profile  
 
 Post subject: More About GameDev-VMK012-Jump.
PostPosted: Tue Sep 09, 2008 5:36 am 

Joined: Wed Aug 06, 2008 7:53 pm
Posts: 182
Location: Russia
More About GameDev-VMK012-Jump.

- I think we should extend the interface of Camera class with these setters:
class Camera {
...
public:
   void SetX(float x) { m_position.x =  x; }
   void SetY(float y) { m_position.y = -y; }
   void SetZ(float z) { m_position.z =  z; }
...
};

SetY() is especially heavily used. I appreciate the code Set( GetX(), newY, GetZ() ) in Player() but simple SetY( newY ) is just better.

- Here is the initialization of "m_fJumpK" member in Player::Jump( ) : m_jumpK = 4.0F * m_jumpHeight / ( m_jumpLen * m_jumpLen );
and the use in Player::Update( float time ) : Set(GetX(), –m_jumpK * x0 * x0 + m_jumpY0, GetZ());
Obviously we can move a negation (–) to the initialization stage: m_jumpK = –4.0F * m_jumpHeight / ( m_jumpLen * m_jumpLen );
Then the use is: Set(GetX(), m_jumpK * x0 * x0 + m_jumpY0, GetZ());
Not too much, only one float-point negation, but though.

Additionally, combining with newlly added SetY() we’ve got:
    const float x0 = time - m_jumpX0;
    SetY( m_jumpK * x0 * x0 + m_jumpY0 );

That's all. Just for fun, I've deduced the coefficients of jumping trajectory, or more exactly OY-projection function, from generic quadric equation { a*x^2 + b*x + c }, trying to optimize something. I've figured out that what we have in GameEndgine is the most optimal, since any displacement of parabola along 0X-axe or rising it (both to get rid of some extra calculations), inevitably emit additional linear term, which means one extra multiplication during the cycle.


Offline
 Profile  
 
 Post subject:
PostPosted: Tue Sep 09, 2008 6:29 am 

Joined: Sat Jun 23, 2007 7:56 pm
Posts: 145
Thanks for the great reply.

Reading and doing calculations to embedd it in my brain :D


Offline
 Profile  
 
 Post subject: A problem with Player::SetPosition()
PostPosted: Sat Sep 05, 2009 2:30 pm 

Joined: Wed Aug 06, 2008 7:53 pm
Posts: 182
Location: Russia
When I was testing a hot-fix to the Vector3 class I also noticed that the function Player::SetPosition( x, y, z ) works incorrectly for X and Z co-ordinates, notably, the sign of x and z should be reversed to put the player at correct position. (Remember, we have done this for Y co-ordinate). Supposedly, we need this sign switch to ‘compensate’ Translate()-operation inside Game class (when we apply player’s/camera’s position to the scene) in the following (pseudo) code:

//  inside Game::UpdateGame()
    ::glRotatef( GetPlayer().GetAngleX(), 1.0F, 0.0F, 0.0F );
    ::glRotatef( GetPlayer().GetAngleY(), 0.0F, 1.0F, 0.0F );
    ::glTranslatef( GetPlayer().GetX(), GetPlayer().GetY(), GetPlayer().GetZ() ); // NOTE!


To fix this, I had to go inside Camera class and update all places, where we initialize Camera::m_position. Like so:

inline void Camera::SetPosition( float x, float y, float z )
{
    m_position.x = -x; // = x; // BEHOLD!
    m_position.y = -y;
    m_position.z = -z; // = z; // BEHOLD!
}


Nevertheless, I’m waiting for Marek’s comments. I also wonder am I the only one unfortunate with Player::SetPosition() or there is somebody else? :)


Offline
 Profile  
 
 Post subject:
PostPosted: Sun Sep 06, 2009 5:45 pm 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
That looks correct. The camera should always be moved in the opposite direction that the "player" is moving in for everything to get rendered correctly in OpenGL.

In DirectX there is an extra abstraction that lets you control the camera location, In OpenGL there is no such layer but it is easily achieved just by negating the player's position.


Offline
 Profile  
 
Display posts from previous:  Sort by  
 Page 1 of 1 [ 8 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  

cron