I can't find something like CCWaves(or CCLiquid etc) class in cocos2d v3.x.
but they are exist in cocos2d-x v2.x
so, is it really disappear in cocos2d v3.x? and are there some replaceable class i can use?
thanks! ;)
In my practice I have not used this effect. But in project ccp-tests can be found EffectsTest.cpp file. This file contains Waves::create() and Liquid::create() methods.
If you go over to the definition of a method, you can find such implementation in CCActionGrid3D.cpp:
Waves* Waves::create(float duration, const Size& gridSize, unsigned int waves, float amplitude, bool horizontal, bool vertical)
Liquid* Liquid::create(float duration, const Size& gridSize, unsigned int waves, float amplitude)
EDIT:
Oh, I just noticed, you compare cocos2d-X v.2.x and cocos2d v.3.x.
According to the Class Reference, no similar class in cocos2d. But you can find examples of such effect here, or migrate to cocos2d-x :)
Related
typedef boost::geometry::model::d2::point_xy<double> boostPoint;
How to use boost::geometry::distance with opencv cv::Point without convertion to boostPoint?
double EuclideanDistance(const cv::Point2d &pt1, const cv::Point2d &pt2)
{
boostPoint boostPt1(pt1.x, pt1.y);
boostPoint boostPt2(pt2.x, pt2.y);
double distance= boost::geometry::distance(boostPt1, boostPt2);
return distance;
}
Update:
I tried this code, but it complaines to x error: ‘x’ has not been declared
BOOST_GEOMETRY_REGISTER_POINT_2D(cv::Point2d, double, boost::geometry::cs::cartesian, x, y)
Make sure you include the necessary header as indicated by the doc:
#include <boost/geometry/geometries/register/point.hpp>
If you want to make the code more elegant, just use the proper way. Boost is not a advantage if you added to your code. Since your points are OpenCV points, compute the distance using OpenCV like this:
double EuclideanDistance(const cv::Point2d &pt1, const cv::Point2d &pt2)
{
return cv::norm(pt1-pt2,cv::NORM_L2);
}
EDIT:
Since the OP need to do it in this way, I may suggest this solution: Create your own Point Class let us call it MyPoint. In MyPoint define copy constructors and conversation from and to cv::Point, boostPoint. In your code just use YourPoint everywhere. If you need help in implementing this just comment.
I am currently porting my ray tracer to the GPU by using CUDA, and to get my feet wet I am modifying the example CUDA 6.5 project (adding an array of integers) to use a custom Color struct instead of integer. However, I am getting various errors whenever I compile my code.
I have all of my class's member functions declared with the __host__ and __device__ attributes, and I have all of the definition code in a .cu file. In my color struct, I have a Darken method that interpolates the given color to black by the given amount. I also have a static definition for black that the Darken function uses.
For example, here is a trimmed down version of the struct:
// **********************
// .hpp file
// **********************
struct Color
{
float R;
float G;
float B;
__host__ __device__ static Color Darken(const Color& c, float amount);
static Color Black;
};
// **********************
// .cu file
// **********************
const Color Color::Black( 1.0f, 1.0f, 1.0f );
Color Color::Darken(const Color& c, float amount)
{
return Color( Math::Lerp( c.R, Black.R, amount ),
Math::Lerp( c.G, Black.G, amount ),
Math::Lerp( c.B, Black.B, amount ) );
}
However, whenever I go to compile the code, I get the following error:
error : identifier "rex::Color::Black" is undefined in device code
I have tried adding __device__, __host__, __global__, and various combinations of those specifiers to the colors, but the CUDA compiler tells me that they are not applicable. Also, after I add any of the specifiers to the static colors, I get the same error for the color's R, G, and B components.
Does anyone know how I can use the static color definitions in CUDA?
As per the documentation, the CUDA object model does not support static data members, so there is no direct way to do what you are trying to do.
As pointed out by Robert Crovella in comments, you could use a __constant__ memory declaration to achieve similar functionality, and you can also use namespace tricks to get around duplicate definitions when using whole compilation, or use extern with a single definition in separate compilation.
[This answer was added as a community wiki entry to get this question off the unanswered question list]
I want to convert my image which is a .bmp file into a physics body. I have tried but it does not work i.e I do not get the desired result. I have searched alot about it o google and finally asking you all to please help me out as I am new to it. Also I am wondering is there really a way to convert images into a box2D body or We simple cannot do that ? I have tried the following code :
My addBrick Function
b2Body* addBrick(int x,int y,int w,int h,bool dyn=true)
{
b2BodyDef bodydef;
bodydef.position.Set(x*P2M,y*P2M); //Setting body position
if(dyn)
{
bodydef.type=b2_dynamicBody; // dynamic body means body will move
}
b2Body* body=world->CreateBody(&bodydef); //Creating box2D body
b2PolygonShape shape; //Creating shape object
shape.SetAsBox(P2M*w,P2M*h);
////////////// Adding Fixtures(mass, density etc) //////////////
b2FixtureDef fixturedef;
fixturedef.shape=&shape;
fixturedef.density=1.0;
fixturedef.restitution = 0.7;
body->CreateFixture(&fixturedef);
return body;
}
drawbrick logic:
void drawbrick()
{
pix[0].readBMPFile("brick.bmp");
pix[0].mDraw();
}
declaration as b2Body
b2Body* myBrick;
calling functions:
myBrick = addBrick(100,0,10,10);
drawbrick();
Where am I going wrong? Can somebody please spot my mistakes??
The most effective way I have found to convert any sort of image into a Box2D body is by using the PhysicsEditor tool (link). I'm not affiliated with them and I am an independent software developer developer.
The editor allows you to import your image then automatically create polygons that you can import into a "shape cache" and then load into the bodies when you create them.
The Shape Cache API (which you can also get from their site) looks like this:
class Box2DShapeCache
{
public:
// Static interface
static Box2DShapeCache& instance(void);
public:
bool init();
void addShapesWithFile(const std::string &plist);
b2Fixture* addHullFixtureToBody(b2Body *body, const std::string &shape);
/* Shapes created in the physics editor are in pixel dimensions. When they are loaded
* they are normalized to the size of maximum of the width/height.
*
*/
void addFixturesToBody(b2Body *body, const std::string &shape, float32 scaleMeters);
CCPoint anchorPointForShape(const string& shape);
CCSize imageSizeForShape(const string& shape);
const std::vector<b2Vec2>& hullPointsForShape(const std::string &shape);
void reset();
float getPtmRatio() { return ptmRatio; }
~Box2DShapeCache() {}
private:
std::map<std::string, BodyDef *> shapeObjects;
Box2DShapeCache(void) {}
float ptmRatio;
};
NOTE 1 - I have used this with Cocos2d-x very effectively. In the video here (link), it was used to create the asteroids the spiders are walking on.
NOTE 2 - The original class was called GB2ShapeCache. It was written in objective-c and has been ported (here) to C++. If you need another C++ version, let me know (mine is slightly modded to import convex hulls from the tool) and I can help.
Was this helpful?
I'm writing an API for internal needs and so ease of use is one of the top priorities. I wonder if I'm pushing it too far as in the following example.
The function to solve the inverse geodetic problem takes in geocoordinates of two points and calculates distance between them and asimuths (angles) from each of the points to the other.
Ease-of-use-optimised conventional solution might look something like (please don't mind the length of the names, I know there's room for improvement):
class Angle;
class GeoCoordinate;
...
struct InverseGeodeticOut
{
Angle forwardAzimuth;
Angle backAzimuth;
double distance;
};
InverseGeodeticOut inverseGeodetic(const GeoCoordinate &firstPoint,
const GeoCoordinate &secondPoint);
// or
void inverseGeodetic(const GeoCoordinate &firstPoint,
const GeoCoordinate &secondPoint,
InverseGeodeticOut *result);
My question is how reasonable would it be to take it one step further to save user some typing:
class Angle;
class GeoCoordinate;
...
struct InverseGeodetic
{
InverseGeodetic();
InverseGeodetic(const GeoCoordinate &firstPoint,
const GeoCoordinate &secondPoint);
Angle forwardAzimuth;
Angle backAzimuth;
double distance;
};
// so the usages would be
InverseGeodeticOut inverse = inverseGeodetic(firstPoint, secondPoint);
InverseGeodeticOut inverse;
inverseGeodetic(firstPoint, secondPoint, &inverse);
InverseGeodetic inverse(firstPoint, secondPoint);
Perhaps in this particular example the difference is too small to be worth talking about but I wonder if such constructs are okay in general.
I like your 2nd code example, though I find the public constructor a bit confusing. Especially if there are other ways to construct an InverseGeodetic. I'd rather use a static factory method to construct it. That way you can give a more meaningful name to the method:
struct InverseGeodetic
{
Angle forwardAzimuth;
Angle backAzimuth;
double distance;
static InverseGeodetic FromTwoPoints(const GeoCoordinate &, const GeoCoordinate &);
};
// usage
auto inverse = InverseGeodetic::FromTwoPoints(a, b);
But then that might be my C# background bleeding through.
I have been following lazyfoos tutorials on SDL, and I have heavily modified his code to make sort of a ship game, that moves around. I'm trying to make the ship shoot, but i have absolutely no idea how to go about doing this. I have the ship and it's movements and the actual application of the image in a class, and I as wondering if anyone had any techniques or certain ways that are efficient in making the ship shoot, making the shot move independently and then disappearing when it goes off screen. I know that I am giving a vague explanation sort of, but I don't want to be given all of the answers, just a little sample code and a point in the right direction.
Create a class to hold a projectile, with all the information you need in it, such as this:
struct Projectile
{
Vector2 position;
Vector2 velocity;
shared_ptr<Image> graphic;
Time time_until_my_destruction;
bool dead;
void update(Time time_delta) {
if(!dead) {
position += velocity * time_delta;
time_until_my_destruction -= time_delta;
if(time_until_my_destruction < 0.0) dead = true;
}
}
void draw(DrawDest & dest) const {
graphic->draw(dest, position);
}
bool checkCollision(const GameObject & object) const {
return object.area().contains(position);
}
};
This class is not complete obviously, you'll probably want to make adjustments to access levels, and write some constructors and other things, but it should give you the basic idea.
Make a container of those. When the ship fires, put one into the container. Each frame, call update, draw, check if the projectile is dead and check for collisions against the game objects. If a collision occurs, apply damage or whatever. If the object is dead, remove it from the container.
I can only absolutely recommend Aaron's Game Programming Tutorials, it uses C++ and SDL.