I want to convert a Sprite into its shadow, I've tried to use glBlendEquation() function but it's not giving what I exactly want.I've followed following links for it :
http://gamedevelopment.games1234.net/view/63538897166780581719204/rendering-shadow-sprites-in-cocos2d-x
http://discuss.cocos2d-x.org/t/shadow-sprites/1214
What's proper way to do that?
My way to do that - js implementation:
shadow = cc.Sprite.create("sameNameAsParentSprite.png");
shadow.setColor(cc.c3b(0, 0, 0));
shadow.setOpacity(50);
parent.addChild(shadow, -1);
shadow.setPosition(cc.p(parent.getContentSize().width * 0.5 + 2, parent.getContentSize().height * 0.5 - 2));
Hope it will help you.
Related
I was trying to create a game the involves the user walking into the screen. I found some idea on how to do this here being lead by this question. But the tutorial is based on GLES1 and I could not adopt it for GLES2.
Here is what the design looks like,
Here is what I tried so far,
I modified GLState and added
public void frustumProjectionGLMatrixf(final float fov_degrees, float aspect, float zNear, float zFar) {
this.mProjectionGLMatrixStack.glFrustumf(fov_degrees, aspect, zNear, zFar);
}
and I modified GLMatrixStack and added
public void glFrustumf(float fov_degrees, float aspect, float zNear, float zFar) {
float[] mTemp = new float[2 * GLMatrixStack.GLMATRIX_SIZE];
Matrix.setIdentityM(this.mMatrixStack, this.mMatrixStackOffset);
// Matrix.frustumM(this.mMatrixStack, this.mMatrixStackOffset, 0, this.getWidthRaw(), this.getHeightRaw(), 0, 10, 300);
Matrix.perspectiveM(this.mMatrixStack, this.mMatrixStackOffset, fov_degrees, aspect, zNear, zFar);
Matrix.setLookAtM(this.mMatrixStack, this.mMatrixStackOffset, 0, 120f, zNear * 10, 0, 0, 0f, 0, 1, 0);
Matrix.scaleM(this.mMatrixStack, this.mMatrixStackOffset, 1, -1, 1);
System.arraycopy(this.mMatrixStack, this.mMatrixStackOffset, mTemp, GLMatrixStack.GLMATRIX_SIZE, GLMatrixStack.GLMATRIX_SIZE);
Matrix.multiplyMM(this.mMatrixStack, this.mMatrixStackOffset, mTemp, GLMatrixStack.GLMATRIX_SIZE, mTemp, 0);
}
and I created the camera as follows
this.camera = new Camera(0, 0, WIDTH, HEIGHT) {
#Override
public void onApplySceneMatrix(final GLState pGLState) {
super.onApplySceneMatrix(pGLState);
this.setZClippingPlanes(-3000, 3000);
setFrustum(pGLState);
}
#TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void setFrustum(GLState pGLState) { // set field of view to 60 degrees
float fov_degrees = 60;
float fov_radians = fov_degrees / 180 * (float) Math.PI;
float aspect = this.getWidth() / (this.getHeight());
float camZ = this.getHeight() / 2 / (float) Math.tan(fov_radians / 2);
pGLState.frustumProjectionGLMatrixf(fov_degrees, aspect, -100, 100);
pGLState.flush();
}
};
But there is nothing drawn on the screen. The scene is totally black. Any if there is no way to adapt perspective in AndEngine GLES2, other tricks to make this work will be appreciated.
Honestly i gave up and made my own pseudo 3D projection engine. The problem with this is that it is very slow, as it is all done without GL coding.
I had to use Sprite groups and 1 really big mesh(Mesh being the road), which really hurt the layering on the Z axis if you have rolling hills or tunnels etc. You will see in the pictures below.
In the end i had to create 3 sprite groups and 3 meshes. Detect if a sprite was behind the ground/tunnel/etc.
From that point backward(into the distance) i would
1: take sprites out of the first group and into the 2nd
2: stop all the first meshes vertices and draw the 2nd mesh from that point onward
3: repeat, if collision occurred behind the 2nd mesh, start the 3rd
hard to explain, took me a while to get it working and it's very quirky with a lot of restrictions. It took me months to get the FPS from 3 back to 60.
Without Layering (Trees show over the ground)
With collision detection layering
I can go into more detail if you would like.
Also if anyone has a better way of doing this, drop in some information for us.
I have a drawn a random dot matrix on the screen using matlab/psychtoolbox like this:
Screen('DrawDots', wPtr, dotPositionMatrix, dotSizes, dotColors, dotCenter, 2);
Screen('Flip', wPtr, (stimVbl + STIMULUS_DURATION - .5 * ifi), 0);
Now I want to save the result somehow into a figure that I can print off. How do I do that? I have no idea where to start looking for this information i.e. to save what came up once on the screen. Any guidance much appreciated.
Try Screen('GetImage'). In your case, for example:
Screen('DrawDots', wPtr, dotPositionMatrix, dotSizes, dotColors, dotCenter, 2);
Screen('Flip', wPtr, (stimVbl + STIMULUS_DURATION - .5 * ifi), 0);
current_display = Screen('GetImage',wPtr);
The variable current_display will then be a 3D array of pixel values representing the screen at that moment. You can save this, export this, do whatever you want with it.
Im using OpenCV to help me detect a coin in an image taken from an iPhone camera. Im using HoughCircles method to help me find them but the results are less than hopeful.
cv::Mat greyMat;
cv::Mat filteredMat;
cv::vector<cv::Vec3f> circles;
cv::cvtColor(mainImageCV, greyMat, CV_BGR2GRAY);
cv::threshold(greyMat, filteredMat, 100, 255, CV_THRESH_BINARY);
for ( int i = 1; i < 31; i = i + 2 )
{
// cv::blur( filteredMat, greyMat, cv::Size( i, i ), cv::Point(-1,-1) );
cv::GaussianBlur(filteredMat, greyMat, cv::Size(i,i), 0);
// cv::medianBlur(filteredMat, greyMat, i);
// cv::bilateralFilter(filteredMat, greyMat, i, i*2, i/2);
}
cv::HoughCircles(greyMat, circles, CV_HOUGH_GRADIENT, 1, 50);
NSLog(#"Circles: %ld", circles.size());
for(size_t i = 0; i < circles.size(); i++)
{
cv::Point center((cvRound(circles[i][0]), cvRound(circles[i][1])));
int radius = cvRound(circles[i][2]);
cv::circle(greyMat, center, 3, cv::Scalar(0,255,0));
cv::circle(greyMat, center, radius, cv::Scalar(0,0,255));
}
[self removeOverViews];
[self.imageView setImage: [self UIImageFromCVMat:greyMat]];
This current segment of code returns that i have 15 circles and the are all position along the right side of the image which has me confused.
Im new to OpenCV and there are barely any examples for iOS which has left me desperate.
Any help would be greatly appreciated, thanks in advance!
Your algorithm doesn't make much sense. It seems that you are using cv::GaussianBlur iteratively, but when you run HoughCircles on it, it's only going to work on the grey image that has been filtered by a GassianBlur with a 31x31 kernel, which is going to blur the crap out of the image. It might make better sense to do something like this to see the best results:
This will show you all images iteratively, which I believe is what you wanted to do in the first place.
// NOTE only psuedocode, won't compile, need to fix up.
for ( int i = 1; i < 31; i = i + 2 )
{
cv::GaussianBlur(filteredMat, greyMat, cv::Size(i,i), 0);
cv::HoughCircles(greyMat, circles, CV_HOUGH_GRADIENT, 1, 50);
for(size_t i = 0; i < circles.size(); i++)
{
cv::Point center((cvRound(circles[i][0]), cvRound(circles[i][1])));
int radius = cvRound(circles[i][2]);
cv::circle(greyMat, center, 3, cv::Scalar(0,255,0));
cv::circle(greyMat, center, radius, cv::Scalar(0,0,255));
}
cv::imshow("Circles i " + i, greyMat);
}
You still need some edges for the HoughCircle implementation to work. It uses a Canny edge detector and if you are blurring your image that much.
Also I would suggest you work with the bilateralFilter which blurs but attempts to keep some edges.
This might help as well for defining the correct parameters: HoughCircles Parameters to recognise balls
All the above code does is run the same process over and over, so your circles detect the drawn circles over and over again. Not the best. Also uses Gaussian Blur over and over, not the best way, in my opinion. I can see the Gaussian Blur in a for loop to make the image more readable, but not HoughCircles in the for loop. You need to include all the variables in houghcircles, it doubled my recognition rate when I used them all.
cv::HoughCircles(gray, circles, CV_HOUGH_GRADIENT, 1, 30, 50, 20, 10, 25);
Same format that is available on opencv website it is the C++ format.
Here is a link to my iPhone sim pic. Costco aspirin on my desktop. App counts circles in image and displays total in label.
Here is my code, it has a lot of comments included to show what I have tried...and sifted through. Hope this helps.
OpenCV install in xcode
I know this is an old question, so just putting this here in case someone else will make the same mistake (as did I...):
This line:
cv::Point center((cvRound(circles[i][0]), cvRound(circles[i][1])));
has the brackets messed up, the double "((" at the beginning is causing the point to be initialized with only one parameter instead of two, it should be:
cv::Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
Hope that helps.
I use open source, iCarousel in my application to bring the carousel control. The carousel type which I use is iCarouselTypeRotary and the images are arranged linearly in this type. But, I need the images to bring like the carousel in the attached images. What should I do to make my carousel little tilted to the top view as the style in the below images? Kindly help. Thanks in advance.
You can implement 3D tilt manually:
In iCarousel.m: 574
return CATransform3DTranslate(transform, radius * sin(angle), 0.0f, radius * cos(angle) - radius);
change to:
float tilt = MAX_TILT_VALUE * cos(angle); // greater angle means greater vertical offset
return CATransform3DTranslate(transform, radius * sin(angle), tilt, radius * cos(angle) - radius);
To make the code clear and reusable, implement tilt offset as option (similar to iCarouselOptionArc).
PS: If you want perspective scaling, you will need to add scale transform that depends on cos(angle) similarly to tilt.
Check by using the style:iCarouselTypeWheel use the horizontal wheel set the radius of the wheel as you want. I have done this in vertical wheel type. But i think it should the appearance as above using horizontal wheel type.
I have created a 3D cube in iphone using CALayer's. Now I wanted to rotate that cube(CALayer) at 90˚ when user double taps on it.
I was able to rotate that cube(CALayer) to 90˚ once but when I double tap the cube(CALayer) is not rotating.
Here is the code that I used to rotate the cube(CALayer)
CATransform3D x = CATransform3DRotate(currentLayer.sublayerTransform, M_PI / 2, 0, 0, 1);
currentLayer.transform = x;
Can anyone help in this. What I'm doing wrong.
PS. For the people who are wondering how I got the degree sign then here is the trick
Option + K
its because you are not changing the angle of rotation .... to understand this lets say you are passing M_PI/2 each time to that method .... so CATransform3DRotate do not rotate it to next 90˚ rather it rotate the layer to the specified angle in this case its 90... so you are not getting any chage because it already at 90˚ ..... so to get correct result do this
static float angle = M_PI / 2;//dont make it static rather make it a global variable
angle += M_PI / 2;
CATransform3D x = CATransform3DRotate(currentLayer.sublayerTransform,angle, 0, 0, 1);
currentLayer.transform = x;