Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - rmxhaha

Pages: [1]
1
Graphics / A Rectangle Shake Around
« on: August 11, 2013, 05:54:24 pm »
A month ago I experiment with viewport and everything I tried works
Now, I tried putting them into my project as a Camera system

and something bothers me
A Rectangle seems to shake around

Here is the compiled program
https://dl.dropboxusercontent.com/u/33612776/Kuroneko.rar

Left - Move Left
Right - Move Right
Space - Jump ( can jump twice )


This White Rectangle which shakes around represent "The Hero" and it's also the anchor point of the camera

Here is some code regarding the Camera system

Code: [Select]
#ifndef CAMERA_H
#define CAMERA_H

#include "Global.h"
#include "Physic.h"
#include "Hero.h"

#include <SFML/Graphics.hpp>

namespace Camera {
void initialize();

void update( float dt );

void calibrate( sf::RenderWindow& App );
}

#endif
Code: [Select]

#include "Camera.h"

namespace Camera {
namespace {
sf::View view;
const sf::FloatRect viewPortBig ( 0.f, 0.f, 1.f, 1.f );

// the first 2 parameters are the camera coordinate
sf::FloatRect viewRect ( 100.f, 0.f, WINDOW_WIDTH, WINDOW_HEIGHT );

const float focus_dx = -WINDOW_WIDTH / 2;
const float focus_dy = WINDOW_HEIGHT / 3.f;

Physic::Body HeroBody;
}

void initialize(){
HeroBody = Hero::get_hero_body();
sf::Vector2f position = HeroBody.getPosition();

viewRect.left = focus_dx + position.x;
viewRect.top = position.y - focus_dy;
}

void update( float dt ){
}

void calibrate( sf::RenderWindow& App ){
static sf::Vector2f TargetCoordinate;
static sf::Vector2f position;

position = HeroBody.getPosition();

TargetCoordinate.x = focus_dx + position.x;
TargetCoordinate.y = -position.y + focus_dy;


viewRect.left += ( TargetCoordinate.x - viewRect.left ) / 10.f;
viewRect.top += ( TargetCoordinate.y - viewRect.top ) / 10.f;

view.setViewport( viewPortBig );

view.reset( viewRect );
App.setView( view );
}
}
Code: [Select]
#include "TextureManager.h"
#include "Utility.h"
#include <iostream>

using namespace std;


int main()
{
    Physic::initialize();
Hero::initialize();
    Camera::initialize();

Physic::set_gravity( sf::Vector2f( 0.f, -500.f ) );

    sf::RenderWindow window( sf::VideoMode( WINDOW_WIDTH, WINDOW_HEIGHT ), "Project Kuroneko By Rmxhaha" );
    window.setFramerateLimit( 50 );

// -- map things
Physic::add_body( 100, 100, 40000, 70, "static" );
Physic::add_body( 500, 400, 400, 70, "static" );


    sf::Clock Timer;
    float delta_time = 0.f;

    while ( window.isOpen() )
    {
delta_time = Timer.getElapsedTime().asSeconds();
        Timer.restart();

        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }


Physic::update( delta_time );
Hero::update( delta_time );

        Camera::update( delta_time );
        Camera::calibrate( window );

// -- clearing the screen
        window.clear( ClearColor );

// -- draw everything
Physic::debug_draw( window );

// -- end of drawing
        window.display();
    }

    return 0;
}

Did I do something wrong ?
I don't think I do but well I don't know much about viewport anyway

Can someone point out the source of this problem ?
Is the problem is outside the program ? Like my GPU is too old or something ?

I used SFML 2.0 with "GCC 4.7 TDM (SJLJ) - 32 bits" written beside the download button
and CodeBlocks 12.11 with it's default compiler
and Window 7 Ultimate

2
Graphics / Re: sf::ConveShape getPoint
« on: March 28, 2013, 09:55:42 am »
Yup I am serious, I am bad at geometry and doing a lot of brute force calculation which require to access more. Maybe this won't be a problem for now.... I will be back when this has become a problem.

Thanks for your answer

3
Graphics / sf::ConveShape getPoint
« on: March 28, 2013, 05:28:12 am »
I get a little bit curious about one function in sf::ConvexShape class. In my version of SFML 2.0 there is a getPoint function inside sf::ConvexShape class.
it returns  Vector2f...

Why is that ?
Why not const Vector2f& ?

is there any perpose in doing that ?
I mean I've tried before that accessing getPoint took around 1.8 times accessing a direct float took. Which could only means a copy happened

Although it doesn't give much a difference if there is only a few thousand getPoint call but I am worried that it might be a bottleneck which is less likely to happened but I still am worried...

4
Graphics / Missing GetCharacterPos in SFML 2.0
« on: October 13, 2012, 12:46:13 pm »
Hey just today I want to move my project to SFML 2.0 from SFML 1.6.
If I am not mistaken sf::String is changed to sf::Text.
and I am missing GetCharacterPos in sf::Text

where is it ? is it depricated or renamed or something else ??

If you have to know I use GetCharacterPos to know each characters width to word-wrap

5
General discussions / Re: My Image takes 16 byte per pixel
« on: October 11, 2012, 12:03:10 pm »
Ok I get it now...
It's just that the memory managements....

I know that C++ program tend to allocate more than they need because of the OS Query things.
I just don't really care about it until I see big numbers.

Thanx for the answers
So sorry to bother you all for me being newbie

6
General discussions / Re: My Image takes 16 byte per pixel
« on: October 11, 2012, 11:31:32 am »
IDE ? I use code::blocks 10.24
and C++ Patch that is mentioned on the tutorial

I quite new in C++ application and making GUI and stuffs
so I don't know it's in debug mode or not

From what I always do I pressed F9 to compile

If the memory usage is not the actual memory usage of the application. Why would it be allocated in the first place. I mean if you do something like this

int * p = new int[1000];
 

I am sure that 4KB of data will be allocated no more no less.

so it's kinda confuse me, the way Windows allocate memory that isn't used by the application

7
General discussions / Re: My Image takes 16 byte per pixel
« on: October 11, 2012, 11:17:08 am »
Well as you said I count the memory usage using task-manager...

counting on the pixel something like

The intial memory usage of SFML is about 7 MB in the task manager.

if the image is 800 x 600
The task manager will show you that it takes about 14 MB

that goes to the question why does 800x600 image takes so much memory

it does the same when it loads up 2 or more pictures

I tried 2 image 800x600 and the task manager shows it takes about 22 MB

so I jump to the conclusion 1 picture 800x600 takes 7MB
if you count it
7MB = 7000000 KB
7000000 : 800 : 600 = 14.5 byte

So I assume that 16 byte is the usage of memory per pixel.

8
General discussions / My Image takes 16 byte per pixel
« on: October 11, 2012, 11:03:42 am »
It's just a while ago I relized that SFML is taking much of my memory. If I calculate it roughly it will be about 16 byte per pixel. Is it normal or is it me being stupid ?

I know that graphic library with 32 bit in their option use 32 bit of data per pixel which means it uses 4 byte of data per pixel instead of 16 byte. So why is my program that uses SFML takes that much even though I set it in the sf::RenderWindow like this

sf::RenderWindow window(sf::VideoMode( 1024, 768, 32 ), "Title" );
 

Pages: [1]