• What do you need help with? V4 (January 2012)
    966 replies, posted
  • Well in javascript you can do getElementByClass, so if c# dom is similar that might just work
  • [QUOTE=ROBO_DONUT;34309357]Look up "poisson disc generation" First result links to a simple one-page [url=http://people.cs.ubc.ca/~rbridson/docs/bridson-siggraph07-poissondisk.pdf]paper[/url] with a fairly straightfoward algorithm.[/QUOTE] Thanks! [quote][img]http://27.media.tumblr.com/tumblr_ly4dc3kun41r5x1ako1_500.jpg[/img][/quote]
  • [QUOTE=Within;34313645]In .NET, how can I get InnerHtml based on class names? I'm interested in getting the HTML from the tip-container class, as shown below: [html]<div class="tip-container"> <article class="tip tip-color-15 splash" id="tip_1423"> <h1 unselectable="on">brotip #1415</h1> <p unselectable="on">ladies, guys are sick of <br> hearing you ask where <br> all of the "nice guys" are. <br> they're in the friend zone, <br> where you left them.</p> <footer unselectable="on" class="tip-footer"></footer> <footer unselectable="on" class="tip-copyright">brotips.com</footer> </article> </div>[/html] GetElementById doesn't work for classes (obviously). I can't predict the [I]tip_x[/I] ID (since for some reason it doesn't follow the tip number as shown on the page), so I can't use that to GetElementById[/QUOTE] what are you doing
  • [IMG]http://img809.imageshack.us/img809/7603/20120120211535.png[/IMG] [img]http://img803.imageshack.us/img803/8751/20120120213514.png[/img] I have a little VB2010 game i'm making (please don't say anything about it, I need to take this class in order to go to java next year) 1.Is there anything I can do with the transparency settings, if I set the pictureboxes to be transparent the border of the image is still blocking the back. 2. What would i use in order to make the keys flash at random and require a keypress to shut them off? 3. is there a possible way to make the screen sidescroll with the character without scroll bars I have double buffer for the form on all it did was make it smoother
  • Sorry to bother you all but I would like to find a good Java LWJGL tutorial series? I've been trying to google for one for some time. I can just find some really basic ones that don't go indepth on all the Open gl stuff.
  • [QUOTE=thomasfn;34308911][code]public static Vector2 Lerp(Vector2 a, Vector2 b, float mu) { return (b-a) * mu + a; }[/code] "a" would be the start vector, "b" would be the end vector, "mu" would be a value between 0 and 1.[/QUOTE] You don't need to program this, C# provides it as MathHelper.Lerp().
  • I'm trying to hook the KeyboardProc of an app, but I can't seem to do it. The program just freezes when it receives keyboard input. I haven't really dealt with DLLs or hooking before so I barely understand what I'm doing Here's how I install the hook (I removed the checks that ensure that the handles etc. are all OK - they are): [cpp]char *dllName = "full path to .dll"; char *procName = "_KeyboardP@12"; char *targetName = "Untitled - Notepad"; HWND targetWindow = 0; DWORD targetThreadId = 0; HOOKPROC hHookP = 0; HINSTANCE hDll = 0; HHOOK hHook = 0; hDll = LoadLibrary(dllName); hHookP = (HOOKPROC)GetProcAddress(hDll, procName); targetWindow = FindWindow(0, targetName); targetThreadId = GetWindowThreadProcessId(targetWindow, 0); hHook = SetWindowsHookEx(WH_KEYBOARD, hHookP, hDll, targetThreadId);[/cpp] Here's the hook in a .DLL: [cpp]__declspec(dllexport) LRESULT WINAPI KeyboardP(int nCode, WPARAM wParam, LPARAM lParam) { return CallNextHookEx(0, nCode, wParam, lParam); }[/cpp]
  • [QUOTE=Within;34313645]In .NET, how can I get InnerHtml based on class names? I'm interested in getting the HTML from the tip-container class, as shown below: [html]<div class="tip-container"> <article class="tip tip-color-15 splash" id="tip_1423"> <h1 unselectable="on">brotip #1415</h1> <p unselectable="on">ladies, guys are sick of <br> hearing you ask where <br> all of the "nice guys" are. <br> they're in the friend zone, <br> where you left them.</p> <footer unselectable="on" class="tip-footer"></footer> <footer unselectable="on" class="tip-copyright">brotips.com</footer> </article> </div>[/html] GetElementById doesn't work for classes (obviously). I can't predict the [I]tip_x[/I] ID (since for some reason it doesn't follow the tip number as shown on the page), so I can't use that to GetElementById[/QUOTE] What I did was, instead of using the default shit that .NET has, use this instead: [url]http://htmlagilitypack.codeplex.com/[/url] It's a DLL so you'll have to add a reference to it in your project in VS. I found it very easy to use and I used it for some web scraping of my own. :smile:
  • I'm trying to load and draw two textured models in XNA, but it shoots back the error "Object refrence not set to an instance of an object" on this line of code; "meshPart.Effect = effect.Clone();" [csharp] private Model loadModel(string assetName, out Texture2D[] textures) { Model newModel = Content.Load<Model>(assetName); textures = new Texture2D[newModel.Meshes.Count]; int i = 0; foreach (ModelMesh mesh in newModel.Meshes) foreach (BasicEffect currentEffect in mesh.Effects) textures[i++] = currentEffect.Texture; foreach (ModelMesh mesh in newModel.Meshes) foreach (ModelMeshPart meshPart in mesh.MeshParts) meshPart.Effect = effect.Clone(); return newModel; } //draws the starbox private void drawSkyBox() { SamplerState ss = new SamplerState(); ss.AddressU = TextureAddressMode.Clamp; ss.AddressV = TextureAddressMode.Clamp; device.SamplerStates[0] = ss; DepthStencilState dss = new DepthStencilState(); dss.DepthBufferEnable = false; device.DepthStencilState = dss; Matrix[] starboxTransforms = new Matrix[starboxModel.Bones.Count]; starboxModel.CopyAbsoluteBoneTransformsTo(starboxTransforms); int i = 0; foreach (ModelMesh mesh in starboxModel.Meshes) { foreach (Effect currentEffect in mesh.Effects) { Matrix worldMatrix = starboxTransforms[mesh.ParentBone.Index]; currentEffect.CurrentTechnique = currentEffect.Techniques["Textured"]; currentEffect.Parameters["xWorld"].SetValue(worldMatrix); currentEffect.Parameters["xView"].SetValue(viewMatrix); currentEffect.Parameters["xProjection"].SetValue(projectionMatrix); currentEffect.Parameters["xTexture"].SetValue(starBoxTextures[i++]); } mesh.Draw(); } dss = new DepthStencilState(); dss.DepthBufferEnable = true; device.DepthStencilState = dss; } private void drawWeapon() { SamplerState ss = new SamplerState(); ss.AddressU = TextureAddressMode.Clamp; ss.AddressV = TextureAddressMode.Clamp; device.SamplerStates[0] = ss; DepthStencilState dss = new DepthStencilState(); dss.DepthBufferEnable = true; device.DepthStencilState = dss; //Matrix worldMatrix = weaponPositionMatrix; Matrix[] weaponTransforms = new Matrix[shipModel.Bones.Count]; shipModel.CopyAbsoluteBoneTransformsTo(weaponTransforms); int i = 0; foreach (ModelMesh mesh in shipModel.Meshes) { //sets the effects for all meshes in the model foreach (Effect currentEffect in mesh.Effects) { worldMatrix = weaponTransforms[mesh.ParentBone.Index]; currentEffect.CurrentTechnique = currentEffect.Techniques["Textured"]; currentEffect.Parameters["xWorld"].SetValue(weaponTransforms[mesh.ParentBone.Index] * worldMatrix); currentEffect.Parameters["xView"].SetValue(viewMatrix); currentEffect.Parameters["xProjection"].SetValue(projectionMatrix); currentEffect.Parameters["xEnableLighting"].SetValue(true); currentEffect.Parameters["xLightDirection"].SetValue(sunAngle); currentEffect.Parameters["xTexture"].SetValue(grenadeLauncherTextures[i++]); currentEffect.Parameters["xAmbient"].SetValue(0.5f); } mesh.Draw(); } } [/csharp] It was working fine until I decided to do some late night editing, and I have no idea what went wrong. Can anyone help me?
  • Your "effect" variable is null. Where is that variable defined? It isn't mentioned anywhere else in the code you posted.
  • I have some knowledge in Java so would it be possible to use this [url]http://code.google.com/p/kryonet/[/url] library to make a little console chat applet?
  • [QUOTE=Blueridge;34301779]What's a clear way of removing multiple elements in an array? For a school assignment I have to make a class that holds an array of integers, and add methods that add to it, remove etc. Kinda like an ArrayList. The problem, however, is they want me to make a removeAll(int val) method that removes all occurrences of val from the list. For example, removeAll(4) would change {1, 2, 4, 6, 3, 4, 4, 6, 5, 6, 4} to {1, 2, 6, 3, 6, 5, 6, 0, 0, 0, 0}. For my regular remove() method, I'm using Apache Common's Lang ArrayUtils class to remove the element. Removing all elements with it doesn't work fully, for some reason. My current plan of attack is to find out how many times val appears in the array, and then call ArrayUtils.remove() that many times. But it gives me weird results, for instance shrinking the array. Any other way to attack this? I can't use ArrayList supposedly, and I doubt they'll check if I am or not, but it would be nice to figure out how to do this the way they want me to.[/QUOTE] This is what I've come up with: [CODE] public void removeAll(int val) { int read = 0, write = 0, loop = 0; boolean hasNum = false; while(read <list.length) { if(list[read] == val) { read++; list[write] = list[read]; hasNum = true; } read++; write++; } if(hasNum && read >= list.length) { while(write < list.length) { list[write] = 0; write++; } } } public class IntegerListTest { static IntegerList list; public static void main(String[]args) { list = new IntegerList(10); int[] test = {1, 4, 6, 4, 2, 6, 4, 6, 7, 6}; //expected: {1, 6, 2, 6, 6, 7, 6, 0, 0, 0} list.add(test); list.removeAll(4); list.print(); } } [/CODE] And here's what I got instead of what was expected: 0: 1 1: 6 2: 2 3: 4 4: 6 5: 6 6: 4 7: 6 8: 0 9: 0 This time it gets 1 of the 4s(the first one), but not all of them. Not sure what I'm getting wrong here.
  • [QUOTE=Blueridge;34341890]This is what I've come up with: [CODE] public void removeAll(int val) { int read = 0, write = 0, loop = 0; boolean hasNum = false; while(read <list.length) { if(list[read] == val) { read++; list[write] = list[read]; hasNum = true; } read++; write++; } if(hasNum && read >= list.length) { while(write < list.length) { list[write] = 0; write++; } } } public class IntegerListTest { static IntegerList list; public static void main(String[]args) { list = new IntegerList(10); int[] test = {1, 4, 6, 4, 2, 6, 4, 6, 7, 6}; //expected: {1, 6, 2, 6, 6, 7, 6, 0, 0, 0} list.add(test); list.removeAll(4); list.print(); } } [/CODE] And here's what I got instead of what was expected: 0: 1 1: 6 2: 2 3: 4 4: 6 5: 6 6: 4 7: 6 8: 0 9: 0 This time it gets 1 of the 4s(the first one), but not all of them. Not sure what I'm getting wrong here.[/QUOTE] [cpp]void remove_array(int *list, int count, int value) { int read = 0, write = 0; while (read < count) { while ((read < count) && (list[read] == value)) read++; if (read < count) list[write] = list[read]; write++; read++; } while (write < count) { list[write] = 0; write++; } }[/cpp] [editline]22nd January 2012[/editline] Your idea of having two running indices, one for reading and one for writing was a good one. I imagine my snippet is more like you intended it in your head
  • [QUOTE=ThePuska;34342023][cpp]void remove_array(int *list, int count, int value) { int read = 0, write = 0; while (read < count) { while ((read < count) && (list[read] == value)) read++; if (read < count) list[write] = list[read]; write++; read++; } while (write < count) { list[write] = 0; write++; } }[/cpp] [editline]22nd January 2012[/editline] Your idea of having two running indices, one for reading and one for writing was a good one. I imagine my snippet is more like you intended it in your head[/QUOTE] Converted it to Java. It sets the first appearance of 4 to 0, and then keept every other element the same.
  • [QUOTE=Wyzard;34340688]Your "effect" variable is null. Where is that variable defined? It isn't mentioned anywhere else in the code you posted.[/QUOTE] Whups, sorry. It's defined at the top as [csharp] Effect effect;[/csharp]
  • Can a programmer be liable for the program he makes? I'm making a program that checks a auction site every 5 min and emails a list of people in a text file all auctions with trucks
  • [QUOTE=Mr. Smartass;34345263]Whups, sorry. It's defined at the top as [csharp] Effect effect;[/csharp][/QUOTE] That'll default to null since it's not initialized with a value. Chances are, you're using it without having assigned a value to it yet.
  • [QUOTE=Wyzard;34346166]That'll default to null since it's not initialized with a value. Chances are, you're using it without having assigned a value to it yet.[/QUOTE] Nope, before the model draw calls I have this [csharp] protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); device = graphics.GraphicsDevice; shipModel = loadModel("grenadelauncher", out grenadeLauncherTextures); effect = Content.Load<Effect>("effects"); starboxModel = loadModel("starbox", out starBoxTextures); font = Content.Load<SpriteFont>("font"); } [/csharp]
  • [QUOTE=Mr. Smartass;34346432]Nope, before the model draw calls I have this [csharp] protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); device = graphics.GraphicsDevice; shipModel = loadModel("grenadelauncher", out grenadeLauncherTextures); effect = Content.Load<Effect>("effects"); starboxModel = loadModel("starbox", out starBoxTextures); font = Content.Load<SpriteFont>("font"); } [/csharp][/QUOTE] Put a break point on that line and ensure that Content.Load<EFfect>("effects"); isn't returning null.
  • [QUOTE=Lord Ned;34346448]Put a break point on that line and ensure that Content.Load<EFfect>("effects"); isn't returning null.[/QUOTE] I did, and it isn't; The thing is, the error started after I changed the second model's effect type to textured from colored, so I'm 100% sure that that's where the error is coming from; [csharp] private void drawWeapon() { SamplerState ss = new SamplerState(); ss.AddressU = TextureAddressMode.Clamp; ss.AddressV = TextureAddressMode.Clamp; device.SamplerStates[0] = ss; DepthStencilState dss = new DepthStencilState(); dss.DepthBufferEnable = true; device.DepthStencilState = dss; //Matrix worldMatrix = weaponPositionMatrix; Matrix[] weaponTransforms = new Matrix[shipModel.Bones.Count]; shipModel.CopyAbsoluteBoneTransformsTo(weaponTransforms); int i = 0; foreach (ModelMesh mesh in shipModel.Meshes) { //sets the effects for all meshes in the model foreach (Effect currentEffect in mesh.Effects) { worldMatrix = weaponTransforms[mesh.ParentBone.Index]; currentEffect.CurrentTechnique = currentEffect.Techniques["Textured"]; currentEffect.Parameters["xWorld"].SetValue(weaponTransforms[mesh.ParentBone.Index] * worldMatrix); currentEffect.Parameters["xView"].SetValue(viewMatrix); currentEffect.Parameters["xProjection"].SetValue(projectionMatrix); currentEffect.Parameters["xEnableLighting"].SetValue(true); currentEffect.Parameters["xLightDirection"].SetValue(sunAngle); currentEffect.Parameters["xTexture"].SetValue(grenadeLauncherTextures[i++]); currentEffect.Parameters["xAmbient"].SetValue(0.5f); } mesh.Draw(); } } [/csharp]
  • I have a more conceptual question about pseudocode and planning the actual structure. How thoroughly do you prepare a relatively serious project theoretically before actually starting to code it? As far as I am aware, it is the best idea to create a language independent pseudocode structure before actually starting to create it.
  • If it's a complex enough program I'll spend some time thinking about overall architecture first, but I don't see much value in creating a pseudocode mockup of a whole program before starting to write the "real" code. To the extent that your real code matches what you wrote in pseudocode, you're just doing the same work twice. And you'll probably discover problems and design considerations while working on the real code that you didn't foresee while writing pseudocode, so you'll end up deviating from your plans anyway. Some people like to use [url=https://en.wikipedia.org/wiki/Unified_Modeling_Language]UML[/url] to design a program in advance. That can be useful for high-level planning, but IMO trying to plan out all the details (like every method's argument list) is a waste, Pseudocode is more useful for smaller things, like figuring out an algorithm without having to worry about details like memory management.
  • I can't actually start something. I just got an idea, but I can't make myself open Code::Blocks and start programming. It's kind of a...laziness? Really need help on this, I don't understand why I can't get myself to do any programming.
  • [QUOTE=Bumrang;34352475]I can't actually start something. I just got an idea, but I can't make myself open Code::Blocks and start programming. It's kind of a...laziness? Really need help on this, I don't understand why I can't get myself to do any programming.[/QUOTE] I find just talking to other programmers [about programming] motivating
  • [QUOTE=ief014;34352898]I find just talking to other programmers [about programming] motivating[/QUOTE] Or, if making a game, having an artist to create sprites for you. It helps me want to continue working when I can keep expanding instead of being limited in assets.
  • Obj-C passing a mutable array from the appDelegate to the view controller. It's a big long array of restaurants that are tagged on a map. The appDelegate pulls the data from a plist and makes a nice array and then passes it to the viewController to add the info to the map. The appDelegate does it's job right, the NSLogs prove it. But once the viewController gets it... it's a null array. App Delegate code self.viewController.restaurants = restaurants; And in View Controller NSLog(@"THIS IS, %@",restaurants); returns "THIS IS (null)" What's going on and why doesn't this work?
  • I don't really know if anyone would be willing to help with this, as (at least to me) it seems possibly pretty complicated, but here goes: I have a rectangle with known coordinates. Inside this rectangle is another, smaller polygon; its coordinates are also known. I then have a large set of coordinates that represent another polygon, which may or may not be concave. I'm hoping to come up with a way of finding the best way to fit said curve so that all its points are inside the outer rectangle, but the inner polygon must be inside this curve. The inner polygon must remain in a fixed position, and the set of points representing the curve can be translated, rotated and scaled (as long as the scaling is done in both x and y simultaneously and by an equal factor). So uh, yeah. I have absolutely no idea as to where I should even begin with this. :suicide: If anyone could even just point me in the vaguely right direction regarding to where the hell I should start, I would be very, very grateful. also i hope this is in the right section, as the problem seems to be leaning more towards a maths problem than a programming problem, i guess
  • [QUOTE=ned_ballad;34358033]Obj-C passing a mutable array from the appDelegate to the view controller. It's a big long array of restaurants that are tagged on a map. The appDelegate pulls the data from a plist and makes a nice array and then passes it to the viewController to add the info to the map. The appDelegate does it's job right, the NSLogs prove it. But once the viewController gets it... it's a null array. App Delegate code self.viewController.restaurants = restaurants; And in View Controller NSLog(@"THIS IS, %@",restaurants); returns "THIS IS (null)" What's going on and why doesn't this work?[/QUOTE] If the View Controller's array is a property try [self restaurants] or self.restaurants in NSLog.
  • it ended up being that I was passing the array before the view controller was created 6 hours... SIX HOURS and it was the wrong order messing me up :(