Jump to content

  • Log In with Google      Sign In   
  • Create Account


DgekGD

Member Since 01 Feb 2012
Offline Last Active Mar 08 2014 01:50 PM
-----

Posts I've Made

In Topic: Creating a simple 2d engine (C++), best way to create an Sprite class?

15 March 2013 - 12:26 PM

Create separate classes for Shaders, Vertex Buffers etc. 

 

 For example i have the following class for vertex shader:

class VertexShaderDX11
	{
	protected:

		ID3D11VertexShader*	m_pShader;
		InputAssemblerStateDX11*	m_pState;

	public:
		VertexShaderDX11()  { m_pState = new InputAssemblerStateDX11(); }
		~VertexShaderDX11() {	SAFE_RELEASE(m_pShader);
								SAFE_DELETE(m_pState); }

		ABOOL Create(BlobDX11 & shaderbuffer, INPUT_LAYOUT* layout, AUINT8 num,
										 AUINT16 topology);
		AVOID Set() const;
	};

 

Note that it has pointer to the InputAssembler structure (it stores information about Input Assembler stage as for vertex shader you have to have right input topology). 

 

 In your sprite class you can reference shader for rendering and bind it to the pipeline before you render your sprite. Don't recompile shader all the time! Compile it one time and then just have a pointer to an object of your shader class which stores compiled shader.  Multiple sprites can use single shader for rendering just having pointer to it.


In Topic: Deactivate a rigid body in Bullet

09 January 2013 - 05:48 AM

I guess, you can use btRigidBody::setFlags method and set proper flags to configure behavior for your rigid body. Here is a list of all flags(line 117). 


In Topic: Missile Pathing for 2D game

05 January 2013 - 12:10 PM

 Okay. Imagine you missile is going to the right (1, 0) - x and y coordinates accordingly. Currently it has position (200, 200). It's target lies in the point (300, 200), so target angle between missile direction and X axis is zero(targetOrientation = 0) and current angle of missile direction and X axis is zero(missile.orientation = 0)

 

 Next frame your target moves to the position (200, 100), probably you won't have such a huge jumps in just a single frame, but i try to show you an idea. So your desired direction for a missile is (0,1) now which make angle of Pi/2 (90 degrees) with X axis. So you start to rotate your missile. Your maxAngularAcceleration value should be already is defined for each missile, so you increase its rotation :missile.rotation += missile.angularAcceleration * time  and than orientation (or angle between direction and X axis) :  missile.orientation += missile.rotation * time.

 

 Than you use current angle to get movement direction. Start with creating Z axis rotation matrix (Z axis goes into your screen or out of your screen) and multiply vector (1, 0) with this matrix. As a result you will get rotated vector. That you can multiply it by speed scalar. You can read this small tutorial if you still have some questions regarding retrieving direction from current angle.

 

 I hope it helps ;) Let me know if you still have some questions :)


In Topic: Missile Pathing for 2D game

05 January 2013 - 07:50 AM

Yep, atan2 function will work, perhaps you have to swap deltaX and deltaY arguments to get an angle from X axis. 

 

  Orientation - is a desired angle or current angle ( position for movement )

  Rotation - is a speed orientation is changed (velocity for movement )

  angularAcceleration - is a speed rotation is changed (acceleration for movement)

 

 I hope everything is clear now:)


In Topic: Missile Pathing for 2D game

05 January 2013 - 05:19 AM

Basically, when your missile updates it's target position(it's not necessary to do every single frame) find target angle of rotation, so that missile points in right direction (with the help of atan2 function).

And than update missile rotation as you update its position. Here is an example:

 missile.angularAcceleration = targetOrientation - missile.orientation;
 if (missile.angularAcceleration < 0)
   missile.angularAcceleration = -maxAngularAcceleration;
 else
   missile.angularAcceleration = maxAngularAcceleration;

 missile.orientation += missile.rotation * time;
 missile.rotation += missile.angularAcceleration * time;

 if (missile.rotation > maxRotation) missile.rotation = maxRotation;


It's far not ideal implementation, just to give you an idea. Actually, you can make your rotation even smoother with the use of slow down radius for example(when angle to rotate remains small it starts to slow down a little bit). Also, maybe you fill need some radius of satisfaction(it's doubtful that your object will rotate EXACTLY at the angle you need and it will end up in flickering).


PARTNERS