• What do you need help with? V. 3.0
    4,884 replies, posted
I'm writing an input/binding system for a first-person shooter in Linux and was wondering what is the best way to get relative mouse input? I assume that reading from /dev/input/mice and interpreting the second byte as (int)rx and the third byte as (int)ry is not good practice...plus it requires elevated privileges.
[QUOTE=Chuushajou;30335373]Does anyone have any decent tutorials on how to do collisions in actionscript 2? It's for a school project :v:[/QUOTE] hittest should suffice
[QUOTE=Night-Eagle;30343507]I'm writing an input/binding system for a first-person shooter in Linux and was wondering what is the best way to get relative mouse input? I assume that reading from /dev/input/mice and interpreting the second byte as (int)rx and the third byte as (int)ry is not good practice...plus it requires elevated privileges.[/QUOTE] SDL is pretty cool. It's SDL_GetRelativeMouseState for both 1.2 and 1.3 (which I would recommend, though it's still the dev-version). Using Xlib would probably be preferred to reading from /dev/input/mouse. Look for XListInputDevices and XIQueryPointer, though you have to calculate the relative movement yourself. Or if you use XCB just look for the documentation of the event pump. Otherwise reading from /dev/input/mouse should be fine I guess, but I only really have done this stuff with SDL.
I need help with one of my Flash projects, I'm trying to use gskinners shape based collision detection, but for some reason I cant get it to work, but im pretty new to using classes, so I dont understand the structure too much. Can i get a tutorial on how to use the gskinner class? EDIT: im using the as2 version EDIT: well im gonna go for broke here and post all my coding, bare with me theres a lot here. basicly im making a 2D top down version of WipEout HD Fury, so file structure is something like this (the .fla is called wipeout as3 because i was initialy coding in as3 and never changed the filename) wipeout as3.fla (the flash file containing all the MCs and animations, but only enough coding to import all of the external code files, as well as the VCam and its script) the code in this is; [code] #include RaceControl.as" [/code] the RaceControl.as is used to determine the Car's control scheme, and refers to a physics code called RaceCar.as. i found it on the interwebs, all credit to matt carpenter; [code] // Race control // Create key listener var keyListener:Object = new Object(); keyListener.onKeyDown = function () { switch ( Key.getCode() ) { case Key.UP: _root.mc2.ForwardOn(); break; case Key.DOWN: _root.mc2.ReverseOn(); break; case Key.RIGHT: _root.mc2.RightTurnOn(); break; case Key.LEFT: _root.mc2.LeftTurnOn(); break; } } keyListener.onKeyUp = function () { switch ( Key.getCode() ) { case Key.UP: _root.mc2.ForwardOff(); break; case Key.DOWN: _root.mc2.ReverseOff(); break; case Key.RIGHT: _root.mc2.RightTurnOff(); break; case Key.LEFT: _root.mc2.LeftTurnOff(); break; } } Key.addListener(keyListener); [/code] the physics script it refers to, RaceCar.as, is as follows; [code] /* Racecar ver. 0.1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Author: matt carpenter http://orangesplotch.com License: This code is released under the Creative Commons Attribution-ShareAlike 2.5 License http://creativecommons.org/licenses/by-sa/2.5/ */ class Racecar extends MovieClip { private static var MASS_CONST:Number = 10; private static var MIN_SPIN:Number = 1; private static var MAX_TORQUE:Number = 1; private var maxaccel:Number; // px. per frame. squared private var drag:Number; // ratio private var turnRadius:Number; // px private var spinDrag:Number; // ratio private var _turn:Number; // 1, 0, -1 public var _accel:Number; // 1, 0, -1 public var vel:flash.geom.Point; // px. per frame private var heading:Number; // radians private var spin:Number; // radians per frame private var spinImpact:Number; // radians per frame // Initialize car state function Racecar() { // car characteristics this.maxaccel = 1; this.turnRadius = 100; this.drag = 0.05; this.spinDrag = 0.2; // state info this.vel = new flash.geom.Point(0, 0); this.heading = 0; this.spin = 0; this._accel = 0; this._turn = 0; this.spinImpact = 0; this.onEnterFrame = Update; } // Updates car state private function Update() { // Add drag this.vel.x *= (1 - this.drag); this.vel.y *= (1 - this.drag); this.spinImpact *= this.spinDrag; if ( Math.abs(this.spinImpact) <= 1 ) { this.spinImpact = 0; } // get the heading this.heading = Math.PI / 180 * this._rotation; // Add acceleration this.vel.x += Math.sin( this.heading ) * this._accel * this.maxaccel; this.vel.y -= Math.cos( this.heading ) * this._accel * this.maxaccel; var velMag:Number = Math.sqrt(this.vel.x * this.vel.x + this.vel.y * this.vel.y); this.spin = velMag / this.turnRadius * this._turn; // calculate torque (turning the car changes the direction it travels) var torque:flash.geom.Point = new flash.geom.Point(0,0); var newHeading:Number = this.heading + this.spin + this.spinImpact; torque.x = Math.sin(newHeading) * velMag - this.vel.x; torque.y = -Math.cos(newHeading) * velMag - this.vel.y; var torqueMag = Math.sqrt(Math.pow(torque.x,2) + Math.pow(torque.y,2)); // limit torque, so the car will "spin out" if turning too fast if (torqueMag > MAX_TORQUE) { torque.x = MAX_TORQUE * torque.x / torqueMag; torque.y = MAX_TORQUE * torque.y / torqueMag; } // apply torque to velocity this.vel.x += torque.x; this.vel.y += torque.y; // update position and heading this._x += this.vel.x; this._y += this.vel.y; this.heading = newHeading; this._rotation = this.heading * 180 / Math.PI; } /// - - - - - - - - - - - - - - /// /// CAR CONTROL FUNCTIONS /// /// - - - - - - - - - - - - - - /// // Forward and reverse public function ForwardOn() { this._accel = 1; } public function ForwardOff() { this._accel = 0; } public function ReverseOn() { this._accel = -1; } public function ReverseOff() { this._accel = 0; } // Left and right turn public function RightTurnOn() { this._turn = 1; } public function RightTurnOff() { this._turn = 0; } public function LeftTurnOn() { this._turn = -1; } public function LeftTurnOff() { this._turn = 0; } //Bounce Function (WIP) public function bounce() { this.vel.x *= -0.75; this.vel.y *= -0.75; } } [/code] the Bounce Function is my own work, and is what i want to happen when a collision is detected. now, the movieclip used for the car is my own drawn design, as is the track, and i want to use GSkinner's shape based collision to detect the collisions properly. so far i have the car driving around quite happily but i need it to collide with the walls of the track, rather than drive right through them. can i get a tutorial on how best to use the class? EDIT: hmm, looking at how far back this is in the thread now, it would be easier for anyone who can help to PM me :P
AS2 or AS3?
2D Collisions are pretty easy with basic shapes. Just wrote a flawless code for detecting a collision between a circle and a rectangle. [editline]9th June 2011[/editline] Maybe not so flawless, it doesn't work if the two objects centers have the same x or y value. If anyone wants to know I'm just finding the quadrant the rectangle is in relative to the circle if the circle's center was (0,0), then checking the corresponding corner of the rectangle if the distance from it is less than the circle's radius.
[code] public void CheckCollisions(Rectangle platform) { if (Boundaries.Right > platform.Left + 1 && Boundaries.Left < platform.Right - 1) { if (Boundaries.Bottom >= platform.Top && Boundaries.Bottom <= platform.Top + mGravity) { mPosition.Y = platform.Top - 40; mFalling = false; } else if (Boundaries.Top <= platform.Bottom - mGravity && Boundaries.Top >= platform.Bottom - mGravity) { mPosition.Y = platform.Bottom; mFalling = false; } } if (Boundaries.Bottom > platform.Top + mGravity && Boundaries.Top < platform.Bottom - mGravity) { { if (Boundaries.Right > platform.Left - 1 && Boundaries.Right < platform.Center.X / 2) { mPosition.X = platform.Left - 40; } } } if (!mFalling) { if (Boundaries.Top == platform.Top - 40 || Boundaries.Top == platform.Bottom) { if (Boundaries.Left > platform.Right) mFalling = true; } } } [/code] My collision code... The problem - Falling is being a bitch, it won't work for multiple platforms in the same Y position due to the "if (!mFalling)" part The solution - No idea. Any help?
So I have: [cpp]void RegisterLib(LuaState Lua, const luaL_reg *Reg, const std::string &LibName) { // Create a table to put the functions in lua_newtable(Lua); // Fill the table const luaL_reg *f = Reg; for( ; f->func; f++) { // Key lua_pushstring(Lua, f->name); // Value lua_pushcfunction(Lua, f->func); lua_settable(Lua, -3); } // Name the table lua_setglobal(Lua, LibName.c_str()); }[/cpp] And: [cpp]void RegisterFunctions() { RegisterLib(G::lua, windowFuncs, "Window"); RegisterLib(G::lua, graphicFuncs, "Graphics"); }[/cpp] (windowFuncs and graphicFuncs are luaL_reg arrays containing my functions and their names) For some reason, it's crashing on the second RegisterLib call, specifically on the lua_newtable line. Any ideas why? I think it might be to do with the stack, but I have no idea really.
So I finally managed to get the ball from the last page working properly. I feel accomplished.
[QUOTE=Chris220;30357223]So I have: [cpp]void RegisterLib(LuaState Lua, const luaL_reg *Reg, const std::string &LibName) { // Create a table to put the functions in lua_newtable(Lua); // Fill the table const luaL_reg *f = Reg; for( ; f->func; f++) { // Key lua_pushstring(Lua, f->name); // Value lua_pushcfunction(Lua, f->func); lua_settable(Lua, -3); } // Name the table lua_setglobal(Lua, LibName.c_str()); }[/cpp] And: [cpp]void RegisterFunctions() { RegisterLib(G::lua, windowFuncs, "Window"); RegisterLib(G::lua, graphicFuncs, "Graphics"); }[/cpp] (windowFuncs and graphicFuncs are luaL_reg arrays containing my functions and their names) For some reason, it's crashing on the second RegisterLib call, specifically on the lua_newtable line. Any ideas why? I think it might be to do with the stack, but I have no idea really.[/QUOTE] It looks like you are passing the state incorrectly to the function. I don't know what your LuaState type is, so I don't really know whats going on here. What you are supposed to do is pass the pointer to the Lua state (lua_State*). And why are you not using luaL_register(L, "name", Reg) to handle your library registrations?
Just got the XNA game studio creators guide (second edition), but I can't seem to find its website with all the needed resources.. can anyone link me to it?
So I'm using Java's switch statements to put together a long string for output. Here's a chunk of the code: [cpp] public String provideInfo() { String info = ""; info += "(Style: "; switch(style) { case 1: info += "Attack) "; System.out.println(name + " set style " + 1); break; case 2: info += "Defense) "; System.out.println(name + " set style " + 2); break; case 3: info += "Lucky) "; System.out.println(name + " set style " + 3); break; } System.out.println(name + " style completed: " + info); info += "(Weapon: "; switch(weapon) { case 1: info += "Sword) "; System.out.println(name + " set weapon " + 1); break; case 2: info += "Axe) "; System.out.println(name + " set weapon " + 2); break; case 3: info += "Flail) "; System.out.println(name + " set weapon " + 3); break; case 4: info += "Warhammer) "; System.out.println(name + " set weapon " + 4); break; } System.out.println(name + " weapon completed: " + info); info += "(Armor: "; switch(armor) { case 1: info += "Light) "; System.out.println(name + " set armor " + 1); break; case 2: info += "Medium) "; System.out.println(name + " set armor " + 2); break; case 3: info += "Heavy) "; System.out.println(name + " set armor " + 3); break; } System.out.println(name + " armor completed: " + info); return info; }[/cpp] This is part of the Player object, and it's called exactly twice by the Game object. When it's called the first time, everything goes fine, all the case's printlns trigger. When it's called the second time, for the second player, none of the printlns inside the Armor switch trigger, and it skips straight from printing the string up to (Armor: to "Armor completed. Any ideas? The only thing I can think of is that something isn't allowing the scanner to read the command line correctly. [editline]9th June 2011[/editline] It's kind of busy, everything's fairly compact because I've been debugging, not because I code like that :v:
OK so i'm still working on the garrysmod Lua profiler. I'm at the point where i want to profile each line of a function and i can set the debug hook up and what not, but i'm unsure of how i can return the values the timers return from the debug hook to the lua function then to the actual lua script. [cpp] void DebuggerHook(lua_State* L, lua_Debug* ar) { ILuaInterface* g_Lua = Lua(); if (ar->event != LUA_HOOKLINE) return; timer->Stop(); } LUA_FUNCTION( ProfileFile ) { ILuaInterface* g_Lua = Lua(); g_Lua->CheckType( 1 , GLua::TYPE_STRING); lua_sethook(L, &DebuggerHook, LUA_MASKLINE, 0); g_Lua->FindAndRunScript( g_Lua->GetString(1) ,true , true ); //timer->Start(); } [/cpp]
Okay, much less specific question incoming. Is there a good way to define a shitton of ints?
[QUOTE=mutated;30364587]Okay, much less specific question incoming. Is there a good way to define a shitton of ints?[/QUOTE] In most languages something like: [code] int a, b, c, d, e, f, g, h, i, j, k, l, m; [/code] will work. It will give them all the default value.
[QUOTE=Lord Ned;30364683]In most languages something like: [code] int a, b, c, d, e, f, g, h, i, j, k, l, m; [/code] will work. It will give them all the default value.[/QUOTE] Well, yes. I'm looking for an easy way to define a lot of separate numbers at startup.
I'll ask again because I really can't wait to start learning, does anyone here have the link to the xna game studio creators guide website? My copy didn't come with the link, and all the resources are there.
[QUOTE=mutated;30365128]Well, yes. I'm looking for an easy way to define a lot of separate numbers at startup.[/QUOTE] Can't you use an array, and then a for loop or something to put the values in?
[QUOTE=Jcw87;30360165]It looks like you are passing the state incorrectly to the function. I don't know what your LuaState type is, so I don't really know whats going on here. What you are supposed to do is pass the pointer to the Lua state (lua_State*). And why are you not using luaL_register(L, "name", Reg) to handle your library registrations?[/QUOTE] LuaState is just a simple RAII class that wraps a lua_State. The first call works, it's only the second one that crashes so I think the state is being passed ok... And I'm not using luaL_register because I'm still learning how to use the API, so I'm trying to do as much as I can with the lua_xxxxx commands to see how it all works underneath.
[QUOTE=Chris220;30365867]LuaState is just a simple RAII class that wraps a lua_State. The first call works, it's only the second one that crashes so I think the state is being passed ok... And I'm not using luaL_register because I'm still learning how to use the API, so I'm trying to do as much as I can with the lua_xxxxx commands to see how it all works underneath.[/QUOTE] I think that the way you are passing it is causing it to be duplicated, and the copy is used the first time you call your function. The Lua state should NEVER be duplicated in this manner. Everything appears to work fine, until your function returns. The copy is destroyed, and the original remains. The problem though, is that the original contains pointers to data that is now invalid, and WILL cause crashes on the next API call, which happens to be the second time you call your function. You should only pass a pointer to the Lua state to all functions that are going to use it.
Ah, that makes sense, thanks. Changed it to pass the LuaState by reference and it works. Thanks again!
I'm just starting out with C#, literally last night started. [code]using System; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { int number = 5; for(int i = 0; i < number; i++) Console.WriteLine(i); Console.ReadLine(); } } } [/code] I roughly understand how it works, but why doesn't the int i = 0 have to be declared outside of the for loop and the int number = 5 does?
You can sequence variable declarations and assignments even inside for-loops. [csharp]for (int i = 0, f = 10; i < f; i++)[/csharp] [editline]10th June 2011[/editline] I don't like to do it though, it makes it hard to see at a glance how the for-loop is looping.
[QUOTE=ThePuska;30369492]You can sequence variable declarations and assignments even inside for-loops. [csharp]for (int i = 0, f = 10; i < f; i++)[/csharp] [editline]10th June 2011[/editline] I don't like to do it though, it makes it hard to see at a glance how the for-loop is looping.[/QUOTE] Right, I see now, thank you
Im trying to make an engine/framework with SlimDX but Im having some issues I want to create a window class that will basically wrap all the ugly stuff into a simple new window( width, height, title...; Im struggelling to decide which version of DX to use, I would preffer DX 9 as its more compatible but the only tutorials available are for DX11 and I dont even have a DX11 card Also does anyone know if you can create a native SlimDX window? or do you have to create a form and then use that for SlimDX? Finally what is a method called when you can do: myWindow.Draw += DrawMethod(); So I can have my draw method in the actual game/example
AHH Having problems trying to create an onkeylistener in java for an android app. I'm no java guru so I'm kinda throwing myself in the deep end a bit here. I want it so that when the user enters a number into the text box and presses a button, the number they entered is set as a int and then do calculations on the number. I've gotten the calculation bit ok (well I at least understand what to do for it.) however I'm having problems with creating a key listener and setting it as a int Here's my code: [code] package powerizer.pak; import android.app.Activity; import android.content.DialogInterface.OnKeyListener; import android.os.Bundle; import android.view.KeyEvent; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class powerizer extends Activity { Button button1; TextView ansOutput; EditText edittext; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ansOutput = (TextView)findViewById(R.id.ansOutput); button1 = (Button)findViewById(R.id.button1); edittext = (EditText)findViewById(R.id.edittext); edittext.setOnClickListener(new OnKeyListener() { public boolean onKey(View v, int keycode, KeyEvent event){ if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keycode == KeyEvent.KEYCODE_ENTER)) { ansOutput.setText(powerizer.this, edittext.getText(), ansOutput.length()).show(); return true; } } } button1.setOnClickListener(new View.OnClickListener() { public void onClick(View v){ ansOutput.setTag(edittext); } }); } } [/code] Now I know its not completely done and nothing will work on it yet, however I plan on doing that once I get this problem sorted. I've googled for a while and can't find anything that works. Hell, the code i'm using is currently copypasta'd from the android SDK and doesn't work. Here's what I see in Eclipse: [url]http://i.imgur.com/zJ7vm.png[/url] Any help will be appreciated :)
Is it possible in C# to call the parent constructor within the body of the child constructor, or does it have to appear right after the child constructor declaration? Right now the child class's constructor takes a filename, from which it reads information. The problem is that the parent constructor's variables are readonly so they need to be set in a parent constructor, and I don't have the info it needs until I've finished reading the file. Is my only option creating a static Load(String filename) function that calls the constructor with all the data?
[QUOTE=DeadKiller987;30365768]Can't you use an array, and then a for loop or something to put the values in?[/QUOTE] The thing I'm running into is that the values are somewhat arbitrary. But an array would honestly work better, thanks.
[QUOTE=RyanDv3;30374504]Is it possible in C# to call the parent constructor within the body of the child constructor, or does it have to appear right after the child constructor declaration? Right now the child class's constructor takes a filename, from which it reads information. The problem is that the parent constructor's variables are readonly so they need to be set in a parent constructor, and I don't have the info it needs until I've finished reading the file. Is my only option creating a static Load(String filename) funstion that calls the constructor with all the data?[/QUOTE] It's not possible because if you were allowed to change the new instance before the base was initialized it could lead to a corrupted object state.
I have this code in pygame to determine collision between a circle and a rectangle, and I feel as though it's a lot more complicated than it should be. [code] def distance(p1,p2): return math.sqrt((p1[0]-p2[0])**2 + (p1[1]-p2[1])**2) #Simple distance forumula between 2 points def squarecollide(rect1,rect2,radius): #rect1 is used as the rectangle, rect2 is the circle's rect. quadrant = '' #Imagine the circle as the origin of a coordinate plane. if rect1.center[0] < rect2.center[0] and rect1.center[1] < rect2.center[1]: quadrant = 'topleft' #The rectangle is to the topleft of the circle if rect1.center[0] > rect2.center[0] and rect1.center[1] < rect2.center[1]: quadrant = 'topright' #The rectangle is to the top right of the circle if rect1.center[0] > rect2.center[0] and rect1.center[1] > rect2.center[1]: quadrant = 'bottomright' #Etc. if rect1.center[0] < rect2.center[0] and rect1.center[1] > rect2.center[1]: quadrant = 'bottomleft' #Etc. if quadrant == 'topleft': if distance(rect1.center,rect2.topleft) < radius: return True if quadrant == 'topright': if distance(rect1.center,rect2.topright) < radius: return True if quadrant == 'bottomleft': if distance(rect1.center,rect2.bottomleft) < radius: return True if quadrant == 'bottomright': if distance(rect1.center,rect2.bottomright) < radius: return True if quadrant == '': #If the rectangle has the same x or y value as the circle's center if rect1.left >= rect2.right: if distance(rect1.center,rect2.midright) < radius: return True if rect1.right <= rect2.left: if distance(rect1.center,rect2.midleft) < radius: return True if rect1.top >= rect2.bottom: if distance(rect1.center,rect2.midbottom) < radius: return True if rect1.bottom <= rect2.top: if distance(rect1.center,rect2.midtop) < radius: return True[/code] I just need some help optimizing it is all.
Sorry, you need to Log In to post a reply to this thread.