As was foretold, we've added advertisements to the forums! If you have questions, or if you encounter any bugs, please visit this thread: https://forums.penny-arcade.com/discussion/240191/forum-advertisement-faq-and-reports-thread/
We're funding a new Acquisitions Incorporated series on Kickstarter right now! Check it out at https://www.kickstarter.com/projects/pennyarcade/acquisitions-incorporated-the-series-2

The beginner programming thread

1131416181963

Posts

  • AndorienAndorien Registered User regular
    edited March 2008
    Jasconius wrote: »
    Andorien wrote: »
    I have another XNA question.
    Currently I'm messing around trying to create a simple little 2D sprite game. I've been reading some tutorials and as far as most of them get with 2D is just drawing a sprite to the screen. They then either want to jump right into making a basic physics engine or into 3D.

    What I need to know is what is the best way "i.e. best practice" for taking a sprite off the screen. What I mean is, lets say I have SpriteA and lets say SpriteA is the sprite for a giant enemy crab or something. Lets also say that I hit the weak spot on SpriteA for massive damange and killed the crab. Now that the grab is dead I don't want to draw SpriteA to the screen anymore. So do I just not call the draw method or is there some kind of content unload method I should be calling?

    Just don't draw the sprite to the screen anymore. The only thing that might need to be unloaded is the sprite data itself, but
    1. It'll be unloaded when the program ends.
    2. You'll probably want to keep it incase you need to use it again without having to load it again.
    If you need to get rid of it before you call Content.Unload(), you can do Texture2D.Dispose(), which should release its unmanaged resources (and will cause an error if you try and draw it after that).

    Good stuff, thanks.

    On the subject of this, does C# have support for destructors?

    Kinda, but from what I've read its advised that beginners not mess with them. But I think all constructors and destructs are just overloads of the base class of all classes or something.

    C# does have destructors, but they're not near as important as they are in C++, as they'll get called whenver the GC feels like deleting the data. They're mostly used if you have any unmanaged resources allocated.

    Andorien on
  • AndorienAndorien Registered User regular
    edited March 2008
    It should be noted that my like of XNA is actually the only thing preventing me from switching to Linux.

    Andorien on
  • JacksNsomniaJacksNsomnia Registered User regular
    edited March 2008
    Could someone explain to me how to get "monthName" to print out what is assigned to it?
    void printHeader  ( int year, int month )
    {
    	char monthName;
    	
    	switch (month)
    	{
    	case 1: monthName = "January";
    		break;
    	case 2: monthName = "February";
    		break;
    	case 3: monthName = "March";
    		break;
    	case 4: monthName = "April";
    		break;
    	case 5: monthName = "May";
    		break;
    	case 6: monthName = "June";
    		break;
    	case 7: monthName = "July";
    		break;
    	case 8: monthName = "August";
    		break;
    	case 9: monthName = "September";
    		break;
    	case 10: monthName = "October";
    		break;
    	case 11: monthName = "November";
    		break;
    	case 12: monthName = "December";
    		break;
    	}
    	printf("\n\n%c                      %d\n"
           "Sun Mon Tue Wed Thu Fri Sat\n"
           "=== === === === === === ===\n", monthName, year);
    }
    

    Thanks

    JacksNsomnia on
    24584849if1gs7.jpg
  • LittleBootsLittleBoots Registered User regular
    edited March 2008
    Could someone explain to me how to get "monthName" to print out what is assigned to it?
    void printHeader  ( int year, int month )
    {
    	char monthName;
    	
    	switch (month)
    	{
    	case 1: monthName = "January";
    		break;
    	case 2: monthName = "February";
    		break;
    	case 3: monthName = "March";
    		break;
    	case 4: monthName = "April";
    		break;
    	case 5: monthName = "May";
    		break;
    	case 6: monthName = "June";
    		break;
    	case 7: monthName = "July";
    		break;
    	case 8: monthName = "August";
    		break;
    	case 9: monthName = "September";
    		break;
    	case 10: monthName = "October";
    		break;
    	case 11: monthName = "November";
    		break;
    	case 12: monthName = "December";
    		break;
    	}
    	printf("\n\n%c                      %d\n"
           "Sun Mon Tue Wed Thu Fri Sat\n"
           "=== === === === === === ===\n", monthName, year);
    }
    

    Thanks

    I'm a newb but maybe you should try monthName as type string or char[].

    LittleBoots on

    Tofu wrote: Here be Littleboots, destroyer of threads and master of drunkposting.
  • JacksNsomniaJacksNsomnia Registered User regular
    edited March 2008
    How do I declare a string?

    JacksNsomnia on
    24584849if1gs7.jpg
  • LittleBootsLittleBoots Registered User regular
    edited March 2008
    How do I declare a string?

    Well, if you're in C++ you used to be able to include <string> and declare a string using "string MyString;" I believe. But it's been awhile since I've messed with C++ or C.

    LittleBoots on

    Tofu wrote: Here be Littleboots, destroyer of threads and master of drunkposting.
  • SmasherSmasher Starting to get dizzy Registered User regular
    edited March 2008
    Is this for c or c++? Strings are treated differently between the two, and are much simpler and safer the c++ way (though you can do strings the c way in c++ if you really want/need to).

    Smasher on
  • JacksNsomniaJacksNsomnia Registered User regular
    edited March 2008
    It's in C.

    JacksNsomnia on
    24584849if1gs7.jpg
  • JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited March 2008
    Anyone have any good resources for tutorials for programming momentum and drift for 2D movement?

    I am totally stuck.

    Jasconius on
  • JaninJanin Registered User regular
    edited March 2008
    It's in C.

    Declare it as char *

    Janin on
    [SIGPIC][/SIGPIC]
  • JacksNsomniaJacksNsomnia Registered User regular
    edited March 2008
    I fixed it.

    JacksNsomnia on
    24584849if1gs7.jpg
  • ecco the dolphinecco the dolphin Registered User regular
    edited March 2008
    Janin wrote: »
    It's in C.

    Declare it as char *

    I'm a bit late now, but surely it should be const char *?

    ecco the dolphin on
    Penny Arcade Developers at PADev.net.
  • SushisourceSushisource Registered User regular
    edited March 2008
    Jasconius wrote: »
    Big question for those of you using XNA.

    So, these fancy new spriteFonts are fine and dandy, but I want to do something... unorthadox with them

    I need to somehow let the user enter a string, then create a 2d array with width (in pixels) that that string would become when run through the spritefont dealy, and height being the height of the highest letter. Then I need to fill this array with a 1 wherever the image is black and a 0 wherever it's white.

    So, for example, the word LOL

    Would end up (roughly, using a small blocky font) in the array as

    100010010
    100101010
    100101010
    110010011

    This array will then become that font, but in 3d little cubes.

    Any help deserves mad props. Thanks.

    Well with a combination of System.Text and System.Drawing you can create Bitmaps from text input.

    Then you could take the resultant bitmap and analyze each bit for it's color and then create a matrix or what have you of 0's and 1's.

    But that array would gigantic (one entry per pixel) so you'd have to think of some way to shrink it down to the right size, say, for every 5 adjacent black pixels only do a single 1.

    That's all I can think of on a whim.

    Would the method you are talking about make a bitmap of only the word the user enters, or the whole character set? Because my input is only ever going to be one word, at fixed font height of 8, so the array isn't going to be that big.

    Sushisource on
    Some drugee on Kavinsky's 1986
    kavinskysig.gif
  • Zetetic ElenchZetetic Elench Registered User regular
    edited March 2008
    Interrupt wrote: »
    [Re: C#] One thing I'd like to ask is; I see a lot of animation examples, for making things rotate or fade in and out, and so on, and they're often just a time counter plugged into a sine function. Is that the best way to go about things which are visual and time dependent? Moving a box onto the screen in a way which is more organic, for example - coming in fast and slowing down to stop right where you want it.

    It sounds like you're looking at an easing function which creates a smoother transition or movement than a linear change over time. If you use a box moving from one place to another as an example, one type of easing would be to start out fast but slow down as it moves into place instead of having it abruptly stop. A google search for easing functions will find tons.

    <3

    Exactly what I was after.

    It is so difficult to look for something when you don't know what it's called.

    Zetetic Elench on
    nemosig.png
  • JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited March 2008
    Jasconius wrote: »
    Big question for those of you using XNA.

    So, these fancy new spriteFonts are fine and dandy, but I want to do something... unorthadox with them

    I need to somehow let the user enter a string, then create a 2d array with width (in pixels) that that string would become when run through the spritefont dealy, and height being the height of the highest letter. Then I need to fill this array with a 1 wherever the image is black and a 0 wherever it's white.

    So, for example, the word LOL

    Would end up (roughly, using a small blocky font) in the array as

    100010010
    100101010
    100101010
    110010011

    This array will then become that font, but in 3d little cubes.

    Any help deserves mad props. Thanks.

    Well with a combination of System.Text and System.Drawing you can create Bitmaps from text input.

    Then you could take the resultant bitmap and analyze each bit for it's color and then create a matrix or what have you of 0's and 1's.

    But that array would gigantic (one entry per pixel) so you'd have to think of some way to shrink it down to the right size, say, for every 5 adjacent black pixels only do a single 1.

    That's all I can think of on a whim.

    Would the method you are talking about make a bitmap of only the word the user enters, or the whole character set? Because my input is only ever going to be one word, at fixed font height of 8, so the array isn't going to be that big.

    Just the string input.

    You create a bitmap of a predetermined size (you can even load a white BMP or PNG from file as a starter, as a matter of fact, I recommend it). Then, you create a new Brush, the brush is simple since it's just black. Then, there is a method, I don't remember where, either in System.Text or System.Drawing that will let you draw a string input onto a bitmap using that brush, a font, font-size, and a few other parameters.

    I have the code at work, if I can find it I will pass it along.

    Jasconius on
  • InterruptInterrupt Registered User regular
    edited March 2008
    Jasconius wrote: »
    Anyone have any good resources for tutorials for programming momentum and drift for 2D movement?

    I am totally stuck.

    Depending on what you're doing, this Gamedev tutorial on 2D Car physics might be what you're looking for:
    http://www.gamedev.net/reference/programming/features/2dcarphys/page3.asp

    It sounds like you're doing car physics but if you're doing something simpler then you can usually just keep a Velocity vector that gets added onto the Position vector every frame and altering that Velocity when getting keypresses instead of changing the Position directly.

    Interrupt on
  • JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited March 2008
    Interrupt wrote: »
    Jasconius wrote: »
    Anyone have any good resources for tutorials for programming momentum and drift for 2D movement?

    I am totally stuck.

    Depending on what you're doing, this Gamedev tutorial on 2D Car physics might be what you're looking for:
    http://www.gamedev.net/reference/programming/features/2dcarphys/page3.asp

    It sounds like you're doing car physics but if you're doing something simpler then you can usually just keep a Velocity vector that gets added onto the Position vector every frame and altering that Velocity when getting keypresses instead of changing the Position directly.

    That's pretty close, and the site overall is exactly what I was looking for, thanks.

    Jasconius on
  • SushisourceSushisource Registered User regular
    edited March 2008
    Jasconius wrote: »
    Just the string input.

    You create a bitmap of a predetermined size (you can even load a white BMP or PNG from file as a starter, as a matter of fact, I recommend it). Then, you create a new Brush, the brush is simple since it's just black. Then, there is a method, I don't remember where, either in System.Text or System.Drawing that will let you draw a string input onto a bitmap using that brush, a font, font-size, and a few other parameters.

    I have the code at work, if I can find it I will pass it along.

    I would greatly appreciate it if you could procure said code. Thanks!

    On the subject of your question, remember that when working with many physics-formula based collisions it can be necessary to keep a very accurate timer. I say this because I had loads of issues with it a while back, so be careful.

    Sushisource on
    Some drugee on Kavinsky's 1986
    kavinskysig.gif
  • JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited March 2008
    Jasconius wrote: »
    Just the string input.

    You create a bitmap of a predetermined size (you can even load a white BMP or PNG from file as a starter, as a matter of fact, I recommend it). Then, you create a new Brush, the brush is simple since it's just black. Then, there is a method, I don't remember where, either in System.Text or System.Drawing that will let you draw a string input onto a bitmap using that brush, a font, font-size, and a few other parameters.

    I have the code at work, if I can find it I will pass it along.

    I would greatly appreciate it if you could procure said code. Thanks!

    On the subject of your question, remember that when working with many physics-formula based collisions it can be necessary to keep a very accurate timer. I say this because I had loads of issues with it a while back, so be careful.

    I'm doing it in Flash so my timers will be inconsistent by nature unless I keep the code very lightweight (which it is right now). My problem will be when I throw 50+ AI's on to the map.

    Jasconius on
  • DigDug2000DigDug2000 Registered User regular
    edited March 2008
    Kinda a weird question but:

    I have a Firefox extension that hooks into the Vista compositor and lets you draw glass on windows. Works fine here for me, but (apparently) not for other people. I've only sent it to a few, and none of them were exactly my ideal testers. I'm not sure if the problem was that they didn't have composition enabled correctly, or if it was some problem with my code.

    I'm just loading the DLL at runtime (is that the best way to do something like this?). Here's most of the relevent code (trying to remove the extra XPCOM stuff).

    Setting up:
    typedef HRESULT (WINAPI*ExtendFramePtr)(HANDLE hWnd, MARGINS* margins);
    typedef HRESULT (WINAPI*IsCompositionEnabledPtr)(BOOL* pfEnabled);
    
    static ExtendFramePtr CompositorExtendFrame = NULL;
    static IsCompositionEnabledPtr CompositorIsCompositionEnabled = NULL;
    
    Constructor:
    gDWMDLLInst = NULL;
    gDWMDLLInst = ::LoadLibrary(L"dwmapi.dll");
    if(gDWMDLLInst) {
      CompositorExtendFrame = (ExtendFramePtr)GetProcAddress(gDWMDLLInst, "DwmExtendFrameIntoClientArea");
      CompositorIsCompositionEnabled = (IsCompositionEnabledPtr)GetProcAddress(gDWMDLLInst, "DwmIsCompositionEnabled");
    }
    
    Calling the function:
    hr = CompositorIsCompositionEnabled(_retval);
    ...
    hr = CompositorExtendFrame (hWnd, margins);
    
    This all seems pretty simple to me. Anyone know off the top of their head what might be wrong (or have Vista running with glass and can test)?

    DigDug2000 on
  • Recoil42Recoil42 Registered User regular
    edited March 2008
    Anyone here have any experience with AVL trees?

    edit: Nevermind, got it!

    Recoil42 on
  • iTunesIsEviliTunesIsEvil Cornfield? Cornfield.Registered User regular
    edited March 2008
    DigDug2000 wrote: »
    Glass & Firefox
    I've got Vista running with Aero enabled, and I'd be happy to test. Do you have the MARGINS type set up correctly? Alternately, how do you have it set up?

    iTunesIsEvil on
  • LoneIgadzraLoneIgadzra Registered User regular
    edited March 2008
    eecc wrote: »
    Janin wrote: »
    It's in C.

    Declare it as char *

    I'm a bit late now, but surely it should be const char *?

    Why const char *?

    Also oh god C strings suck much better to switch to C++ if only for strings. If it's a class assignment in C, tell the professor he is stupid there is no reason to ever use C strings when you can just add "pp" to the file extension, use g++ instead of gcc, and have strings that aren't so completely prone to fuckups.

    C strings aren't hard to understand, they're just worthless and you need a reference sheet for the function names because they're from 1200BC and are stupid.

    LoneIgadzra on
  • ecco the dolphinecco the dolphin Registered User regular
    edited March 2008
    eecc wrote: »
    Janin wrote: »
    It's in C.

    Declare it as char *

    I'm a bit late now, but surely it should be const char *?

    Why const char *?

    Also oh god C strings suck much better to switch to C++ if only for strings. If it's a class assignment in C, tell the professor he is stupid there is no reason to ever use C strings when you can just add "pp" to the file extension, use g++ instead of gcc, and have strings that aren't so completely prone to fuckups.

    C strings aren't hard to understand, they're just worthless and you need a reference sheet for the function names because they're from 1200BC and are stupid.

    Because the original assignment was something like:

    pszMonth = "June";

    "June" will typically be allocated in some form of read-only memory (e.g. put into code space), and so attempting to write to the string will result in an access violation/segmentation fault. In other words, the string is read-only.

    Making the char * a const will let the compiler help enforce this read-only aspect of the string.

    Also, there are situations where C++ is not an appropriate substitute for C. While I share your opinion that C++ strings are more convenient than C strings, the blanket statement that C++ should always be used over C is a bit strong.

    ecco the dolphin on
    Penny Arcade Developers at PADev.net.
  • JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited March 2008
    Alright might as well post my problem.

    This is in Actionscript. I am trying to program an Asteroids style ship movement class that includes inertia when turning.

    This is the relevant code
    if (m_KeyPressed_UP && !m_KeyPressed_DOWN)
    			{
    				
    				var vectorX:Number = Math.cos(2.0 * Math.PI * (this.rotation - 90) / 360.0);
    				var vectorY:Number = Math.sin(2.0 * Math.PI * (this.rotation - 90) / 360.0);			
    				
    				var currentMaxX:Number = ((PlayerShip.Speed * vectorX) / EnB2.SPEED_SCALE);
    				var currentMaxY:Number = ((PlayerShip.Speed * vectorY) / EnB2.SPEED_SCALE);
    				
    				
    				
    				if(Math.abs(currentMaxX) > m_AbsoluteMaxX)
    				{
    					if(currentMaxX > 0)
    					{
    						currentMaxX = m_AbsoluteMaxX;
    					}
    					else
    					{
    						currentMaxX = m_AbsoluteMaxX * -1;
    					}
    				}
    				
    				if(Math.abs(currentMaxY) > m_AbsoluteMaxY)
    				{
    					if(currentMaxY > 0)
    					{
    						currentMaxY = m_AbsoluteMaxY;
    					}
    					else
    					{
    						currentMaxY = m_AbsoluteMaxY * -1;
    					}
    				}				
    				
    				nextX = (currentMaxX * PlayerShip.Acceleration) + m_PreviousXMovement;
    				nextY = (currentMaxY * PlayerShip.Acceleration) + m_PreviousYMovement;							
    				
    				
    				if (Math.abs(nextX) > Math.abs(currentMaxX))
    				{					
    					nextX = currentMaxX;					
    				}
    				
    				if (Math.abs(nextY) > Math.abs(currentMaxY))
    				{								
    					nextY = currentMaxY;					
    				}
    				
    				PlayerMap.x = PlayerMap.x + nextX;
    				PlayerMap.y = PlayerMap.y + nextY;
    
    				m_PreviousXMovement = nextX;
    				m_PreviousYMovement = nextY;				
    
    			}
    			if (!m_KeyPressed_UP && !m_KeyPressed_DOWN)
    			{
    				
    				if (m_PreviousXMovement != 0 || m_PreviousYMovement != 0)
    				{
    					
    					nextX = m_PreviousXMovement - (m_PreviousXMovement * (PlayerShip.Acceleration * .25));
    					nextY = m_PreviousYMovement - (m_PreviousYMovement * (PlayerShip.Acceleration * .25));
    					
    					PlayerMap.x = PlayerMap.x + nextX;
    					PlayerMap.y = PlayerMap.y + nextY;
    
    					if (Math.abs(nextX) < EnB2.INERTIA_HALT && Math.abs(nextY) < EnB2.INERTIA_HALT)
    					{
    						trace("HALT");
    						m_PreviousXMovement = 0;
    						m_PreviousYMovement = 0;
    					}
    					else
    					{
    						m_PreviousXMovement = nextX;
    						m_PreviousYMovement = nextY;
    					}
    				}
    			}
    

    Right now if I accelerate quickly in a particular direction and then let go of the forward key, turn, and then repress the forward key, the ship will drift as expected (for the most part, there are some unrelated math errors that are causing some jerkiness atm).

    However, if I am just going forward and I press the left or right key with the forward key still depressed, no inertia is carried at all and the ship will pretty much spin on a dime. I have tried a few different methods of carrying over some additional speed but I think this per-frame model is not exactly physics friendly. Any help would be appreciated.

    My two current theories:

    1) The per-frame-rendering is actually carrying out exactly what I want it to do but at 35 frames per second the ship inertia is smoothing out too fast for me to notice. This is solid except it seems to work just fine if I turn while not accelerating and then re-accelerate.

    2) Something to do with my speed capping and/or crossing the number line between negative and positive values is causing weirdness.

    It's really been bugging me.

    Note, AbsoluteMaxX and Y are calculations of VectorX and VectorY at their maximum possible values (rotation of 0, 90, 180, or 270). I have it this way for ship acceleration.

    Jasconius on
  • SmasherSmasher Starting to get dizzy Registered User regular
    edited March 2008
    var accelerationX:Number = 0;
    var accelerationY:Number = 0;
    
    if (m_KeyPressed_UP && !m_KeyPressed_DOWN){	   
    	accelerationX = Math.cos(2.0 * Math.PI * (this.rotation - 90) / 360.0) / EnB2.SPEED_SCALE;
    	accelerationY = Math.sin(2.0 * Math.PI * (this.rotation - 90) / 360.0) / EnB2.SPEED_SCALE;
    }
    else if (!m_KeyPressed_UP && m_KeyPressed_DOWN){
    	// handle braking here if you want it
    }
    else{ // Treats both "up and down" and "neither up nor down" as no input 
    	// Having drag in space violates Newton's First Law.  If that's intentional then fine, just want to be sure you know
    	// And no, I'm not counting drag from space dust or solar wind
    	accelerationX = velocityX * DRAG_FACTOR; // -1 <= DRAG_FACTOR <= 0
    	accelerationY = velocityY * DRAG_FACTOR; // -1 stops instantly, 0 is no drag, values outside the range are acid trips
    }
    
    velocityX = velocityX + accelerationX; // I think velocityX corresponds to your m_PreviousMovement
    velocityY = velocityY + accelerationY; // I find this name easier to understand at a glance, but call it whatever you want
    
    var currentVelocity:Number = Math.sqrt(velocityX*velocityX + velocityY*velocityY);
    if(Math.abs(currentVelocity) < EnB2.INERTIA_HALT){ 
    	velocityX = 0;
    	velocityY = 0;
    }
    else if(currentVelocity > PlayerShip.speed){
    	velocityX = velocityX * PlayerShip.speed / currentVelocity;
    	velocityY = velocityY * PlayerShip.speed / currentVelocity;
    }
    
    PlayerMap.x = PlayerMap.x + velocityX;
    PlayerMap.y = PlayerMap.y + velocityY;
    

    Smasher on
  • JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited March 2008
    Yeah there's drag just for the sake of the game. I'll try this when I get home, thanks.

    Jasconius on
  • GrimReaperGrimReaper Registered User regular
    edited March 2008
    Quick question, is the Express version of Visual C# still horribly crippled in regards to SQL? As in you can only use SQL Server Express.

    Or can you connect proper to a SQL server via OLE/OBDC now?

    By that I mean without having to code it up manually. Whereas in standard/pro etc you can pretty much for a good chunk drag and drop. Saving me the hassle.

    GrimReaper on
    PSN | Steam
    ---
    I've got a spare copy of Portal, if anyone wants it message me.
  • LoneIgadzraLoneIgadzra Registered User regular
    edited March 2008
    eecc wrote: »

    Why const char *?

    Also oh god C strings suck much better to switch to C++ if only for strings. If it's a class assignment in C, tell the professor he is stupid there is no reason to ever use C strings when you can just add "pp" to the file extension, use g++ instead of gcc, and have strings that aren't so completely prone to fuckups.

    C strings aren't hard to understand, they're just worthless and you need a reference sheet for the function names because they're from 1200BC and are stupid.

    Because the original assignment was something like:

    pszMonth = "June";

    "June" will typically be allocated in some form of read-only memory (e.g. put into code space), and so attempting to write to the string will result in an access violation/segmentation fault. In other words, the string is read-only.

    Making the char * a const will let the compiler help enforce this read-only aspect of the string.

    Also, there are situations where C++ is not an appropriate substitute for C. While I share your opinion that C++ strings are more convenient than C strings, the blanket statement that C++ should always be used over C is a bit strong.

    I'm not sure I follow. Unless the guy who first asked the question has previously given a few more details, making a string read-only doesn't seem like a given to me, unless it is being passed as an argument.

    Also, I wasn't blanketing that C++ is better (honestly I hate it too), but seeing as you can compile a C source file as C++ and not have to worry about very many things working differently, there's no reason not to do it if only just for strings IMHO.

    LoneIgadzra on
  • JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited March 2008
    GrimReaper wrote: »
    Quick question, is the Express version of Visual C# still horribly crippled in regards to SQL? As in you can only use SQL Server Express.

    Or can you connect proper to a SQL server via OLE/OBDC now?

    By that I mean without having to code it up manually. Whereas in standard/pro etc you can pretty much for a good chunk drag and drop. Saving me the hassle.

    I'm going to guess that you still can't.

    Also: drag and drop databinding is the devil.

    Jasconius on
  • ecco the dolphinecco the dolphin Registered User regular
    edited March 2008
    eecc wrote: »

    Why const char *?

    Also oh god C strings suck much better to switch to C++ if only for strings. If it's a class assignment in C, tell the professor he is stupid there is no reason to ever use C strings when you can just add "pp" to the file extension, use g++ instead of gcc, and have strings that aren't so completely prone to fuckups.

    C strings aren't hard to understand, they're just worthless and you need a reference sheet for the function names because they're from 1200BC and are stupid.

    Because the original assignment was something like:

    pszMonth = "June";

    "June" will typically be allocated in some form of read-only memory (e.g. put into code space), and so attempting to write to the string will result in an access violation/segmentation fault. In other words, the string is read-only.

    Making the char * a const will let the compiler help enforce this read-only aspect of the string.

    Also, there are situations where C++ is not an appropriate substitute for C. While I share your opinion that C++ strings are more convenient than C strings, the blanket statement that C++ should always be used over C is a bit strong.

    I'm not sure I follow. Unless the guy who first asked the question has previously given a few more details, making a string read-only doesn't seem like a given to me, unless it is being passed as an argument.

    That's the thing though - any string literal is automatically read-only.

    Here is a link to the C99 standard. In section 6.4.5 ("String literals"), point 6, second sentence:
    If the program attempts to modify such an array, the behavior is undefined.

    The array they refer to is the string literal array, e.g. "June", "Arbitrarily defined string" - anything inbetween two double-quotes.

    ecco the dolphin on
    Penny Arcade Developers at PADev.net.
  • DeathPrawnDeathPrawn Registered User regular
    edited March 2008
    Alrighty, so I've decided to try my hand at doing some XNA programming using the Wiimote. I've got code that essentially rotates a sprite based on the Wiimote's accelerometer data for the Y-axis. I don't know the right terminology (it's a linear translation?) but a position value of Y (ranging from -1 to 1) results in a rotation angle of N * Y. It all works jolly well, except that it's too intolerant. Attempting to hold the Wiimote perfectly still often results in the object shaking, because the accelerometer value is varying by 0.0384616 (roughly).

    Any suggestions to make my code ignore this margin of error while still allowing a high level of accuracy?

    DeathPrawn on
    Signature not found.
  • SmasherSmasher Starting to get dizzy Registered User regular
    edited March 2008
    Set the acceleratometer value to 0 if it's less than some threshold?

    Smasher on
  • JasconiusJasconius sword criminal mad onlineRegistered User regular
    edited March 2008
    DeathPrawn wrote: »
    Alrighty, so I've decided to try my hand at doing some XNA programming using the Wiimote. I've got code that essentially rotates a sprite based on the Wiimote's accelerometer data for the Y-axis. I don't know the right terminology (it's a linear translation?) but a position value of Y (ranging from -1 to 1) results in a rotation angle of N * Y. It all works jolly well, except that it's too intolerant. Attempting to hold the Wiimote perfectly still often results in the object shaking, because the accelerometer value is varying by 0.0384616 (roughly).

    Any suggestions to make my code ignore this margin of error while still allowing a high level of accuracy?

    Yes, you have to program a dead zone where controller input is ignored.

    Jasconius on
  • DigDug2000DigDug2000 Registered User regular
    edited March 2008
    Jasconius wrote: »
    DeathPrawn wrote: »
    Alrighty, so I've decided to try my hand at doing some XNA programming using the Wiimote. I've got code that essentially rotates a sprite based on the Wiimote's accelerometer data for the Y-axis. I don't know the right terminology (it's a linear translation?) but a position value of Y (ranging from -1 to 1) results in a rotation angle of N * Y. It all works jolly well, except that it's too intolerant. Attempting to hold the Wiimote perfectly still often results in the object shaking, because the accelerometer value is varying by 0.0384616 (roughly).

    Any suggestions to make my code ignore this margin of error while still allowing a high level of accuracy?

    Yes, you have to program a dead zone where controller input is ignored.
    Or can't you just average over some range of time?

    DigDug2000 on
  • Recoil42Recoil42 Registered User regular
    edited March 2008
    DigDug2000 wrote: »
    Jasconius wrote: »
    DeathPrawn wrote: »
    Alrighty, so I've decided to try my hand at doing some XNA programming using the Wiimote. I've got code that essentially rotates a sprite based on the Wiimote's accelerometer data for the Y-axis. I don't know the right terminology (it's a linear translation?) but a position value of Y (ranging from -1 to 1) results in a rotation angle of N * Y. It all works jolly well, except that it's too intolerant. Attempting to hold the Wiimote perfectly still often results in the object shaking, because the accelerometer value is varying by 0.0384616 (roughly).

    Any suggestions to make my code ignore this margin of error while still allowing a high level of accuracy?

    Yes, you have to program a dead zone where controller input is ignored.
    Or can't you just average over some range of time?

    You should do that anyways, but you'll still need some kind of deadzone. Even with averaging, you're going to get a twitch when no motion is intended. Probably less of a twitch, but still a twitch. Averaging will, however, smooth out the intentional motion.

    Recoil42 on
  • PaperPlatePaperPlate Registered User regular
    edited March 2008
    If its been asked or answered in this thread already I apologize, just getting in on this now. I am looking for a C/C++ and/or? C# compiler, free preferably. I use Notepad ++ for coding in .lua (WoW addons) and at work I just write batch jobs using my company's language/software. Lacking a solid background in programming I have been wanting to get a bit more into it since I enjoy it. Also I feel exploring programming at home will help me at work (just started as a technical analyst having little programming background).

    Thanks for any suggestions.

    PaperPlate on
    Minecraft: PAPRPL8
    League of Legends (your friendly neighborhood support): PAPRPL8
  • SushisourceSushisource Registered User regular
    edited March 2008
    The Microsoft Visual Studio Express editions are great IDEs / compilers.

    They should do everything you need and more for free

    Sushisource on
    Some drugee on Kavinsky's 1986
    kavinskysig.gif
  • JaninJanin Registered User regular
    edited March 2008
    PaperPlate wrote: »
    If its been asked or answered in this thread already I apologize, just getting in on this now. I am looking for a C/C++ and/or? C# compiler, free preferably. I use Notepad ++ for coding in .lua (WoW addons) and at work I just write batch jobs using my company's language/software. Lacking a solid background in programming I have been wanting to get a bit more into it since I enjoy it. Also I feel exploring programming at home will help me at work (just started as a technical analyst having little programming background).

    Thanks for any suggestions.

    GCC is a good compiler, and it supports C and C++. The Windows port is called MinGW, and is availble either standalone or as part of an IDE like Code::Blocks.

    Janin on
    [SIGPIC][/SIGPIC]
  • AndorienAndorien Registered User regular
    edited March 2008
    The Microsoft Visual Studio Express editions are great IDEs / compilers.

    They should do everything you need and more for free

    Andorien on
This discussion has been closed.