orx and xcode

edited February 2010 in Help request
Hello, I just find orx and it look very very nice!
I have just a problem: how do you install orx under mac?
I have xcode but I very bad with a computer...
If somebody can explain me how I can do it will be very helpfuhl for me!
Thank you

Comments

  • edited February 2010
    Hi Palmier and welcome here!

    You don't exactly need to install orx on your mac, simply add liborx.dylib to your project as a resource and link against it.
    You also need to provide the path to orx's header files (orx.h ...) in your project properties (the field is called: Header Search Paths).
    That's about it. I will try to add a tutorial in the wiki to setup orx for xcode as soon as I'm done with the iPhone port. :)

    If you have any trouble, feel free to contact me directly by PM and let me know what specific step is the problem. =)
  • edited May 2010
    the best way to use a library is having something like install....
    There could be a shell script to install the files into the xcode project library templates.....
    After that,every one could easily create a project with orx.

    Cocos2d for iphone is the best example.
  • edited May 2010
    I'll look into how Cocos2D deals with the problem when I'm done with the current 1.2, so it might be in a couple of weeks.

    If someone feel like contributing with such install/scripts they are more than welcomed to do so. :)
  • edited May 2010
    I think I could help to write the shell script,But because I just came from Windows/VS platform,I have no idea about the project template and file template in MacOS/XCode.


    BTW:post some thought here after I learned orx and cocos2d for IPhone.
    Cocos2D for IPhone is the best 2D engine for IPhone I found.It have many useful game concept.Like Layer,Scene,menu,tile map.It's action design is great.
    It more like a tradition game engine with sprite,animation than orx.It supports some 3rd animation editors like Zwoptex to make the animation support easier.It supports 3rd map editor too.But when you should make thing with box2d,you should straight use the box2d library and code for the
    relation between the abstract physics world with the sprite you made.

    ORX's abstract level is high....because everything is a object with physics and sprite/animation.I could create a object with one line code and everything is fixed in setting.But the problem is That I didn't know every setting really means and what setting I can set.The only thing I can do is to try and try again,But after that,If I still have problem,It too hard to step into code to found what I did wrong.(Though iarwain is very kind,but I shouldn't bear to fix every problem after a day....)
    orx is too radical for setting(setting can't be equal to data) without a useful editor.........As a programmer,I am more familiar with getting everything done with code than setting.
    Getting the program into device/simulator is a very time wasting process.It make things worse.Even I change a little setting,I have to wait too mush time to watch the result.....Not like in Windows.
    In addition,ini setting is antediluvian,even orx make so many expand for it.
    But the base funtion,Setting a value with some operation on another key's value,is impossible.
    like We can do something like below:
    [Camera]
    FrustumWidth = @Display.ScreenWidth
    FrustumHeight = @Display.ScreenHeight

    but we can't do something like below:
    [Camera]
    FrustumWidth = @Display.ScreenWidth / 2
    FrustumHeight = @Display.ScreenHeight / 2

    That make the setting is less useful......

    If someone is very fimilar with orx,orx could be great,especial for it's portable.One can develop in windows and run it on IPhone.I am in the way to that.
    But Portability is also the weak point of orx.It can't be special design for IPhone like cocos2d for Iphone does.Like the DeviceOrientationPortrait and DeviceOrientationLandscape things.......

    Just the view point from me,who just be interested in IPhone.
  • edited May 2010
    jtianling wrote:
    I think I could help to write the shell script,But because I just came from Windows/VS platform,I have no idea about the project template and file template in MacOS/XCode.

    Thanks for the proposal, but if you don't have time to look into this I'll have a look into Cocos2D a in couple of weeks. I'm pretty new to MacOS/XCode and XCode really doesn't like me much (and it's reciprocal :D).
    BTW:post some thought here after I learned orx and cocos2d for IPhone.
    Cocos2D for IPhone is the best 2D engine for IPhone I found.It have many useful game concept.Like Layer,Scene,menu,tile map.It's action design is great.
    It more like a tradition game engine with sprite,animation than orx.It supports some 3rd animation editors like Zwoptex to make the animation support easier.It supports 3rd map editor too.But when you should make thing with box2d,you should straight use the box2d library and code for the
    relation between the abstract physics world with the sprite you made.

    I heard very good things about Cocos2D and I only have looked at it on surface so far.
    To me, it didn't appear as a game engine but more as a high level game library, which isn't a bad thing, but not what I'm trying to do with orx.

    I usually see 4 different kinds of game creation tools:
      none
    • Low level game libraries: Allegro, SDL, ClanLib, ...
    • High level game libraries: IndieLib, Cocos2D, STK, ...
    • Game engines: they're usually 3D ones: Panda3D, Irrlicht, Delta3D, ...
    • Fully integrated game engines: Construct, Unreal, Unity, GameMaker, ...none

    I think orx is (or trying to be) part of the third list. You don't manage sprites, sound resources etc, in orx, you just have objects with properties and rules in a 3D world.

    What it means in the end is that, as you said, there's a higher level of abstraction which usually leads to less low level control.
    As everything is public in orx, and due to the plugin architecture, you could take control of the low level parts, even rendering if you needed 3D support.
    Of course, it's not the philosophy of the engine and I'm trying hard to make things so that you wouldn't feel the need too much to do so. :)

    Orx is the way it is because I don't like having to initialize in code a whole bunch of things and write 10 lines everytime I want to add a new sprite with a visual effect.
    I'd rather just change some parameters in config and restart the program without changing a line of code, or even just reload the config file on-the-fly depending on the cases.
    Of course, nothing's perfect and this aim isn't totally reached, but that's my current goal: having the least amount of code to write as possible.

    I'm a low-level programmer with an history in the demo scene so I love doing low-level code for optimization or some visual effects for example.
    However, when I want to write a high level applications, such as games, I'm very lazy and want all the repetitive tasks to be hidden from me and done automatically.
    ORX's abstract level is high....because everything is a object with physics and sprite/animation.I could create a object with one line code and everything is fixed in setting.But the problem is That I didn't know every setting really means and what setting I can set.The only thing I can do is to try and try again,But after that,If I still have problem,It too hard to step into code to found what I did wrong.(Though iarwain is very kind,but I shouldn't bear to fix every problem after a day....)
    orx is too radical for setting(setting can't be equal to data) without a useful editor.........

    I totally understand your frustration.
    There isn't much documentation so far but there are some interesting tutorials made by Grey in addition to the basics ones I wrote. It's something we should work on in the future.

    Also you can find all the internal properties in CreationTemplate.ini and SettingsTemplate.ini files which are both part of orx's distribution. I trust most of the parameter names to be self explanatory, but if you find some obscure ones I'd be happy to give more explanations. :)

    A couple of months ago, a new comer named Blarg discovered orx and mastered all of its aspects very fast, even without being a programmer at the beginning. So I thought the tutorials were extensive enough, but I was wrong and we'll still work on a better doc/communication. :)

    But without much feedback it's hard to know which parts are hard to learn.

    As for an editor, since the beginning it's something we'd like to have. Unfortunately, it's something I'll never do myself (I *hate* writing GUI code) and I hope, one day, to see one made by the community. :)
    Eyecreate's Pey editor might even be the base for a more complete editor and I'm looking forward to see the next improvements to it. :)
    As a programmer,I am more familiar with getting everything done with code than setting.

    I perfectly understand this point of view. However, as a programmer too, I'd rather have things that can be automated made by a program/engine than having to write it myself. I'm lazy that way. :D

    If we take the example of Cocos2D, I found these tutorials: http://monoclestudios.com/cocos2d_whitepaper.html

    Maybe they aren't as tight as they could have been but I find all the steps to setup and handle resources very tedious.
    Again it's only a personal feeling and I know a lot of programmers who like writing verbose code and stay in control of everything, line by line. It's just not the philosophy we wanted to have behind orx.

    That being said, I like the scene feature in Cocos2D, but even this feature can be done very easily in orx with one object for the scene (and children) + a orxFX for transitions. Setting a lifetime on your root object will then free all the resources used by all its children (physics, sound, sprites, ...).

    As for tile maps, Scroll adds a map concept on top of orx. It's also written in C++ and allows very easy callback notifications for all your game objects (Scroll is written in templated C++).
    In addition to that, the level editor can be embedded in your game application and allows you to run your game directly from the editing view. It's still in early stage and lacks features, but I think it'll help people with a need for tile-based or object-based levels.
    Getting the program into device/simulator is a very time wasting process.It make things worse.Even I change a little setting,I have to wait too mush time to watch the result.....Not like in Windows.

    Why not running orx on your windows then? Instead than the iPhone version? Orx runs on windows, linux and Mac OS X. Your result will be the same than running your program in your simulator and would be more faster. But if I read correctly further in your post, that's probably what you think of doing.

    Just out of curiosity, how would you have a faster code/test loop using Cocos2D?
    The only thing preventing you from recompiling/restarting your app would be scripting support, I presume that's what you lack in orx and you like on Cocos2D?
    In addition,ini setting is antediluvian,even orx make so many expand for it.
    But the base funtion,Setting a value with some operation on another key's value,is impossible.
    like We can do something like below:
    [Camera]
    FrustumWidth = @Display.ScreenWidth
    FrustumHeight = @Display.ScreenHeight

    but we can't do something like below:
    [Camera]
    FrustumWidth = @Display.ScreenWidth / 2
    FrustumHeight = @Display.ScreenHeight / 2

    Actually, this issue isn't a INI issue. It's more the way data are interpreted inside of orx. If you get the raw value in orx, using orxConfig_GetRawValue, you'll get the exact string: @Display.ScreenWidth / 2. You could then interpret it the way you want. It's just that orx doesn't know how to process arithmetic expression so far, but it's something I've been thinking of adding in the future as I too would like to use things like this.
    However, it's not tied to the INI format, the same issue would arise with XML or JSON files.

    What I personnally like with the INI format is that it's very simple and not verbose at all. I dislike XML because of its verbosity. Of course, using XML editors hide this issue. Hopefully so will do Pey for orx's config files. :)
    That make the setting is less useful......

    Less useful, that's true, but still more useful than nothing. If you have to do it in code, when you want to change it, you have to recompile, and when you want to refer to it for another part of your code, you either use a shared static const/define or an extra variable, and again it has to be maintained in code in opposition to a single line in a text file.
    If someone is very fimilar with orx,orx could be great,especial for it's portable.One can develop in windows and run it on IPhone.I am in the way to that.

    But Portability is also the weak point of orx.It can't be special design for IPhone like cocos2d for Iphone does.Like the DeviceOrientationPortrait and DeviceOrientationLandscape things.......

    You're definitely right. Orx can't be too specific as it has to maintain most of the features across all supported platforms.
    However, some platform-specific features, such as the accelerometer, are supported, even in config files (like the update frequency of the accelerometer that will only be used on iPhone). If you want to use the device orientation, it's not something specific to Cocos2D, it's something part of Apple's iPhone SDK and you can also use it with orx if you feel like it.

    You have access to the ApplicationDelegate in orx, and you can write code as you would do with having to go through orx.
    I didn't do this bridge (for the device orientation) as I'd rather use the camera concept + rotation, this way my world simulation doesn't care about how I plan to use the device + my UI can be adapted to a different aspect ratio very easily (no lines of code required).

    I recently did that for an iPhone port of the Drops prototype where I didn't change a single line of code in the program, but by playing with the config files, I could easily have the whole UI adapt to a landscape or a portrait setting. And to do that, I didn't have either to update all the buttons, simply change the UICamera setting (rotation + frustum): all the buttons were scaled and positionned to fit the new orientation.
    Just the view point from me,who just be interested in IPhone.

    Even if things aren't perfect yet, even for developping for only one platform, such as the iPhone, I think orx is worth it.
    But again, it's because I like the way things are handled and that I don't need much code to manage resources. :)

    We'll continue to improve orx so as to support new features for our users, and make it more and more user friendly, but that's a long process and we need feedback for it. :)
  • edited May 2010
    I have known more philosophy of orx.
    I am sorry for that I had so much misunderstanding about orx because of lack of knowledge.
    for something to explain.

    I don't like xcode either,But as a programmer need to be familar with it,I have a no idea.....except change the setting to let it more like VS.......lol

    I still insist ini config is too old to use.
    I don't like XML either.
    But In my project I used to use JSON or Lua(just for config is great too).Lua can do the processing arithmetic expression things but need some code to use it.
    JSON can be used and created easily with a good library.(Like Jsoncpp)

    In cocos2d for iphone you could set the device orientation just with one line code....like:
    [none[CCDirector sharedDirector] setDeviceOrientation:CCDeviceOrientationLandscapeLeft];

    "I didn't do this bridge (for the device orientation) as I'd rather use the camera concept + rotation, this way my world simulation doesn't care about how I plan to use the device + my UI can be adapted to a different aspect ratio very easily (no lines of code required).I recently did that for an iPhone port of the Drops prototype where I didn't change a single line of code in the program, but by playing with the config files, I could easily have the whole UI adapt to a landscape or a portrait setting. And to do that, I didn't have either to update all the buttons, simply change the UICamera setting (rotation + frustum): all the buttons were scaled and positionned to fit the new orientation."

    Can you tell me more about how to do it?

    If I had known orx better,I could develop in windows.But I still slumping in the setting things about orientation, accelerator, box2d, touch event(just as you knew in other posts).

    I like cocos2d for iphone...maybe because It is more like the library of my company. the sprite,animation.........May be I should get used to orx,so I can get out some of mac/Xcode things away.....
  • edited May 2010
    CreationTemplate.ini and SettingsTemplate.ini help me a lot....
  • edited May 2010
    jtianling wrote:
    I have known more philosophy of orx.
    I am sorry for that I had so much misunderstanding about orx because of lack of knowledge.
    for something to explain.

    No worries, on the contrary, it's very good you have all these questions as I'm sure those informations will be useful to others too! :)
    And it's probably something we could compile as a FAQ on the wiki at some point.
    I don't like xcode either,But as a programmer need to be familar with it,I have a no idea.....except change the setting to let it more like VS.......lol

    Hehe, true. My favourite was emacs for a long time and now... I don't have a favourite anymore. All the IDEs I've been using have their strenghts and weaknesses, I have yet to find the perfect IDE for me. :)
    I still insist ini config is too old to use.
    I don't like XML either.
    But In my project I used to use JSON or Lua(just for config is great too).Lua can do the processing arithmetic expression things but need some code to use it.
    JSON can be used and created easily with a good library.(Like Jsoncpp)

    If you look on this forum, there's already a thread about this. I admit I like the simple INI syntax but I understand its limitations all too well. Having support for other descriptive languages will be certainly a plus, unfortunately, unless someone else does it, it's currently low on my todo list as there are so many things I'd like to have first, such as network or scripting support. :)
    In cocos2d for iphone you could set the device orientation just with one line code....like:
    [none[CCDirector sharedDirector] setDeviceOrientation:CCDeviceOrientationLandscapeLeft];

    True, but you still have to compile when you want to change your mind. ;) But I have to admit that for this specific point, it's something done very easily in Cocos2D.
    Actually as it relies on a very simple call of Apple's SDK, you could theoretically also do it for orx, but the syntax would be slightly different.
    "I didn't do this bridge (for the device orientation) as I'd rather use the camera concept + rotation, this way my world simulation doesn't care about how I plan to use the device + my UI can be adapted to a different aspect ratio very easily (no lines of code required).I recently did that for an iPhone port of the Drops prototype where I didn't change a single line of code in the program, but by playing with the config files, I could easily have the whole UI adapt to a landscape or a portrait setting. And to do that, I didn't have either to update all the buttons, simply change the UICamera setting (rotation + frustum): all the buttons were scaled and positionned to fit the new orientation."

    Can you tell me more about how to do it?

    I'll even post all the source of the modified Drops version either during the week or next week end as right now I lack a bit of time (and it's not on the computer I use every day).
    I actually added the ParentCamera config property in order to support this idea.
    If I had known orx better,I could develop in windows.But I still slumping in the setting things about orientation, accelerator, box2d, touch event(just as you knew in other posts).

    Unfortunately, for the accelerator you have to use the device as it's not even supported by the simulator. Same for multi-touches. If you use orx on windows for example, you can simulate the accelerator with a pad/joystick though. Unfortunately you can't simulate the multitouches.
    I like cocos2d for iphone...maybe because It is more like the library of my company. the sprite,animation.........May be I should get used to orx,so I can get out some of mac/Xcode things away.....

    The way Cocos2D is made is very similar to most high level game libraries so it's something programmers feel very comfortable with, and it's normal. I still think it'd be faster to develop complex things and games using orx, but it's also because I know very well how orx works. ;)
    If you don't feel comfortable with orx's genericity, you can still make direct calls to Apple's iPhone SDK when you need them.
    I tried to forward events I knew were essentials (multi-touches, accelerometer, ApplicationWillResignActive/ApplicationDidBecomeActive, etc...) but I'm sure I missed some and I'll be happy to support them in the future. :)
  • edited May 2010
    jtianling wrote:
    CreationTemplate.ini and SettingsTemplate.ini help me a lot....

    I know they're very basic but I use them all the time! ;)
  • edited May 2010
    I don't think the Device Orientation things can be easily set in a game with apple SDK.
    If It's a application with UIKit,Apple's SDK is useful.But it did nothing with a game.The game engine should deal with it all by itself.

    Because I do thing the Device Orientation things didn't get original support by orx,I think I can have a transformation by myself.

    I tried the ParentCamera propery, but it is useless except getting all the objects invisible.(With a position range in (100,100))
  • edited May 2010
    jtianling wrote:
    I don't think the Device Orientation things can be easily set in a game with apple SDK.
    If It's a application with UIKit,Apple's SDK is useful.But it did nothing with a game.The game engine should deal with it all by itself.

    You're totally right. The Apple SDK only affect UIKit widgets, my bad. I could probably add some shortcut like this, but it'll get tricky to handle when someone is using more than one viewport simultaneously.
    Because I do thing the Device Orientation things didn't get original support by orx,I think I can have a transformation by myself.

    Again, I think using a rotation on the camera should do the trick (except for the FPS display as you mentionned earlier).
    I tried the ParentCamera propery, but it is useless except getting all the objects invisible.(With a position range in (100,100))

    I'll post the updated version of Drops before the end of the week so that you can see how I used it to separate world camera and UI camera and make them independent.
  • edited May 2010
    I look forward the new example Drops,the new tutorials and the new version 1.2 orx.

    BTW: I always confused by the coordinate system after set the camera rotation.Can you write a little tutorial about the coordinate system of orx with camera rotation?
  • edited May 2010
    Sure,

    I can write a small one during the next week end. Maybe if you can provide me with a small code example of what is not working as you expect, I could use it as a base for a tutorial?
  • edited May 2010
    jtianling wrote:
    CreationTemplate.ini and SettingsTemplate.ini help me a lot....

    I completely forgot to mention that the parameters were explained in more details on the wiki here (http://orx-project.org/wiki/en/orx/config/settings_structure/main) and here (http://orx-project.org/wiki/en/orx/config/settings_main/main).

    Let me know if it's of any help! :)
  • edited May 2010
    I just found it, it's so useful。You should put it easier to find! I think it even more useful than tutorials after one knows a little about orx.
  • edited May 2010
    iarwain wrote:
    Sure,

    I can write a small one during the next week end. Maybe if you can provide me with a small code example of what is not working as you expect, I could use it as a base for a tutorial?

    So many things about coordinate system of orx I need to know more.
    Like the original coordinate,It's not like Screen coordinate,not like cartesian coordinates with the origin point at left bottom.(like cocos). It's not like the OpenGL coordinate with origin at center of screen.It's strange.

    After set camera rotation,I look the device as a rotated way,I should set coordinate in another way.

    The mouse input come from a screen coordinate.
    The touch input on IPhone from a view coordinate?
    I think it is kind of troublesome to get and change touch event position like these code:


    UIApplication *app = [UIApplication sharedApplication];
    orxAppDelegate *appDelegate = [app delegate];
    UIView *view = [appDelegate poView];
    CGPoint currentPos = [touch locationInView:view];
    orxVECTOR pos;
    pos.fX = currentPos.x;
    pos.fY = currentPos.y;
    pos.fZ = 0.0;

    And after device set Orientation(even don't set), how to translate the position to world position to set to a object.
    Its complexity make me crazy.
    If the view is not the only view on IPhone,the things go to more terrible。

    I hope you could summarize how to translate coordinates(between screen,view,world) in these situations with some example.Adding some help function in orx is more great.

    I just find the
    inline orxVECTOR GetMouseWorldPosition()
    {
    orxVECTOR MouseWorldPosition = { 0.0, 0.0, 0.0 };
    orxVECTOR MouseScreenPosition = { 0.0, 0.0, 0.0 };

    orxRender_GetWorldPosition( orxMouse_GetPosition( &MouseScreenPosition ), &MouseWorldPosition );

    return MouseWorldPosition;
    }
    function in tutorial.
    It's not helpful enough.

    the coordinates in orx like this,why? OrxAxis.png
    OrxAxis 102.2K
  • edited May 2010
    jtianling wrote:
    I just found it, it's so useful。You should put it easier to find! I think it even more useful than tutorials after one knows a little about orx.

    The link is actually on the first page after the language selection screen of the wiki. What would you suggest to make it more accessible?
  • edited May 2010
    jtianling wrote:
    So many things about coordinate system of orx I need to know more.

    So here we are! :)
    Like the original coordinate,It's not like Screen coordinate,not like cartesian coordinates with the origin point at left bottom.(like cocos). It's not like the OpenGL coordinate with origin at center of screen.It's strange.

    Well yes and no.

    There are 2 coordinate systems you should be aware of: the screen coordinate system (2D) and the world coordinate one (3D).

    The screen coordinate is the typical 2D coordinate (unlike Cocos which apparently doesn't use the usual 2D standard from what you told us).
    Basically the X axis goes from left to right and the Y axis goes from top to bottom. The origin is the top left corner and the unit is the pixel. It matches how the actual video memory is.

    The world coordinate takes the same 2 axes and adds a Z one, so as to form a right-handed 3D coordinate system. Hence the Z axis comes from the user toward the screen (if you trust your right hand, it should also work for memorizing purposes :)). Its unit is also based on the pixel.
    As the physics plugin and the sound plugin (for spatialization) use meter as unit, you can define the ratio between pixels and meters, separately for both plugins.

    Viewports in orx are always defined in the screen coordinate system.

    Cameras are placed in the 3D world (like you would do with any 3D engine), but they are 2D cameras, so they are always oriented along the Z axis, from negative to positive. The 2D center of the camera matches its position (which makes sense if you imagine it's a 3D camera in a 3D space).

    So when a camera is bound to a viewport V and its position is (X, Y, Z), an object in the world at position (X, Y, Z') will be rendered exactly in the center of V as long as Z + NearFrustum < Z' <= Z + FarFrustum

    That's about all you need to know about coordinate systems so as tobe able to use orx. :)
    After set camera rotation,I look the device as a rotated way,I should set coordinate in another way.

    Not really, the screen space didn't change, it's just that the world will be rendered with a rotated angle on your viewport.
    The mouse input come from a screen coordinate.
    The touch input on IPhone from a view coordinate?

    Yes, but the iPhone view (warning, view, not viewport) coordinate is the same as the screen coordinate as there's only one iPhone view in orx (poView), has its origin at the top left of the screen and fills the whole screen. They're strictly the same.
    I think it is kind of troublesome to get and change touch event position like these code:
    UIApplication *app = [UIApplication sharedApplication];
    orxAppDelegate *appDelegate = [app delegate];
    UIView *view = [appDelegate poView];
    CGPoint currentPos = [touch locationInView:view];
    orxVECTOR pos;
    pos.fX = currentPos.x;
    pos.fY = currentPos.y;
    pos.fZ = 0.0;
    

    You don't have to do this manually!
    The mouse plugin does this exact thing for you.
    Calling orxMouse_GetPosition() will then give you the position of your touch in screen space (which, again, is the same as the view one).
    It's only when dealing with multiple touches that you need to do something like this.
    And after device set Orientation(even don't set), how to translate the position to world position to set to a object.
    Its complexity make me crazy.
    If the view is not the only view on IPhone,the things go to more terrible。

    Again, there's only one view in orx but you can have many viewports. Viewports than can be attached to cameras that, in turn, have zoom and rotation...
    So yes, that would not be that trivial if you had to do it yourself.

    That's why there's a function that will do the complete conversion for you:

    orxBOOL orxRender_GetWorldPosition(const orxVECTOR *_pvScreenPosition, orxVECTOR *_pvWorldPosition); :D

    You feed this function with a screen coordinate and it will give you back the 3D coordinate you need if valid (you might have to adjust the Z though depending on what you want to do, more details a bit below).

    If this function returns orxFALSE, it means that the 2D position you provided is not in an actual viewport. In this case, don't use the world position as it won't be set.
    On the contrary, if it returns orxTRUE, it means that your 2D position was in a valid viewport and it will give you the 3D position that corresponds.

    The Z coordinate will be equal to Camera.Z + Camera.FrustumNear, so it's the top most point matching your 2D position with your camera frustum.
    This coordinate is very useful for object picking (as being top most) but placing an object with this Z will be culled at rendering: remember, as seen above, camera render objects with a Z that validates this equation:
    Camera.Z + Camera.FrustumNear < Z <= Camera.Z + Camera.FrustumFar
    Note the first strict inequality.
    I hope you could summarize how to translate coordinates(between screen,view,world) in these situations with some example.Adding some help function in orx is more great.

    I just find the
    inline orxVECTOR GetMouseWorldPosition()
    {
    orxVECTOR MouseWorldPosition = { 0.0, 0.0, 0.0 };
    orxVECTOR MouseScreenPosition = { 0.0, 0.0, 0.0 };

    orxRender_GetWorldPosition( orxMouse_GetPosition( &MouseScreenPosition ), &MouseWorldPosition );

    return MouseWorldPosition;
    }
    function in tutorial.
    It's not helpful enough.

    On the contrary, I think you already have what you need for that. :)

    In this code (I presume it comes from one of Grey's tutorial?), on the same line we ask for the mouse position in screen space (ie. our single touch position) and we transform it in 3D world position.
    It'd be better to check if the function returns orxTRUE though, as if it's not the case, it means your 2D position doesn't have enything rendered to it.
    the coordinates in orx like this,why? OrxAxis.png

    It's not. It's because you try to fusion both spaces: the screen and the world one.

    Both spaces always remain the same, they never changes. It's only the links between both, made by viewport/camera couples, that can change.

    When writing game code logic, you mostly need to pay attention to the world space.

    The only case where you want to deal with screen space is for UI interactions (mouse, touch, ...).

    When this happens, simply use orxRender_GetWorldPosition() to go back to your 3D world space. :)

    Orx currently renders in 2D only (the only available render plugin being 2D so...) but it could as well be a 3D engine as everything happens in a 3D world.
    Presently we only use the Z coordinate for sorting during rendering and for parallax/scale effects when requested.

    Hope this helps. :)
    Please let me know if something still sounds obscure.
  • edited May 2010
    The explain is great!

    But I still have some problem:

    1.the code:

    UIApplication *app = [UIApplication sharedApplication];
    orxAppDelegate *appDelegate = [app delegate];
    UIView *view = [appDelegate poView];
    CGPoint currentPos = [touch locationInView:view];
    orxVECTOR pos;
    pos.fX = currentPos.x;
    pos.fY = currentPos.y;
    pos.fZ = 0.0;

    have to be used, when I need to control the multi-touch.

    2.the coordinates in the picture was verificated by the programs,what confuse me.
    I will post the code and the original output snapshot when I go home tonight.
  • edited May 2010
    Screen_shot_2010_05_13_at_10.png

    I want to know what i'm wrong.
    char buffer[10];
    for( int i = 0; i < 3; ++i ) {
    sprintf(buffer, "X %d", i*75);
    orxOBJECT* object = orxObject_CreateFromConfig("SingleText");
    orxObject_SetTextString(object, buffer);
    orxVECTOR pos;
    pos.fX = i*75;
    pos.fY = 0.0;
    pos.fZ = 0.0;
    orxObject_SetPosition(object, &pos);
    }

    for( int i = 0; i < 5; ++i ) {
    sprintf(buffer, "Y %d", i*50);
    orxOBJECT* object = orxObject_CreateFromConfig("SingleText");
    orxObject_SetTextString(object, buffer);
    orxVECTOR pos;
    pos.fX = 0.0;
    pos.fY = i * 50;
    pos.fZ = 0.0;
    orxObject_SetPosition(object, &pos);
    }

    The coordinate systems I didn't mix,It's like this.


    ; --- Viewports ---

    [Viewport]
    Camera = Camera

    [Camera]
    FrustumWidth = @Display.ScreenWidth
    FrustumHeight = @Display.ScreenHeight
    FrustumNear = -1.0
    FrustumFar = 2.0
    Position = (0.0, 0.0, -1.0)
    Zoom = 1.0

    ; --- Texts ---
    [SingleText] ;============================
    Graphic = SingleTextGraphic
    Position = (0.0, 0.0, 0.0)
    Scale = 2.0
    Smoothing = false

    [SingleTextGraphic] ;===============================
    Text = SingleTextString
    Color = (255, 0, 0)
    Pivot = center

    [SingleTextString] ;=========================
    String = SingleTextString

    ;[SingleText]
    ;String = Ball # ORX
  • edited May 2010
    jtianling wrote:
    The explain is great!

    But I still have some problem:

    1.the code:

    UIApplication *app = [UIApplication sharedApplication];
    orxAppDelegate *appDelegate = [app delegate];
    UIView *view = [appDelegate poView];
    CGPoint currentPos = [touch locationInView:view];
    orxVECTOR pos;
    pos.fX = currentPos.x;
    pos.fY = currentPos.y;
    pos.fZ = 0.0;

    have to be used, when I need to control the multi-touch.

    True, but only for multiple touches. And in this case you'll want to parse all the touches defined in the event you receive, something like:
    UITouch                  *poTouch;
    orxIPHONE_EVENT_PAYLOAD  *pstPayload;
    
    /* Gets payload */
    pstPayload = (orxIPHONE_EVENT_PAYLOAD *)_pstEvent->pstPayload;
    
    /* For all touches */
    for(poTouch in [pstPayload->poUIEvent allTouches])
    {
      orxVECTOR vPosition;
      CGPoint   vTouchPosition;
    
      /* Gets touch's position inside view */
      vViewPosition = [poTouch locationInView:(orxView *)_pstEvent->hSender];
    
      /* Gets orx position */
      orxVector_Set(&vPosition, orx2F(vViewPosition.x), orx2F(vViewPosition.y), orxFLOAT_0);
    }
    

    As you might want other info about the touches (like the phase, for example), you'll have to deal with cocoa code as wrapping everything will be tedious and not very useful.
    2.the coordinates in the picture was verificated by the programs,what confuse me.
    I will post the code and the original output snapshot when I go home tonight.
    Please see my next reply.
  • edited May 2010
    jtianling wrote:
    I want to know what i'm wrong.

    [...]

    The coordinate systems I didn't mix,It's like this.

    [...]

    [Camera]
    FrustumWidth = @Display.ScreenWidth
    FrustumHeight = @Display.ScreenHeight
    FrustumNear = -1.0
    FrustumFar = 2.0
    Position = (0.0, 0.0, -1.0)
    Zoom = 1.0

    You didn't mix the coordinate systems, but the pipeline I explained earlier is still valid.

    Right now, you set your camera at position (0, 0, -1). So every object having a coordinate (0, 0, Z) with -1 < Z <= 1 will be right in front of your camera and thus will be displayed in the middle of the viewports bound to your camera.

    And that's exactly what you can see in your screenshot: you have only one viewport bound to this camera that covers the full screen, thus the object at (0, 0, Z) will be displayed in the middle of it, ie. at screen coordinate (160, 240).

    If you want to have points from the world coordinate (0.0, 0.0, Z) rendered at screen coordinate (0.0, 0.0), you then need to move your camera to the position (160, 240, -1).
    This way, instead of displaying the world region between (-160, -240, -1) and (160, 240, 1) it would display the world region between (0, 0, -1) and (320, 480, 1).

    Please note that using a negative value for FrustumNear won't be accepted as it would be behind the camera. In this case orx will assume 0 for the FrustumNear.

    In the same order of idea, let's say you still had your camera at (0, 0, -1) and had scaled down your viewport with:
    [Viewport]
    RelativeSize = (0.5, 0.5, 1.0)
    RelativePosition = top left
    

    then the same object would still be displayed in the middle of the viewport, but now the viewport covers only the top left quart of the screen. So in the end, your object would be at screen coordinate (80, 120) and displayed half of its current size on both axes.

    The tutorial #5 is all about viewports and cameras: http://orx-project.org/wiki/en/orx/tutorials/viewport

    Hope this helps! :)
  • edited May 2010
    iarwain wrote:
    jtianling wrote:
    I just found it, it's so useful。You should put it easier to find! I think it even more useful than tutorials after one knows a little about orx.

    The link is actually on the first page after the language selection screen of the wiki. What would you suggest to make it more accessible?

    the most important wiki page is "http://orx-project.org/wiki/en/orx/config/settings_main/main".
  • edited May 2010
    "So when a camera is bound to a viewport V and its position is (X, Y, Z), an object in the world at position (X, Y, Z') will be rendered exactly in the center of V as long as Z + NearFrustum < Z' <= Z + FarFrustum"
    And the code is useful.

    But after that,I don't want to know how to use multi-viewport(that hardly use in iPhone), I want to know why the Y axis increase to downside with my config.(as in the picture)
  • edited May 2010
    jtianling wrote:
    But after that,I don't want to know how to use multi-viewport(that hardly use in iPhone), I want to know why the Y axis increase to downside with my config.(as in the picture)

    As stated in one of my previous reply, it's an historic reason. Almost all 2D libraries adopt this convention as it matches the layout of the actual memory.

    It's also the one used by the iPhone as you can see on the official doc: http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/GraphicsandDrawing/GraphicsandDrawing.html (chapter Coordinates and Coordinate Transforms).

    The 3D space is just an extension to this space: X: positive when going to the right, Y: positive when going down and Z: positive when going to the screen.

    If that doesn't answer your question, please let me know.
  • edited May 2010
    I'm sorry for my little knowledge about that.

    Before that,I only knew something about OpenGL and D3D,both the 3D API base in a axis: Y: positive when going upside.So orx asix is strange for me.I show the axis to a friend working in my company who konws 3D well,It said the axis is strange too.May be we both don't know 2D well......

    OK, I will accept that.
  • edited May 2010
    The only difference between the coordinate system used in your image, and the one used in ORX, from what I can see, is that you are "looking" at the 0,0 point from a different camera position.


    Example of a screen with 480x and 800y pixels:
    In your image, you go from (0,0) to (480,800)
    In ORX, you go from (-240,-400) to (240,400)
  • edited May 2010
    Grey wrote:
    The only difference between the coordinate system used in your image, and the one used in ORX, from what I can see, is that you are "looking" at the 0,0 point from a different camera position.


    Example of a screen with 480x and 800y pixels:
    In your image, you go from (0,0) to (480,800)
    In ORX, you go from (-240,-400) to (240,400)

    Yes, I knew that,But that means many things.It's different.One means a screen coordinate and one means a world coordinate of a engine.
Sign In or Register to comment.