Search Results

Search found 3365 results on 135 pages for 'math'.

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

  • Detect line line collision in an Untangled game

    - by Vish
    Pardon me if this is a repeat question,but I've been searching google for vain since the past few days, I'm a flash actionscript game developer who is a bit backward with mathematics, though I find physics both interesting and cool. Similiar game : Untangled flash game I have made an untangled game almost to full completion of logic. But, when two lines intersect , I need those intersected or 'tangled' lines to show a different color; red. It would be really kind of you people if you could suggest an algorithm with / without math for detecting line segment collisions. I'm basically a person who likes to think 'visually' than 'arithmetically' :) P.S I'm trying to make a function as private function isIntersecting(A:Point, B:Point, C:Point, D:Point):Boolean Thanks in advance. Vishnu Ajit

    Read the article

  • Arrays for a heightmap tile-based map

    - by JPiolho
    I'm making a game that uses a map which have tiles, corners and borders. Here's a graphical representation: I've managed to store tiles and corners in memory but I'm having troubles to get borders structured. For the tiles, I have a [Map Width * Map Height] sized array. For corners I have [(Map Width + 1) * (Map Height + 1)] sized array. I've already made up the math needed to access corners from a tile, but I can't figure out how to store and access the borders from a single array. Tiles store the type (and other game logic variables) and via the array index I can get the X, Y. Via this tile position it is possible to get the array index of the corners (which store the Z index). The borders will store a game object and accessing corners from only border info would be also required. If someone even has a better way to store these for better memory and performance I would gladly accept that. EDIT: Using in C# and Javascript.

    Read the article

  • Question about Target parameter of Matrix.CreateLookAt

    - by manning18
    I have a newbie question that's causing me a little bit of confusion when experimenting with cameras and reading other peoples implementations - does this parameter represent a point or a vector? In some examples I've seen people treat it like a specific point they are looking at (eg a position in the world), other times I see people caching the orientation of the camera in a rotation matrix and simply using the Matrix.Forward property as the "target", and other times it's a vector that's the result of targetPos - camPos and also I saw a camPos + orientation.Forward I was also just playing around with hard-coded target positions with same direction eg 1 to 10000 with no discernible difference in what I saw in the scene. Is the "Target" parameter actually a position or a direction (irrespective of magnitude)? Are there any subtle differences in behaviors, common mistakes or gotchas that are associated with what values you provide, or HOW you provide this paramter? Are all the methods I mentioned above equivalent? (sorry, I've only recently started and my math is still catching up)

    Read the article

  • Date calculation algorithm

    - by Julian Cuevas
    I'm working on a project to schedule a machine shop, basically I've got everything covered BUT date calculations, I've got a method called schedule (working on PHP here): public function schedule($start_date, $duration_in_minutes) Now my problem is, currently I'm calculating end time manually because time calculations have the following rules: During weekdays, work with business hours (7:00 AM to 5:00 PM) Work on Saturdays from 7:00 AM to 2:00 PM Ignore holidays (in Colombia we have A LOT of holidays) I already have a lookup table for holidays, I also have a Java version of this algorithm that I wrote for a previous version of the project, but that one's also manual. Is there any way to calculate an end time from a start time given duration?, my problem is that I have to consider the above rules, I'm looking for a (maybe?) math based solution, however I currently don't have the mind to devise such a solution myself. I'll be happy to provide code samples if necessary.

    Read the article

  • Breakout... Getting the ball reflection X angle when htitting paddle / bricks

    - by Steven Wilson
    Im currently creating a breakout clone for my first ever C# / XNA game. Currently Ive had little trouble creating the paddle object, ball object, and all the bricks. The issue im currently having is getting the ball to bounce off of the paddle and bricks correctly based off of where the ball touches the object. This is my forumala thus far: if (paddleLocation.Intersects(ballLocation)) { position.Y = paddleLocation.Y - texture.Height; motion.Y *= -1; // determine X motion.X = 1 - 2 * (ballLocation.X - paddleLocation.X) / (paddleLocation.Width / 2); } The problem is, the ball goes the opposite direction then its supposed to. When the ball hits the left side of the paddle, instead of bouncing back to the left, it bounces right, and vise versa. Does anyone know what the math equation is to fix this?

    Read the article

  • Deforming surfaces

    - by Constantin
    I try to accomplish an deforming physic behaviour for levelsurfaces, but don't get an idea how to start with the implemenation so far. Regardless of the shape from the surface (planes, cubes, spheres…), I want to have small indentations at the positions from game-entitys (players, enemys, objects…). It's kind of complicated to explain, so I illustrated what I'm talking about (here is an example with an sphere): So, the surfaces should be able to deforming themselfs a little bit (to apear like an really soft bed or sofa). My surfaces need probably an high vertices count to get an smooth deforming, but my big problem is the math for calculating this deforming… I'm programming in C/C++ with OpenGL, but will be fine with any advices in the right direction. Any help would be highly appreciated,

    Read the article

  • Fixing a collision detection bug in Slick2D

    - by Jesse Prescott
    My game has a bug with collision detection. If you go against the wall and tap forward/back sometimes the game thinks the speed you travelled at is 0 and the game doesn't know how to get you out of the wall. My collision detection works by getting the speed you hit the wall at and if it is positive it moves you back, if it is negative it moves you forward. It might help if you download it: https://rapidshare.com/files/1550046269/game.zip Sorry if I explained badly, it's hard to explain. float maxSpeed = 0.3f; float minSpeed = -0.2f; float acceleration = 0.002f; float deacceleration = 0.001f; float slowdownSpeed = 0.002f; float rotateSpeed = 0.08f; static float currentSpeed = 0; boolean up = false; boolean down = false; boolean noKey = false; static float rotate = 0; //Image effect system static String locationCarNormal; static String locationCarFront; static String locationCarBack; static String locationCarBoth; static boolean carFront = false; static boolean carBack = false; static String imageRef; boolean collision = false; public ComponentPlayerMovement(String id, String ScarNormal, String ScarFront, String ScarBack, String ScarBoth) { this.id = id; playerBody = new Rectangle(900/2-16, 700/2-16, 32, 32); locationCarNormal = ScarNormal; locationCarFront = ScarFront; locationCarBack = ScarBack; locationCarBoth = ScarBoth; imageRef = locationCarNormal; } @Override public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException { Input input = gc.getInput(); playerBody.transform(Transform.createRotateTransform(2)); float hip = currentSpeed * delta; float unstuckspeed = 0.05f * delta; if(carBack && !carFront) { imageRef = locationCarBack; ComponentImageRender.updateImage(); } else if(carFront && !carBack) { imageRef = locationCarFront; ComponentImageRender.updateImage(); } else if(carFront && carBack) { imageRef = locationCarBoth; ComponentImageRender.updateImage(); } if(input.isKeyDown(Input.KEY_RIGHT)) { rotate += rotateSpeed * delta; owner.setRotation(rotate); } if(input.isKeyDown(Input.KEY_LEFT)) { rotate -= rotateSpeed * delta; owner.setRotation(rotate); } if(input.isKeyDown(Input.KEY_UP)) { if(!collision) { up = true; noKey = false; if(currentSpeed < maxSpeed) { currentSpeed += acceleration; } MapCoordStorage.mapX += hip * Math.sin(Math.toRadians(rotate)); MapCoordStorage.mapY -= hip * Math.cos(Math.toRadians(rotate)); } else { currentSpeed = 1; } } else if(input.isKeyDown(Input.KEY_DOWN) && !collision) { down = true; noKey = false; if(currentSpeed > minSpeed) { currentSpeed -= slowdownSpeed; } MapCoordStorage.mapX += hip * Math.sin(Math.toRadians(rotate)); MapCoordStorage.mapY -= hip * Math.cos(Math.toRadians(rotate)); } else { noKey = true; if(currentSpeed > 0) { currentSpeed -= deacceleration; } else if(currentSpeed < 0) { currentSpeed += acceleration; } MapCoordStorage.mapX += hip * Math.sin(Math.toRadians(rotate)); MapCoordStorage.mapY -= hip * Math.cos(Math.toRadians(rotate)); } if(entityCollisionWith()) { collision = true; if(currentSpeed > 0 || up) { up = true; currentSpeed = 0; carFront = true; MapCoordStorage.mapX += unstuckspeed * Math.sin(Math.toRadians(rotate-180)); MapCoordStorage.mapY -= unstuckspeed * Math.cos(Math.toRadians(rotate-180)); } else if(currentSpeed < 0 || down) { down = true; currentSpeed = 0; carBack = true; MapCoordStorage.mapX += unstuckspeed * Math.sin(Math.toRadians(rotate)); MapCoordStorage.mapY -= unstuckspeed * Math.cos(Math.toRadians(rotate)); } else { currentSpeed = 0; } } else { collision = false; up = false; down = false; } if(currentSpeed >= -0.01f && currentSpeed <= 0.01f && noKey && !collision) { currentSpeed = 0; } } public static boolean entityCollisionWith() throws SlickException { for (int i = 0; i < BlockMap.entities.size(); i++) { Block entity1 = (Block) BlockMap.entities.get(i); if (playerBody.intersects(entity1.poly)) { return true; } } return false; } }

    Read the article

  • How to use Cambria as basic font when math symbols are needed?

    - by Jukka K. Korpela
    I first thought one could use Cambria for copy text (in Word), switching to Cambria Math only when needed (when a character is needed that is not present in Cambria). This does not seem to work that well. For example, if I need the minus-or-plus sign “±”, I cannot take it from Cambria, but if I use it from Cambria Math, it has a shape rather different from the style of “±”, “+”, and “–” in the text, if it is written in Cambria. Similarly, the multiplication sign “×” is much larger in Cambria Math than in Cambria. The obvious solution would be to use Cambria Math as copy text font, for uniformity. But Cambria Math lacks italic and bold. (Word’s formula editor uses Cambria Math by default and can do italic and bold, but it gets them from Plane 1 – they are special mathematic italic and mathematic bold characters, not italic and bold glyphs for normal characters.) Is there any better approach than using Cambria Math for copy text and switching to Cambria when italic or bold is needed?

    Read the article

  • How to get audio spectrum analysis?

    - by Mrwolfy
    I need to find or create a tool that analyzes the audio spectrum of a sound file (like a .wav or .mp3). I need to output the "volume" or power of x number of frequency bands and output the data as text. This will be used to produce a visualization, a graphic equalizer like you'd see on a stereo. I am currently looking at python to do it. My question is are there some tools out there that would do this (signal processing), like math works or others? I don't have any experience with them so any advice would be appreciated.

    Read the article

  • What are the steps taken by this GLSL code?

    - by user827992
    1 void main(void) 2 { 3 vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0); 4 float dist_squared = dot(pos, pos); 5 6 gl_FragColor = (dist_squared < 400.0) 7 ? vec4(.90, .90, .90, 1.0) 8 : vec4(.20, .20, .40, 1.0); 9 } taken from http://people.freedesktop.org/~idr/OpenGL_tutorials/03-fragment-intro.html Now, this looks really trivial and simple, but my problem is with the mod function. This function is taking 2 vec2 as inputs but is supposed to take just 2 atomic arguments according to the official documentation, also this function makes an implicit use of the floor function that only accepts, again, 1 atomic argument. Can someone explain this to me step by step and point out what I'm not getting here? It's some kind of OpenGL trick? OpenGL Math trick? in the GLSL docs i always find and explicit reference to the type accepted by the function and vec2 it's not there.

    Read the article

  • How to move an object along a circumference of another object?

    - by Lumis
    I am so out of math that it hurts, but for some of you this should be a piece of cake. I want to move an object around another along its ages or circumference on a simple circular path. At the moment my game algorithm knows how to move and position a sprite just at the edge of an obstacle and now it waits for the next point to move depending on various conditions. So the mathematical problem here is how to get (aX, aY) and (bX, bY) positions, when I know the Centre (cX, cY), the object position (oX, oY) and the distance required to move (d)

    Read the article

  • Vector normalization gives very imprecise results

    - by Kipras
    When I normalize vectors I receive very strange results. The lengths of the normalized vectors range from 1.0 to almost 1.5. The functions are all written by me, but I just can't find a mistake in my algorithm. When I normalize I just divide all components of the vector by the vector's length. public double length(){ return Math.sqrt(x*x + y*y); } public void normalize(){ if(length() > 0){ x /= length(); y /= length(); } } Is this supposed to happen? I mean I can see the length ranging from 0.9 to 1.1 at worst, but this is just overwhelming. Cheers

    Read the article

  • Do I need a Point and a Vector object? Or just using a Vector object to represent a Point is ok?

    - by JCM
    Structuring the components of an engine that I am developing along with a friend (learning purposes), I came to this doubt. Initially we had a Point constructor, like the following: var Point = function( x, y ) { this.x = x; this.y = y; }; But them we started to add some Vector math to it, and them decided to rename it to Vector2d. But now, some methods are a bit confusing (at least in my opinion), such as the following, which is used to make a line: //before the renaming of Point to Vector2, the parameters were startingPoint and endingPoint Geometry.Line = function( startingVector, endingVector ) { //... }; I should make a specific constructor for the Point object, or there are no problems in defining a point as a vector? I know a vector have magnitude and direction, but I see so many people using a vector to just represent the position of an object.

    Read the article

  • Sans-serif math with latex in matplotlib

    - by Morgoth
    The following script: import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as mpl mpl.rc('font', family='sans-serif') mpl.rc('text', usetex=True) fig = mpl.figure() ax = fig.add_subplot(1,1,1) ax.text(0.2,0.5,r"Math font: $451^\circ$") ax.text(0.2,0.7,r"Normal font (except for degree symbol): 451$^\circ$") fig.savefig('test.png') is an attempt to use a sans-serif font in matplotlib with LaTeX. The issue is that the math font is still a serif font (as indicated by the axis numbers, and as demonstrated by the labels in the center). Is there a way to set the math font to also be sans-serif?

    Read the article

  • Bounding Boxes for Circle and Arcs in 3D

    - by David Rutten
    Given curves of type Circle and Circular-Arc in 3D space, what is a good way to compute accurate bounding boxes (world axis aligned)? Edit: found solution for circles, still need help with Arcs. C# snippet for solving BoundingBoxes for Circles: public static BoundingBox CircleBBox(Circle circle) { Point3d O = circle.Center; Vector3d N = circle.Normal; double ax = Angle(N, new Vector3d(1,0,0)); double ay = Angle(N, new Vector3d(0,1,0)); double az = Angle(N, new Vector3d(0,0,1)); Vector3d R = new Vector3d(Math.Sin(ax), Math.Sin(ay), Math.Sin(az)); R *= circle.Radius; return new BoundingBox(O - R, O + R); } private static double Angle(Vector3d A, Vector3d B) { double dP = A * B; if (dP <= -1.0) { return Math.PI; } if (dP >= +1.0) { return 0.0; } return Math.Acos(dP); }

    Read the article

  • Help Understanding Function

    - by Fred F.
    What does the following function perform? public static double CleanAngle(double angle) { while (angle < 0) angle += 2 * System.Math.PI; while (angle > 2 * System.Math.PI) angle -= 2 * System.Math.PI; return angle; } This is how it is used with ATan2. I believe the actually values passed to ATan2 are always positive. static void Main(string[] args) { int q = 1; //'x- and y-coordinates will always be positive values //'therefore, do i need to "clean"? foreach (Point oPoint in new Point[] { new Point(8,20), new Point(-8,20), new Point(8,-20), new Point(-8,-20)}) { Debug.WriteLine(Math.Atan2(oPoint.Y, oPoint.X), "unclean " + q.ToString()); Debug.WriteLine(CleanAngle(Math.Atan2(oPoint.Y, oPoint.X)), "cleaned " + q.ToString()); q++; } //'output //'unclean 1: 1.19028994968253 //'cleaned 1: 1.19028994968253 //'unclean 2: 1.95130270390726 //'cleaned 2: 1.95130270390726 //'unclean 3: -1.19028994968253 //'cleaned 3: 5.09289535749705 //'unclean 4: -1.95130270390726 //'cleaned 4: 4.33188260327232 }

    Read the article

  • Stupid problem with Javascript calculations and postbacks

    - by rockinthesixstring
    I'm working on an ASP.NET web app where I'm using a Wizard to take the client through a large series of steps. One of the steps includes calculating a bunch of numbers on the fly... the numbers calculate properly but when I click "next" and then go back again... some of the numbers are not retained. Here is the calculation function function CalculateFields() { txtSellingPrice = document.getElementById('<%=txtSellingPrice.ClientID %>'); txtBalanceSheet = document.getElementById('<%=txtBalanceSheet.ClientID %>'); txtDownPayment = document.getElementById('<%=txtDownPayment.ClientID %>'); txtSusEarn = document.getElementById('<%=txtSusEarn.ClientID %>'); txtSusRev = document.getElementById('<%=txtSusRev.ClientID %>'); txtBalanceMult = document.getElementById('<%=txtBalanceMult.ClientID %>'); txtGoodwillMult = document.getElementById('<%=txtGoodwillMult.ClientID %>'); txtSellingPriceMult = document.getElementById('<%=txtSellingPriceMult.ClientID %>'); txtGoodWill = document.getElementById('<%=txtGoodWill.ClientID %>'); txtBalance = document.getElementById('<%=txtBalance.ClientID %>'); chkTakeBack = document.getElementById('<%=chkTakeBack.ClientID %>'); txtVendorTakeBackPercentage = document.getElementById('<%=txtVendorTakeBackPercentage.ClientID %>'); txtSusEarnPercentage = document.getElementById('<%=txtSusEarnPercentage.ClientID %>'); txtBalanceMultPercentage = document.getElementById('<%=txtBalanceMultPercentage.ClientID %>'); txtGoodwillMultPercentage = document.getElementById('<%=txtGoodwillMultPercentage.ClientID %>'); txtSellingPriceMultPercentage = document.getElementById('<%=txtSellingPriceMultPercentage.ClientID %>'); var regexp = /[$,]/g; //Empty value checks SellingPrice = (SellingPrice == "" ? "$0" : SellingPrice); BalanceSheet = (BalanceSheet == "" ? "$0" : BalanceSheet); DownPayment = (DownPayment == "" ? "$0" : DownPayment); susearn = (susearn == "" ? "$0" : susearn); susrev = (susrev == "" ? "$0" : susrev); balmult = (balmult == "" ? "$0" : balmult); goodmult = (goodmult == "" ? "$0" : goodmult); sellmult = (sellmult == "" ? "$0" : sellmult); //Replace $ with String.Empty SellingPrice = txtSellingPrice.value.replace(regexp, ""); BalanceSheet = txtBalanceSheet.value.replace(regexp, ""); DownPayment = txtDownPayment.value.replace(regexp, ""); susearn = txtSusEarn.value.replace(regexp, ""); susrev = txtSusRev.value.replace(regexp, ""); balmult = txtBalanceMult.value.replace(regexp, ""); goodmult = txtGoodwillMult.value.replace(regexp, ""); sellmult = txtSellingPriceMult.value.replace(regexp, ""); //Set the new values txtGoodWill.value = "$" + (SellingPrice - BalanceSheet); txtBalance.value = "$" + (SellingPrice - DownPayment); txtSellingPriceMult.value = "$" + SellingPrice; txtGoodwillMult.value = "$" + (SellingPrice - BalanceSheet); txtBalanceMult.value = "$" + BalanceSheet; if (chkTakeBack.checked == 1) { txtVendorTakeBackPercentage.value = Math.round((SellingPrice - DownPayment) / SellingPrice * 100); } else { txtVendorTakeBackPercentage.value = "0"; } if (!(susearn == "") && !(susearn == "0") && !(susearn == "$0")) { txtSusEarnPercentage.value = Math.round(susearn / susrev * 100); txtBalanceMultPercentage.value = Math.round(balmult / susearn); txtGoodwillMultPercentage.value = Math.round(goodmult / susearn); txtSellingPriceMultPercentage.value = Math.round(sellmult / susearn); } else { txtSusEarnPercentage.value = "0"; txtBalanceMultPercentage.value = "0"; txtGoodwillMultPercentage.value = "0"; txtSellingPriceMultPercentage.value = "0"; } } all of these calculate properly and retain their value across postbacks txtGoodWill.value = "$" + (SellingPrice - BalanceSheet); txtBalance.value = "$" + (SellingPrice - DownPayment); txtSellingPriceMult.value = "$" + SellingPrice; txtGoodwillMult.value = "$" + (SellingPrice - BalanceSheet); txtBalanceMult.value = "$" + BalanceSheet; These ones however do not retain their value across postbacks if (chkTakeBack.checked == 1) { txtVendorTakeBackPercentage.value = Math.round((SellingPrice - DownPayment) / SellingPrice * 100); } else { txtVendorTakeBackPercentage.value = "0"; } if (!(susearn == "") && !(susearn == "0") && !(susearn == "$0")) { txtSusEarnPercentage.value = Math.round(susearn / susrev * 100); txtBalanceMultPercentage.value = Math.round(balmult / susearn); txtGoodwillMultPercentage.value = Math.round(goodmult / susearn); txtSellingPriceMultPercentage.value = Math.round(sellmult / susearn); } else { txtSusEarnPercentage.value = "0"; txtBalanceMultPercentage.value = "0"; txtGoodwillMultPercentage.value = "0"; txtSellingPriceMultPercentage.value = "0"; } The txtVendorTakeBackPercentage always comes back BLANK and the other three always come back as 0 I'm firing these functions by using the onkeyup event within the form fields. If Not Page.IsPostBack Then txtSellingPrice.Attributes.Add("onkeyup", "CalculateFields()") txtBalanceSheet.Attributes.Add("onkeyup", "CalculateFields()") txtDownPayment.Attributes.Add("onkeyup", "CalculateFields()") txtSusRev.Attributes.Add("onkeyup", "CalculateFields()") txtSusEarn.Attributes.Add("onkeyup", "CalculateFields()") End If any thoughts/help/direction would be greatly appreciated.

    Read the article

  • Converting an equation into a way java script can interpret it

    - by GeorgeTaylor
    So I have this code that is meant to do this equation: (1 / 15) * arccos(-tan(L) * tan(23.44 * sin(360 * (D + 284) / 365))) and for testing purposes alert it! But for some reason it returns "NaN". I've probably done something really stupid :P var now = new Date(); var start = new Date(now.getFullYear(), 0, 0); var diff = now - start; var oneDay = 1000 * 60 * 60 * 24; var d = Math.floor(diff / oneDay); var lat = position.coords.latitude; var long = position.coords.longitude; var tanlat = Math.atan(lat); var tantwentythree = Math.tan(23.44); var dayplus = d + 284; var sinday = Math.sin(360 * dayplus); var arccos = Math.acos(tanlat); var start = 1 / 15; var equation = start * arccos * tantwentythree * sinday / 365; alert(equation);

    Read the article

  • Javascript for a prompt which accepts simple math as a value and then returns the answer

    - by user1139403
    I have written a snippet of code in javascript, for a prompt to appear when clicked. I want to be able to enter a simple math problem (i.e. 230/2) and have it output the answer, rather than the math problem I just entered. Your help will be much appreciated. <!DOCTYPE html> <html> <body> <button onclick="myFunction()">Click me</button> <p id="demo"></p> <script type="text/javascript"> function myFunction() { var x; var mathProblem=prompt("Enter your math problem",""); if (name!=null) { x = mathProblem; document.getElementById("demo").innerHTML = x; } } </script> </body> </html>

    Read the article

  • Understanding normal maps on terrain

    - by JohnB
    I'm having trouble understanding some of the math behind normal map textures even though I've got it to work using borrowed code, I want to understand it. I have a terrain based on a heightmap. I'm generating a mesh of triangles at load time and rendering that mesh. Now for each vertex I need to calculate a normal, a tangent, and a bitangent. My understanding is as follows, have I got this right? normal is a unit vector facing outwards from the surface of the triangle. For a vertex I take the average of the normals of the triangles using that vertex. tangent is a unit vector in the direction of the 'u' coordinates of the texture map. As my texture u,v coordinates follow the x and y coordinates of the terrain, then my understanding is that this vector is simply the vector along the surface in the x direction. So should be able to calculate this as simply the difference between vertices in the x direction to get a vector, (and normalize it). bitangent is a unit vector in the direction of the 'v' coordinates of the texture map. As my texture u,v coordinates follow the x and y coordinates of the terrain, then my understanding is that this vector is simply the vector along the surface in the y direction. So should be able to calculate this as simply the difference between vertices in the y direction to get a vector, (and normalize it). However the code I have borrowed seems much more complicated than this and takes into account the actual values of u, and v at each vertex which I don't understand the need for as they increase in exactly the same direction as x, and y. I implemented what I thought from above, and it simply doesn't work, the normals are clearly not working for lighting. Have I misunderstood something? Or can someone explain to me the physical meaning of the tangent and bitangent vectors when applied to a mesh generated from a hightmap like this, when u and v texture coordinates map along the x and y directions. Thanks for any help understanding this.

    Read the article

  • 3D Vector "End Point" Calculation for procedural Vector Graphics

    - by FrostFlame64
    Alright, So I need some help with some Vector Math. I've developing some game Engines that have Procedural Fractal Generation for Some Graphics, such as using Lindenmayer Systems for generating Trees and Plants. L-Systems, are drawn by using Turtle Graphics, which is a form of Vector graphics. I first created a system to draw in 2D Graphics, which works perfectly fine. But now I want to make a 3D equivalent, and I’ve run into an issue. For my 2D Version, I created a Method for quickly determining the “End Point” of a Vector-like movement. Given a starting point (X, Y), a direction (between 0 and 360 degrees), and a distance, the end point is calculated by these formulas: newX = startX + distance * Sin((PI * direction) / 180) newY = startY + distance * Cos((PI * direction) / 180) Now I need something Similarly Equivalent for performing this Calculation in 3D, But I haven’t been able to Google anything that could show me how to do this. I'm flexible enough to get whatever required information is needed for this method calculation, in any reasonable form (Vector3, Quaternion, ect). To summarize: Given a starting point/vector position in 3D space (X, Y, Z), a Direction in 3D space (Vector3, Quaternion, ect), and a Distance, I need to find the “End Point” in 3D Space. Thank you for your time and help.

    Read the article

  • Calculating 3d rotation around random axis

    - by mitim
    This is actually a solved problem, but I want to understand why my original method didn't work (hoping someone with more knowledge can explain). (Keep in mind, I've not very experienced in 3d programming, having only played with the very basic for a little bit...nor do I have a lot of mathematical experience in this area). I wanted to animate a point rotating around another point at a random axis, say a 45 degrees along the y axis (think of an electron around a nucleus). I know how to rotate using the transform matrix along the X, Y and Z axis, but not an arbitrary (45 degree) axis. Eventually after some research I found a suggestion: Rotate the point by -45 degrees around the Z so that it is aligned. Then rotate by some increment along the Y axis, then rotate it back +45 degrees for every frame tick. While this certainly worked, I felt that it seemed to be more work then needed (too many method calls, math, etc) and would probably be pretty slow at runtime with many points to deal with. I thought maybe it was possible to combine all the rotation matrixes involve into 1 rotation matrix and use that as a single operation. Something like: [ cos(-45) -sin(-45) 0] [ sin(-45) cos(-45) 0] rotate by -45 along Z [ 0 0 1] multiply by [ cos(2) 0 -sin(2)] [ 0 1 0 ] rotate by 2 degrees (my increment) along Y [ sin(2) 0 cos(2)] then multiply that result by (in that order) [ cos(45) -sin(45) 0] [ sin(45) cos(45) 0] rotate by 45 along Z [ 0 0 1] I get 1 mess of a matrix of numbers (since I was working with unknowns and 2 angles), but I felt like it should work. It did not and I found a solution on wiki using a different matirx, but that is something else. I'm not sure if maybe I made an error in multiplying, but my question is: this is actually a viable way to solve the problem, to take all the separate transformations, combine them via multiplying, then use that or not?

    Read the article

  • Vector vs Scalar velocity?

    - by Serguei Fedorov
    I am revamping an engine I have been working on and off on for the last few weeks to use a directional vector to dictate direction; this way I can dictate the displacement based on a direction. However, the issue I am trying to overcome is the following problem; the speed towards X and speed towards Y are unrelated to one another. If gravity pulls the object down by an increasing velocity my velocity towards the X should not change. This is very easy to implement if my speed is broken into a Vector datatype, Vector.X dictates one direction Vector.Y dictates the other (assuming we are not concerned about the Z axis). However, this defeats the purpose of the directional vector because: SpeedX = 10 SpeedY = 15 [1, 1] normalized = ~[0.7, 0.7] [0.7, 0.7] * [10, 15] = [7, 10.5] As you can see my direction is now "scaled" to my speed which is no longer the direction that I want to be moving in. I am very new to vector math and this is a learning project for me. I looked around a little bit on the internet but I still want to figure out things on my own (not just look at an example and copy off it). Is there way around this? Using a directional vector is extremely useful but I am a little bit stumped at this problem. I am sorry if my mathematical understanding maybe completely wrong.

    Read the article

  • Japanese Multiplication simulation - is a program actually capable of improving calculation speed?

    - by jt0dd
    On SuperUser, I asked a (possibly silly) question about processors using mathematical shortcuts and would like to have a look at the possibility at the software application of that concept. I'd like to write a simulation of Japanese Multiplication to get benchmarks on large calculations utilizing the shortcut vs traditional CPU multiplication. I'm curious as to whether it makes sense to try this. My Question: I'd like to know whether or not a software math shortcut, as described above is actually a shortcut at all. This is a question of programming concept. By utilizing the simulation of Japanese Multiplication, is a program actually capable of improving calculation speed? Or am I doomed from the start? The answer to this question isn't required to determine whether or not the experiment will succeed, but rather whether or not it's logically possible for such a thing to occur in any program, using this concept as an example. My theory is that since addition is computed faster than multiplication, a simulation of Japanese multiplication may actually allow a program to multiply (large) numbers faster than the CPU arithmetic unit can. I think this would be a very interesting finding, if it proves to be true. If, in the multiplication of numbers of any immense size, the shortcut were to calculate the result via less instructions (or faster) than traditional ALU multiplication, I would consider the experiment a success.

    Read the article

  • JavaScript 3D space ship rotation

    - by user36202
    I am working with a fairly low-level JavaScript 3D API (not Three.js) which uses euler angles for rotation. In most cases, euler angles work quite well for doing things like aligning buildings, operating a hovercraft, or looking around in the first-person. However, in space there is no up or down. I want to control the ship's roll, pitch, and yaw. To do that, some people would use a local coordinate system or a permenant matrix or quaternion or whatever to represent the ship's angle. However, since I am not most people and am using a library that deals exclusively in euler angles, I will be using relative angles to represent how to rotate the ship in space and getting the resulting non-relative euler angles. For you math nerds, that means I need to convert 3 euler angles (with Y being the vertical axis, X representing the pitch, and Z representing a roll which is unaffected by the other angles, left-handed system) into a 3x3 orientation matrix, do something fancy with the matrix, and convert it back into the 3 euler angles. Euler to matrix to euler. Somebody has posted something similar to this on SO (http://stackoverflow.com/questions/1217775/rotating-a-spaceship-model-for-a-space-simulator-game) but he ended up just working with a matrix. This will not do for me. Also, I am using JavaScript, not C++. What I want essentially are the functions do_roll, do_pitch, and do_yaw which only take in and put out euler angles. Many thanks.

    Read the article

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