Daily Archives

Articles indexed Tuesday May 27 2014

Page 11/16 | < Previous Page | 7 8 9 10 11 12 13 14 15 16  | Next Page >

  • Checking whether the user input is a str in Python [migrated]

    - by Sahil Babbar
    I checked various questions on Stack Overflow but one thing every logic lacks. Let me demonstrate using Python: while True: user_input = raw_input() if type(user_input) == str: print 'ERROR' else: print 'BINGO' Also, we cannot use input() in place of raw_input() as it gives the error:Traceback (most recent call last): File ".\test.py", line 3, in <module> user_input = int(input()) File "<string>", line 1, in <module> NameError: name 'asdf' is not defined The problem here is that raw_input converts the user input into string so it always prints 'ERROR' and if I change the second line to user_input = int(raw_input) then, it gives an error: Traceback (most recent call last): File ".\test.py", line 3, in <module> user_input = int(raw_input()) ValueError: invalid literal for int() with base 10: 'asdf' I tried this with try and except but it shall work fine to check integer but not a string. I feel that this question may be marked as a duplicate but I think that this query is important, if logically taken.

    Read the article

  • Designing a social network with CQRS, graph databases and relational databases in mind

    - by Siraj Mansour
    I have done quite an amount of research on the topic so far, but i couldn't come up with a conclusion to make up my mind. I am designing a social network and during my research i stumbled upon graph databases, i found neo4j pretty interesting for user relations and traversing through nodes. I also thought of using a relational database such as MS-SQL or MySQL to store entity data only and depending on neo4j for connections between entities. Of course this means more work in my application to store and pull data in and out of 2 different sources. My first question : Is using this approach (graph + relational) a good approach for designing my social network keeping in mind that users on social networks don't have to in synch with real data by split second ? What are the positives and negatives of this approach ? My Second question : I've been doing some reading on CQRS and as i understood it is mostly useful for collaborative environments, and environments where users see a lot of "stale" data. social networks has shared comments, events, etc .. and many users query or update the same data. Could CQRS be a helpful approach ? Would it give any performance/scalability benefits or non-useful complexity ? Is it fairly applicable with my possible choice of (graph + relational) databases approach mentioned in the question above ? My purpose is to know if the approaches i have mentioned above seem good enough for the business context.

    Read the article

  • Can I eventually consider myself a professional developer if I don't have a CS degree? [on hold]

    - by heltonbiker
    Question first, context later: If I am a dedicated, self-taught programmer, always seeking top-quality books AND READING THEM, while successfully applying all that new knowledge into my current work, could I call myself (and offer my work as) a PROFESSIONAL developer? How limiting (or how common) that is nowadays? I am afraid that, no matter how hard I study and practice, it could be too difficult to compete with "actual", college graduated developers, and potential employers might have doubts investing in an "undergraduated" person. Now, context: My former profession is from healthcare sector, then I studied mechanical engineering (quit in the middle), then I studied product design (master degree), and I ended up working (very happily) at an engineering company that manufactures medical devices. For more than two years now my main activity in this company is software development. The devices contain software, and we gave up hiring software development (domain knowledge needed, too much communication cost). My current company sees a lot of value in what I do, but I cannot afford the risk of depending on this single company for the rest of my life, you get it. But a lot of job offers require some minimal formal education, usually a CS degree. Fact is that I am sure this is my target profession, I don't plan to go to another area, it is a pleasure to dive into books that normal people would consider unreadable, but I'm 36 years old and can't see going back to college as a viable alternative.

    Read the article

  • Structure vs. programming

    - by ChristopherW
    Is it bad that I often find myself spending more time on program structure than actually writing code inside methods? Is this common? I feel I spend more time laying the foundation than actually building the house (metaphorically). While I understand that without a good foundation the house will cave in, but does it legitimately need to take half of the project to finalize code structure? I understand design patterns, and I know where to go if I need help on choosing one, but often I find myself doubting my own choices.

    Read the article

  • Packages organisation with MVC design pattern

    - by Oltarus
    I have been programming quite a lot now and still can't decide which of these packages hierachies was the best: package1 Class1Controller Class1Model Class1View package2 Class2Controller Class2Model Class2View or controller Class1Controller Class2Contoller model Class1Model Class2Model view Class1View Class2View In other words, is it better to apply the MVC design pattern to classes or to packages? Is there any reason to choose one over the other? My question is language-agnostic, but I'm mostly a Java programmer, if it does any difference.

    Read the article

  • ERROR while getting interface

    - by user284391
    I have installed the latest version of aircrack-ng, but when i run this code, sudo airmon-ng start wlan0 I get this. sudo airmon-ng start wlan0 Found 4 processes that could cause trouble. If airodump-ng, aireplay-ng or airtun-ng stops working after a short period of time, you may want to kill (some of) them! -e PID Name 463 avahi-daemon 475 avahi-daemon 683 NetworkManager 756 wpa_supplicant Interface Chipset Driver wlan0 Broadcom wl - [phy0]mon0: ERROR while getting interface flags: No such device (monitor mode enabled on mon0) Is there anyone who could help me get this problem solved please.

    Read the article

  • Not Found Apadche2

    - by user285814
    i have installed apache2, actual php version, mysql server and vsftp on my new ubuntu server. I also installed wordpress and gave the user www-data all rights for /var/www/* and put it to 755. I hooked the Domain to the server with * and @ a-record. Now, everytime when i open a Page, it says 404 file not found on server. i dont know how to fix this. can you help me? Edit: I think its because mod_rewrite. i installed mod_rewrite with: sudo a2enmod rewrite sudo service apache2 restart but it still doesnt work.

    Read the article

  • How to create a theme with a picture panel svg or png for GNOME Flashback (Compiz), Unity, Gnome Classic?

    - by user285802
    How to create a theme with a picture panel svg or png for GNOME Flashback (Compiz) and GNOME Flashback (Metacity) and Unity in Ubuntu 14.04. How to create a theme with a picture panel (svg or png) for Unity and Gnome Classic in Ubuntu 12.04. I can not get gnome-panel.css unity.css and image display panel. This is easily done in GTK 2. Is it possible to GTK 3? Give reference to exemplary themes which are correctly displayed panel with image svg or png.

    Read the article

  • Recommended Method to Watch Amazon Prime using Ubuntu 14.04 LTS

    - by Kurt Sanger
    I realize that Hal is no longer in the Ubuntu Software Center for Ubuntu 14.04 and it is only available from a third party at this time. But I would like to know what Ubuntu's plans are for integrating DRM into Linux? Especially with Amazon's integration into the search tool, one would hope that they would make it easier for their Amazon Prime customers to watch Instant Videos. Is the repository for getting Hal for 13.10 safe for use? What will that break if I install it onto 14.04? Or do we need to find another OS that has DRM built into it? If Hal is okay to add to the OS using a third party repo, then why doesn't Ubuntu Software Center support it too? I imagine that Amazon's contract with the video copyright holders requires that they have some protection on electronically distributed media. I also imagine that getting Amazon to change is much harder than getting a bunch of software engineers to fix Ubuntu. Unless they don't want too. At which point Ubuntu isn't really a complete OS. Very disappointing. In general the ease of use of Ubuntu, the software center, and the large variety of applications was alluring. But breaking DRM wasn't a great idea. Can't wait to see what fails in our next update. Please tell us that there is a plan that is going to work in our future.

    Read the article

  • VLC unable to open MRL

    - by faizal
    I am trying to play a VCD using : /usr/bin/vlc vcd:// But i get the error below : VLC media player 2.1.4 Rincewind (revision 2.1.4-0-g2a072be) [0x14ec1c8] main interface error: no suitable interface module [0x1486118] main libvlc error: interface "globalhotkeys,none" initialization failed [0x1486118] main libvlc: Running vlc with the default interface. Use 'cvlc' to use vlc without interface. [0x7f815c0009b8] main input error: open of `vcd://' failed [0x7f815c0009b8] main input error: Your input can't be opened [0x7f815c0009b8] main input error: VLC is unable to open the MRL 'vcd://'. Check the log for details. Any way to resolve this ?

    Read the article

  • Totem not playing VCD

    - by faizal
    I am trying to play a VCD, but Totem gives me an error : Videos requires to install plugins to support the following multimedia feature: VCD protocol source So i did sudo apt-get install ubuntu-restricted-extras I still get the same error when i try to play the VCD again after installation, so i try : sudo apt-get install w64codecs libdvdcss2 But that gives me the error : Package libdvdcss2 is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source E: Unable to locate package w64codecs E: Package 'libdvdcss2' has no installation candidate Any way to make Totem play the VCD?

    Read the article

  • How to fix no splash screen in Ubuntu after nvidia proprietary driver installation (also black borders)

    - by Fabio Trevisiol
    This is soultion how to fix no splash screen in Ubuntu after nvidia proprietary driver installation. It's no matter what Ubuntu version you use, it should work anyway. (TESTED ON 14.04) Open your terminal and type: sudo apt-get install v86d (TEST WITHOUT) Then: sudo gedit /etc/default/grub Find this line: #GRUB_GFXMODE=640x480 Add below (of course choose your resolution): GRUB_GFXMODE=1024x768x32 (TRY WITHOUT OR DIFFERENT BIT DEPTH) GRUB_GFXPAYLOAD_LINUX=1920x1080x32 (YOU CAN ALSO USE THE KEEP OPTION) Save file and type in terminal: echo FRAMEBUFFER=y | sudo tee /etc/initramfs-tools/conf.d/splash (ALLOWS TO AVOID THAT THE SPLASH SCREEN IS DISPLAYED FOR A FEW SECONDS) sudo update-initramfs -u sudo update-grub2 For all those who complain about the presence of black borders in "plymouth", try to make these changes before installing the nvidia driver or switch back from nvidia to nouveau and from nouveau to nvidia. Kernel update from the Software Updater? It happened to me; I don't know if it matters. I don't know for which of these reasons, but after a few reboots, the black borders are gone. UPDATE discovered the secret: during all these beautiful things, something strange happened. glxinfo | grep vendor server glx vendor string: SGI client glx vendor string: Mesa Project and SGI OpenGL vendor string: nouveau

    Read the article

  • cannot rename files when saving

    - by Botond Vajna
    I am using xubuntu 13.10. Since the last update, when I am saving files I cannot rename other files, there are missing buttons in context menu like rename, cut, copy, etc... let`s say I edited the file named style.css in firefox, and I want to save it, but i do not want to overwrite the original, I want to rename the original for ex: style_orig.css and save the edited file with the name style.css. for doing that I must open thunar, navigate to that file, and rename it, after that, I can save the file from firefox. let`s reformulate this question: if I want to overwrite a file, but preserve the original, then I must make a copy of the original. Well, I can not do this when saving the file from the application, I must open thunar and navigate to that file which is an additional task I have to do. It`s a waste of time.

    Read the article

  • 'Xojo' is the only application that I can't install

    - by Gichan
    I can't install xojo. When I click install in the software center it's not progressing. In the terminal it's stuck in : gichan02@gichan02-Latitude-D520:~$ sudo apt-get install xojo [sudo] password for gichan02: Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: xojo-bin The following NEW packages will be installed: xojo xojo-bin 0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded. Need to get 209 MB/209 MB of archives. After this operation, 596 MB of additional disk space will be used. Do you want to continue? [Y/n] Y 0% [Working] then after waiting for an hour for progress it says: Failed to fetch https://private-ppa.launchpad.net/commercial-ppa-uploaders/xojo/ubuntu/pool/main/x/xojo/xojo-bin_2013.41-0ubuntu1_i386.deb Could not resolve host: private-ppa.launchpad.net So I added apt repository for 'private-ppa': deb https://ging-giana:[email protected]/commercial-ppa-uploaders/xojo/ubuntu trusty main Then when I try 'apt-get update': GPG error: https://private-ppa.launchpad.net trusty Release: The following signatures were invalid: NODATA 2 Then I noticed something the Software Sources:Other software TAB: Added by software-center; credentials stored in /etc/apt/auth.conf https://private-ppa.launchpad.net/commercial-ppa-uploaders/xojo/ubuntu So i go to the '/etc/apt/auth.conf' ,but It cannot be opened and it is not a keyserver. So i uncheck: Added by software-center; credentials stored in /etc/apt/auth.conf https://private-ppa.launchpad.net/commercial-ppa-uploaders/xojo/ubuntu GPG error was gone. But then again I found myself at the beginning of the problem.STUCK at '0% [Working]'. 'Xojo' is the only application that I can't install.Any explanation why is it like that?

    Read the article

  • how to bind super+s to indicator applete complete? - gnome classic

    - by rrosa
    i use gnome classic, i'm not a mouse fan. when i get an email while i'm writing code, i i would super+s to get to the indicator-applet-complete and read it. also to write emails, or check unread instant messages. upgrading from 12.04 to 14.04 made super+s bind to applications menu rather than the indicator applet complete. i removed the binding from the applications using dconf-editor, navigating to: org-gnome-desktop-wm-keybindings and disabling (['disabled']) the panel-main-menu key. now, how do i bind super+s to the indicator applet complete? it seems to be some how binded, since if if press super+s and then move the cursor over the applet it'll open the drop down menus (and it won't if i hover without pressing super+s) but i don't want to have to use the mouse...

    Read the article

  • Adding my face to my web-site in Google's search result

    - by Roman Matveev
    I'm trying to accomplish the rich snippet to the template of my future web-site. The data format is review and I used the microdata formatting to add all necessary information to the web-page. The Structured Data Testing Tool delivered rating, author information and review date: However there is no my face image and the sections related to authorship are empty: I made all that recommended to link my Google+ profile to the web-site: I did something wrong? Or I will not be able to see my face in the test tools ever and it will be in the real SERP?

    Read the article

  • Website hosting and deployment

    - by squixy
    I'm relatively new to Web Development especially when it comes to infrastructure. I have AngularJS application build and served by brunch.io locally. It uses rails-api JSON data. I'd like to deploy my angular application separately from rails server. For now, JS app is placde inside public directory of backend server and deployed together. It isn't elegant nor effective so I want to use some other hosting service. I was thinking about VPS where I could place both Angular and Ruby applications. I read about NodeJS or Nginx that can serve static files, but I don't have any knowledge or experience with these technologies. How is the best way to provide separate frontend and backend applications communicating with each other?

    Read the article

  • How do I fix the Google Webmaster Tools warning: "URL not followed?"

    - by user3611500
    A few days after submitting my sitemap to Google, I received this warning: When we tested a sample of URLs from your Sitemap, we found that some URLs redirect to other locations. We recommend that your Sitemap contain URLs that point to the final destination (the redirect target) instead of redirecting to another URL. The example URL Google gave me is http://iketqua.net/?_escaped_fragment_=CIDTKT/mien-trung/xo-so-kon-tum I checked all possible things that I could think of, but still can't figure out what the warning is about! My sitemap: http://iketqua.net/sitemap.xml

    Read the article

  • How do I put different textures on different walls? LWJGL

    - by lehermj
    So far I have it so you are running around in a box, but all of the walls are the same texture! I've loaded up other textures for the walls (I want the walls a different texture than the floor) but it seems as if its being ignored... Here's my code: int floorTexture = glGenTextures(); { InputStream in = null; try { in = new FileInputStream("floor.png"); PNGDecoder decoder = new PNGDecoder(in); ByteBuffer buffer = BufferUtils.createByteBuffer(4 * decoder.getWidth() * decoder.getHeight()); decoder.decode(buffer, decoder.getWidth() * 4, Format.RGBA); buffer.flip(); glBindTexture(GL_TEXTURE_2D, floorTexture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, decoder.getWidth(), decoder.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer); glBindTexture(GL_TEXTURE_2D, floorTexture); } catch (FileNotFoundException ex) { System.err.println("Failed to find the texture files."); ex.printStackTrace(); Display.destroy(); System.exit(1); } catch (IOException ex) { System.err.println("Failed to load the texture files."); ex.printStackTrace(); Display.destroy(); System.exit(1); } finally { if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } } int wallTexture = glGenTextures(); { InputStream in = null; try { in = new FileInputStream("walls.png"); PNGDecoder decoder = new PNGDecoder(in); ByteBuffer buffer = BufferUtils.createByteBuffer(4 * decoder.getWidth() * decoder.getHeight()); decoder.decode(buffer, decoder.getWidth() * 4, Format.RGBA); buffer.flip(); glBindTexture(GL_TEXTURE_2D, wallTexture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, decoder.getWidth(), decoder.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer); glBindTexture(GL_TEXTURE_2D, wallTexture); } catch (FileNotFoundException ex) { System.err.println("Failed to find the texture files."); ex.printStackTrace(); Display.destroy(); System.exit(1); } catch (IOException ex) { System.err.println("Failed to load the texture files."); ex.printStackTrace(); Display.destroy(); System.exit(1); } finally { if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } } int ceilingDisplayList = glGenLists(1); glNewList(ceilingDisplayList, GL_COMPILE); glBegin(GL_QUADS); glTexCoord2f(0, 0); glVertex3f(-gridSize, ceilingHeight, -gridSize); glTexCoord2f(gridSize * 10 * tileSize, 0); glVertex3f(gridSize, ceilingHeight, -gridSize); glTexCoord2f(gridSize * 10 * tileSize, gridSize * 10 * tileSize); glVertex3f(gridSize, ceilingHeight, gridSize); glTexCoord2f(0, gridSize * 10 * tileSize); glVertex3f(-gridSize, ceilingHeight, gridSize); glEnd(); glEndList(); int wallDisplayList = glGenLists(1); glNewList(wallDisplayList, GL_COMPILE); glBegin(GL_QUADS); // North wall glTexCoord2f(0, 0); glVertex3f(-gridSize, floorHeight, -gridSize); glTexCoord2f(0, gridSize * 10 * tileSize); glVertex3f(gridSize, floorHeight, -gridSize); glTexCoord2f(gridSize * 10 * tileSize, gridSize * 10 * tileSize); glVertex3f(gridSize, ceilingHeight, -gridSize); glTexCoord2f(gridSize * 10 * tileSize, 0); glVertex3f(-gridSize, ceilingHeight, -gridSize); // West wall glTexCoord2f(0, 0); glVertex3f(-gridSize, floorHeight, -gridSize); glTexCoord2f(gridSize * 10 * tileSize, 0); glVertex3f(-gridSize, ceilingHeight, -gridSize); glTexCoord2f(gridSize * 10 * tileSize, gridSize * 10 * tileSize); glVertex3f(-gridSize, ceilingHeight, +gridSize); glTexCoord2f(0, gridSize * 10 * tileSize); glVertex3f(-gridSize, floorHeight, +gridSize); // East wall glTexCoord2f(0, 0); glVertex3f(+gridSize, floorHeight, -gridSize); glTexCoord2f(gridSize * 10 * tileSize, 0); glVertex3f(+gridSize, floorHeight, +gridSize); glTexCoord2f(gridSize * 10 * tileSize, gridSize * 10 * tileSize); glVertex3f(+gridSize, ceilingHeight, +gridSize); glTexCoord2f(0, gridSize * 10 * tileSize); glVertex3f(+gridSize, ceilingHeight, -gridSize); // South wall glTexCoord2f(0, 0); glVertex3f(-gridSize, floorHeight, +gridSize); glTexCoord2f(gridSize * 10 * tileSize, 0); glVertex3f(-gridSize, ceilingHeight, +gridSize); glTexCoord2f(gridSize * 10 * tileSize, gridSize * 10 * tileSize); glVertex3f(+gridSize, ceilingHeight, +gridSize); glTexCoord2f(0, gridSize * 10 * tileSize); glVertex3f(+gridSize, floorHeight, +gridSize); glEnd(); glEndList(); int floorDisplayList = glGenLists(1); glNewList(floorDisplayList, GL_COMPILE); glBegin(GL_QUADS); glTexCoord2f(0, 0); glVertex3f(-gridSize, floorHeight, -gridSize); glTexCoord2f(0, gridSize * 10 * tileSize); glVertex3f(-gridSize, floorHeight, gridSize); glTexCoord2f(gridSize * 10 * tileSize, gridSize * 10 * tileSize); glVertex3f(gridSize, floorHeight, gridSize); glTexCoord2f(gridSize * 10 * tileSize, 0); glVertex3f(gridSize, floorHeight, -gridSize); glEnd(); glEndList();

    Read the article

  • Eculidean space and vector magnitude

    - by Starkers
    Below we have distances from the origin calculated in two different ways, giving the Euclidean distance, the Manhattan distance and the Chebyshev distance. Euclidean distance is what we use to calculate the magnitude of vectors in 2D/3D games, and that makes sense to me: Let's say we have a vector that gives us the range a spaceship with limited fuel can travel. If we calculated this with Manhattan metric, our ship could travel a distance of X if it were travelling horizontally or vertically, however the second it attempted to travel diagonally it could only tavel X/2! So like I say, Euclidean distance does make sense. However, I still don't quite get how we calculate 'real' distances from the vector's magnitude. Here are two points, purple at (2,2) and green at (3,3). We can take two points away from each other to derive a vector. Let's create a vector to describe the magnitude and direction of purple from green: |d| = purple - green |d| = (purple.x, purple.y) - (green.x, green.y) |d| = (2, 2) - (3, 3) |d| = <-1,-1> Let's derive the magnitude of the vector via Pythagoras to get a Euclidean measurement: euc_magnitude = sqrt((x*x)+(y*y)) euc_magnitude = sqrt((-1*-1)+(-1*-1)) euc_magnitude = sqrt((1)+(1)) euc_magnitude = sqrt(2) euc_magnitude = 1.41 Now, if the answer had been 1, that would make sense to me, because 1 unit (in the direction described by the vector) from the green is bang on the purple. But it's not. It's 1.41. 1.41 units is the direction described, to me at least, makes us overshoot the purple by almost half a unit: So what do we do to the magnitude to allow us to calculate real distances on our point graph? Worth noting I'm a beginner just working my way through theory. Haven't programmed a game in my life!

    Read the article

  • Implementing movement on a grid

    - by Dvole
    I have a simple snake game, where I have other NPC snakes on the field. How do I calculate the movement of those other snakes so that they did not hit walls, and each other? So far I have it like this: I check for current coordinates and when there is a wall nearby I change direction to some other one. And so on, this way the snakes never collide the walls. But not actually colliding other snakes, how do I prevent this? I figured I could probe for the direction I'm heading and if there is anything there I would change direction too, but there is a set of situation where this won't work, for example if another snake will block off all exits later.

    Read the article

  • SDL 2.0: is there a library to create 2D particle effects rapidly?

    - by mm24
    I would like to create an light/explosion particle effect using some in built library. I am used to Cocos2D where there are specific classes that you can simply initialize in a certain position and producing a certain particle effect. Is there a way to do so in SDL 2.0 C++? I have found this tutorial but it seems to go for a "build it yoursefl" solution, which is ok but I do not want to re-invent the wheel if someone else has already built it.

    Read the article

  • Avoid double compression of resources

    - by user1095108
    I am using .pngs for my textures and am using a virtual file system in a .zip file for my game project. This means my textures are compressed and decompressed twice. What are the solutions to this double compression problem? One solution I've heard about is to use .tgas for textures, but it seems ages ago, since I've heard that. Another solution is to implement decompression on the GPU and, since that is fast, forget about the overhead.

    Read the article

  • Encode two integers into colour values and compare them in a HLSL shader

    - by Ben Slinger
    I am writing a 2D point and click adventure game in Monogame, and I'd like to be able to create an image mask for every room which defines which parts of the background a character can walk behind, and at which Y value a character needs to be at for the background to be drawn above the character. I haven't done any shader work before but after doing some reading I thought the following solution should work: Create a mask for the room with different walk behind areas painted in a colour that defines the baseline Y value (Walk Behind Mask) Render all objects to a RenderTarget2D (Base Texture) Render all objects to a different RenderTarget2D, but changing every pixel of each object to a colour that defines its Y value (Position Mask) Pass these two textures plus the image mask into the shader, and for each pixel compare the colour of the image mask to the colour of the Position Mask to the Walk Behind Mask - if the Position Mask pixel is larger (thus lower on the screen and closer to the camera) than the Walk Behind Mask, draw the pixel from the Base Texture, otherwise draw a transparent pixel (allowing the background to show through). I've got it mostly working, but I'm having trouble packing and unpacking the Y values into colours and retrieving them correctly in the shader. Here are some code examples of how I'm doing it so far: (When drawing to the Position Mask RenderTarget2D) Color posColor = new Color(((int)Position.Y >> 16) & 255, ((int)Position.Y >> 8) & 255, (int)Position.Y & 255); So as far as I can tell, this should be taking the first 3 bytes of the position integer and encoding them into a 4 byte colour (ignoring the alpha as the 4th byte). This seems to work fine, as when my character is at Y = 600, the resulting Color from this is: {[Color: R=0, G=2, B=88, A=255, PackedValue=4283957760]}. I then have an area in my Walk Behind Mask that I only want the character to be displayed behind if his Y value is lower than 655, so I've painted it with R=0, G=2, B=143, A=255. Now, I think I have the shader OK as well, here's what I have: sampler BaseTexture : register(s0); sampler MaskTexture : register(s1); sampler PositionTexture : register(s2); float4 mask( float2 coords : TEXCOORD0 ) : COLOR0 { float4 color = tex2D(BaseTexture, coords); float4 maskColor = tex2D(MaskTexture, coords); float4 positionColor = tex2D(PositionTexture, coords); float maskCompare = (maskColor.r * pow(2,24)) + (maskColor.g * pow(2,16)) + (maskColor.b * pow(2,8)); float positionCompare = (positionColor.r * pow(2,24)) + (positionColor.g * pow(2,16)) + (positionColor.b * pow(2,8)); return positionCompare < maskCompare ? float4(0,0,0,0) : color; } technique Technique1 { pass NoEffect { PixelShader = compile ps_3_0 mask(); } } This isn't working, however - currently all characters are displayed behind the walk behind area, regardless of their Y value. I tried printing out some debug info by grabbing the pixel from both the Position Mask and the Walk Under Mask under the current mouse position, and it seems like maybe the colours aren't being rendered to the Position Mask correctly? When calculating the colour in that code above I'm getting R=0, G=2, B=88, A=255, but when I mouseover my character I get R=0, G=0, B=30, A=255. Any ideas what I'm doing wrong? It seems like maybe I'm losing some information when rendering to the RenderTarget2D, but I'm now knowledgeable enough to figure out what's happening. Also, I should probably ask, is this an efficient way to do this? Will there be a performance impact? Edit: Whoops, turns out there was a bug that I'd introduced myself, I was drawing out the Position Mask with the position Color, left over from some early testing I was doing. So this solution is working perfectly, though I'm still interested in whether this is an efficient solution performance wise.

    Read the article

  • Algorithm for optimal control on space ship using accelerometer input data

    - by mm24
    Does someone have a good algorithm for controlling a space ship in a vertical shooter game using acceleration data? I have done a simple algorithm, but works very badly. I save an initial acceleration value (used to calibrate the movement according to the user's initial position) and I do subtract it from the current acceleration so I get a "calibrated" value. The problem is that basing the movement solely on relative acceleration has an effect of loss of sensitivity: certain movements are independent from the initial position. Would anyone be able to share a a better solution? I am wondering if I should use/integrate also inputs from gyroscope hardware. Here is my sample of code for a Cocos2d iOS game: - (void) accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration { if (calibrationLayer.visible){ [self evaluateCalibration:acceleration]; initialAccelleration=acceleration; return; } if([self evaluatePause]){ return; } ShooterScene * shooterScene = (ShooterScene *) [self parent]; ShipEntity *playerSprite = [shooterScene playerShip]; float accellerationtSensitivity = 0.5f; UIAccelerationValue xAccelleration = acceleration.x - initialAccelleration.x; UIAccelerationValue yAccelleration = acceleration.y - initialAccelleration.y; if(xAccelleration > 0.05 || xAccelleration < -0.05) { [playerSprite setPosition:CGPointMake(playerSprite.position.x + xAccelleration * 80, playerSprite.position.y + yAccelleration * 80)]; } else if(yAccelleration > 0.05 || yAccelleration < -0.05) { [playerSprite setPosition:CGPointMake(playerSprite.position.x + xAccelleration * 80, playerSprite.position.y + yAccelleration * 80)]; } }

    Read the article

< Previous Page | 7 8 9 10 11 12 13 14 15 16  | Next Page >