Daily Archives

Articles indexed Saturday December 15 2012

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

  • How to properly do weapon cool-down reload timer in multi-player laggy environment?

    - by John Murdoch
    I want to handle weapon cool-down timers in a fair and predictable way on both client on server. Situation: Multiple clients connected to server, which is doing hit detection / physics Clients have different latency for their connections to server ranging from 50ms to 500ms. They want to shoot weapons with fairly long reload/cool-down times (assume exactly 10 seconds) It is important that they get to shoot these weapons close to the cool-down time, as if some clients manage to shoot sooner than others (either because they are "early" or the others are "late") they gain a significant advantage. I need to show time remaining for reload on player's screen Clients can have clocks which are flat-out wrong (bad timezones, etc.) What I'm currently doing to deal with latency: Client collects server side state in a history, tagged with server timestamps Client assesses his time difference with server time: behindServerTimeNs = (behindServerTimeNs + (System.nanoTime() - receivedState.getServerTimeNs())) / 2 Client renders all state received from server 200 ms behind from his current time, adjusted by what he believes his time difference with server time is (whether due to wrong clocks, or lag). If he has server states on both sides of that calculated time, he (mostly LERP) interpolates between them, if not then he (LERP) extrapolates. No other client-side prediction of movement, e.g., to make his vehicle seem more responsive is done so far, but maybe will be added later So how do I properly add weapon reload timers? My first idea would be for the server to send each player the time when his reload will be done with each world state update, the client then adjusts it for the clock difference and thus can estimate when the reload will be finished in client-time (perhaps considering also for latency that the shoot message from client to server will take as well?), and if the user mashes the "shoot" button after (or perhaps even slightly before?) that time, send the shoot event. The server would get the shoot event and consider the time shot was made as the server time when it was received. It would then discard it if it is nowhere near reload time, execute it immediately if it is past reload time, and hold it for a few physics cycles until reload is done in case if it was received a bit early. It does all seem a bit convoluted, and I'm wondering whether it will work (e.g., whether it won't be the case that players with lower ping get better reload rates), and whether there are more elegant solutions to this problem.

    Read the article

  • Points around a circumference C#

    - by Lautaro
    Im trying to get a list of vectors that go around a circle, but i keep getting the circle to go around several times. I want one circel and the dots to be placed along its circumference. I want the first dot to start at 0 and the last dot to end just before 360. Also i need to be able to calculate the spacing by the ammount of points. List<Vector2> pointsInPath = new List<Vector2>(); private int ammountOfPoints = 5; private int blobbSize = 200; private Vector2 topLeft = new Vector2(100, 100); private Vector2 blobbCenter; private int endAngle = 50; private int angleIncrementation; public Blobb() { blobbCenter = new Vector2(blobbSize / 2, blobbSize / 2) + topLeft; angleIncrementation = endAngle / ammountOfPoints; for (int i = 0; i < ammountOfPoints; i++) { pointsInPath.Add(getPointByAngle(i * angleIncrementation, 100, blobbCenter)); // pointsInPath.Add(getPointByAngle(i * angleIncrementation, blobbSize / 2, blobbCenter)); } } private Vector2 getPointByAngle(float angle, float distance, Vector2 centre) { return new Vector2((float)(distance * Math.Cos(angle) ), (float)(distance * Math.Sin(angle))) + centre ; }

    Read the article

  • TexturePacker ignores extensions

    - by The Oddler
    I'm using TexturePacker in one of my games, though when packing a bunch of textures their extension is kept in the data file. So when I want to find a texture I need to search for "image.png" instead of just "image". Is there an option to let texture packer ignore the extensions of my source images in the data file? Solved: So if anyone else wants this, here's the exported I made: https://www.box.com/s/bf12q1i1yc9jr2c5yehd Just extract it into "C:\Program Files (x86)\CodeAndWeb\TexturePacker\bin\exporters\UIToolkit No Extensions" (or something similar) and it should show op as an exporter.

    Read the article

  • How can I stop my Jitter physics meshes being offset?

    - by ben1066
    I'm developing a C# game engine and have hit a snag trying to add physics. I'm using XNA for graphics and Jitter for physics. I am trying to split the XNA model into it's meshes, then create a ConvexHull for each mesh. I then attempt to combine those into a CompoundObject, this however isn't working and depending upon the model the meshes are offset by different amounts. This is the code I'm currently using and it gives me: Any ideas?

    Read the article

  • Connection between Properties of Entities in Data Oriented Design

    - by sharethis
    I want to start with an example illustrating my question. The following way it is done in the most games. class car { vec3 position; vec3 rotation; mesh model; imge texture; void move(); // modify position and rotation void draw(); // use model, texture, ... }; vector<car> cars; for(auto i = cars.begin(); i != cars.end(); ++i) { i->move(); i->draw(); } Data oriented design means to process the same calculation on the hole batch of data at once. This way it takes more advantage out of the processor cache. struct movedata { vec3 position; vec3 rotation; }; struct drawdata { mesh model; imge texture; }; vector<movedata> movedatas; vector<drawdata> drawdatas; for(auto i = movedatas.begin(); i != movedatas.end(); ++i) { // modify position and rotation } for(auto i = drawdatas.begin(); i != drawdatas.end(); ++i) { // use model, texture, ... } But there comes a point where you need to find other properties according to an entity. For example if the car crashes, I do not need the drawdata and the movedata any more. So I need to delete the entries of this entity in all vectors. The entries are not linked by code. So my question is the following. How are properties of the same entity conceptually linked in a data oriented design?

    Read the article

  • InputText inside Primefaces dataTable is not refreshed

    - by robson
    I need to have inputTexts inside datatable when form is in editable mode. Everything works properly except form cleaning with immediate="true" (without form validation). Then primefaces datatable behaves unpredictable. After filling in datatable with new data - it still stores old values. Short example: test.xhtml <h:body> <h:form id="form"> <p:dataTable var="v" value="#{test.list}" id="testTable"> <p:column headerText="Test value"> <p:inputText value="#{v}"/> </p:column> </p:dataTable> <h:dataTable var="v" value="#{test.list}" id="testTable1"> <h:column> <f:facet name="header"> <h:outputText value="Test value" /> </f:facet> <p:inputText value="#{v}" /> </h:column> </h:dataTable> <p:dataTable var="v" value="#{test.list}" id="testTable2"> <p:column headerText="Test value"> <h:outputText value="#{v}" /> </p:column> </p:dataTable> <p:commandButton value="Clear" actionListener="#{test.clear()}" immediate="true" update=":form:testTable :form:testTable1 :form:testTable2"/> <p:commandButton value="Update" actionListener="#{test.update()}" update=":form:testTable :form:testTable1 :form:testTable2"/> </h:form> </h:body> And java: import java.io.Serializable; import java.util.ArrayList; import java.util.List; import javax.annotation.PostConstruct; import javax.faces.bean.ViewScoped; import javax.inject.Inject; import javax.inject.Named; @Named @ViewScoped public class Test implements Serializable { private static final long serialVersionUID = 1L; private List<String> list; @PostConstruct private void init(){ update(); } public List<String> getList() { return list; } public void setList(List<String> list) { this.list = list; } public void clear() { list = new ArrayList<String>(); } public void update() { list = new ArrayList<String>(); list.add("Item 1"); list.add("Item 2"); } } In the example above I have 3 configurations: 1. p:dataTable with p:inputText 2. h:dataTable with p:inputText 3. p:dataTable with h:outputText And 2 buttons: first clears data, second applies data Workflow: 1. Try to change data in inputTexts in p:dataTable and h:dataTable 2. Clear data of list (arrayList of string) - click "clear" button (imagine that you click cancel on form because you don't want to store data to database) 3. Load new data - click "update" button (imagine that you are openning new form with new data) Question: Why p:dataTable with p:inputText still stores manually changed data, not the loaded ones? Is there any way to force p:dataTable to behaving like h:dataTable in this case?

    Read the article

  • Objective-C Simple Inheritance and OO Principles

    - by bleeckerj
    I have a subclass SubClass that inherits from baseclass BaseClass. BaseClass has an initializer, like so: -(id)init { self = [super init]; if(self) { [self commonInit]; } return self; } -(void)commonInit { self.goodStuff = [[NSMutableArray alloc]init]; } SubClass does its initializer, like so: -(id)init { self = [super init]; if(self) { [self commonInit]; } return self; } -(void)commonInit { self.extraGoodStuff = [[NSMutableArray alloc]init]; } Now, I've *never taken a proper Objective-C course, but I'm a programmer more from the Electrical Engineering side, so I make do. I've developed server-side applications mostly in Java though, so I may be seeing the OO world through Java principles. When SubClass is initialized, it calls the BaseClass init and my expectation would be — because inheritance to me implies that characteristics of a BaseClass pass through to SubClass — that the commonInit method in BaseClass would be called during BaseClass init. It is not. I can *sorta understand maybe-possibly-stretch-my-imagination why it wouldn't be. But, then — why wouldn't it be based on the principles of OOP? What does "self" represent if not the instance of the class of the running code? Okay, so — I'm not going to argue that what a well-developed edition of Objective-C is doing is wrong. So, then — what is the pattern I should be using in this case? I want SubClass to have two main bits — the goodStuff that BaseClass has as well as the extraGoodStuff that it deserves as well. Clearly, I've been using the wrong pattern in this type of situation. Am I meant to expose commonInit (which makes me wonder about encapsulation principles — why expose something that, in the Java world at least, would be considered "protected" and something that should only ever be called once for each instance)? I've run into a similar problem in the recent past and tried to muddle through it, but now — I'm really wondering if I've got my principles and concepts all straight in my head. Little help, please.

    Read the article

  • How to permanently remove xcuserdata under the project.xcworkspace and resolve uncommitted changes

    - by JeffB6688
    I am struggling with a problem with a merge conflict (see Cannot Merge due to conflict with UserInterfaceState.xcuserstate). Based on feedback, I needed to remove the UserInterfaceState.xcuserstate using git rm. After considerable experimentation, I was able to remove the file with "git rm -rf project.xcworkspace/xcuserdata". So while I was on the branch I was working on, it almost immediately came back as a file that needed to be committed. So I did the git rm on the file again and just switched back to the master. Then I performed a git rm on the file again. The operation again removed the file. But I am still stuck. If I try to merge the branch into the master branch, it again says that I have uncommitted changes. So I go to commit the change. But this time, it shows UserInterfaceState.xcuserstate as the file to commit, but the box is unchecked and it can't be checked. So I can't move forward. Is there a way to use 'git rm' to permanently remove xcuserdata under the project.xcworkspace? Help!! Any ideas?

    Read the article

  • is there a proper way to handle multiple errors/exceptions?

    - by toPeerOrNotToPeer
    in OO programming, is there some conceptual pattern, ideas, about handling multiple errors? for example, i have a method that performs some checks and should return an error message for each error found ['name is too short', 'name contains invalid unicode sequences', 'name is too long'] now, should i use an array of exceptions (not thrown exceptions)? or something like this is better: class MyExceptionList extends Exception{ public Void addException(Exception e){} public Array getExceptions(){} } any theory behind this argument will be appreciated! (this isn't a request about a specific programming language, but a pure theoretical one) thank you in advance

    Read the article

  • JQuery Tablesorter clear table information

    - by conversoid
    I've created a jquery table that from time to time needs to be cleared and the re-populated, my clear method is this: //Clear table content before repopulating values $('#tabela_dash2_maquinas .real-content table tr:gt(0)').remove(); Now i'm trying to use tablesorter to sort a specific column, but my problem is that when I enable the tablesorter: //Initialize tablesorter $("table").tablesorter(); The table clearing method is not working anymore, it just keeps adding the new data with the old data, creating a lot of repeated information. Please help

    Read the article

  • Using variables in Tasker

    - by Waza_Be
    I am trying to create a Tasker plugin. Everything is fine, and works pretty well. I can configure a String to be sent in my app by using EditActivity and this code, following the examples: resultIntent.putExtra(com.twofortyfouram.locale.Intent.EXTRA_BUNDLE,PluginBundleManager.generateBundle(getApplicationContext(),message)); resultIntent.putExtra(com.twofortyfouram.locale.Intent.EXTRA_STRING_BLURB,generateBlurb(getApplicationContext(), message)); setResult(RESULT_OK, resultIntent); The problem comes when I want to use this code to get the battery level for instance, so I added: resultIntent.putExtra("net.dinglisch.android.tasker.extras.VARIABLE_REPLACE_KEYS",com.twofortyfouram.locale.Intent.EXTRA_STRING_BLURB); but the app is not working and I get a string %BATT as the result, the variable is not replaced... As I haven't found any example, I would be pleased to get some help to make it work.

    Read the article

  • vector does not erase content correctly (infite amount run of copy asignment operator untill crash [BEX])?

    - by Gam Erix
    Well my problem is that after I want to "unload" loaded DLL's the copy assignmnent operator is called an unlimited amount of times until crash. The code from which I remove the vector data looks like this: void UnloadPlugins() { dbg(("[DBG]UnloadPlugins()")); for(std::vector<DLLInfo>::iterator it = plugins.begin(); it != plugins.end(); ++it) { plugins.erase(it); } dbg(("[DBG]UnloadPlugins()::Done")); } however "[DBG]UnloadPlugins()::Done" gets never printed. this is my copy assignmnent operator: // 2. copy assignment operator DLLInfo& operator=(const DLLInfo& that) { dbg(("[DBG]Start-DLLInfo& operator=(const DLLInfo& that)")); Instance = that.Instance;//hinstance dbg(("[DBG]DLLInfo 1")); //Identifier.assign(that.Identifier);//string dbg(("[DBG]DLLInfo 2")); IsAMX = that.IsAMX;//integer dbg(("[DBG]DLLInfo 3")); dwSupportFlags = that.dwSupportFlags;//integer dbg(("[DBG]DLLInfo 4")); Load = that.Load;//integer dbg(("[DBG]DLLInfo 5")); Unload = that.Unload;//integer dbg(("[DBG]DLLInfo 6")); Supports = that.Supports;//integer dbg(("[DBG]DLLInfo 7")); ProcessTick = that.ProcessTick;//integer dbg(("[DBG]DLLInfo 8")); AmxLoad = that.AmxLoad;//integer dbg(("[DBG]DLLInfo 9")); AmxUnload = that.AmxUnload;//integer dbg(("[DBG]DLLInfo 10")); UseDestructor = that.UseDestructor;//bool dbg(("[DBG]DLLInfo 11")); KeyboardHit = that.KeyboardHit;//integer dbg(("[DBG]End-DLLInfo& operator=(const DLLInfo& that)")); return *this; } So the log looks like: [17:50:50] [DBG]UnloadPlugins() [17:50:50] [DBG]~DLLInfo [17:50:50] [DBG]~DLLInfo::if(this->UseDestructor) passed [17:50:50] [DBG]~DLLInfo::if(this->UseDestructor)::if(this->Unload != NULL && this->IsAMX) passed [17:50:50] [DBG]~DLLInfo::end [17:50:50] [DBG]Start-DLLInfo& operator=(const DLLInfo& that) [17:50:50] [DBG]DLLInfo 1 [17:50:50] [DBG]DLLInfo 2 [17:50:50] [DBG]DLLInfo 3 [17:50:50] [DBG]DLLInfo 4 [17:50:50] [DBG]DLLInfo 5 [17:50:50] [DBG]DLLInfo 6 [17:50:50] [DBG]DLLInfo 7 [17:50:50] [DBG]DLLInfo 8 [17:50:50] [DBG]DLLInfo 9 [17:50:50] [DBG]DLLInfo 10 [17:50:50] [DBG]DLLInfo 11 [17:50:50] [DBG]End-DLLInfo& operator=(const DLLInfo& that) [17:50:50] [DBG]Start-DLLInfo& operator=(const DLLInfo& that) ... [17:50:50] [DBG]End-DLLInfo& operator=(const DLLInfo& that) ...repeat until crash What could the problem be?

    Read the article

  • Where to put the star in C and C++ pointer notation

    - by Martin Kristiansen
    For some time the following has been annoing me, where should I put the star in my pointer notation. int *var; // 1 and int* var; // 2 obviously do the same thing, and both notations are correct, but I find that most literature and code I look at use the 1th notation. wouldn't it be more 'correct' to use the 2th notation, separating the type and the variable name by a whitespace, rather than mixing the type and variable tokens?

    Read the article

  • Returning an array of culture formatted dates C# MVC3

    - by user1875797
    I'm new to programming and trying to do an exercise that formats a date to the Thai culture in a variety of formats this is what I have for my code so far: public String[] FormatAsSpecified(DateTime theDate, String theCulture, String[] formats) { String[] dateResults = new String[formats.Length]; CultureInfo culture = CultureInfo.GetCultureInfo(theCulture); for (int i = 0; i < formats.Length; i++) { String culture_formatted_date = theDate.ToString(formats[i], culture); dateResults[i] = culture_formatted_date; } return dateResults; } This is the test method that goes with it: [TestMethod] public void FormatAsSpecifiedReturnsDateLiteralsInSpecifiedFormatForAllStandardFormatStrings() { //Arrange var controller = new DateController(); var theDate = new DateTime(2014, 2, 14, 9, 15, 32, 376); String theCulture = "th-TH"; // Array of all supported standard date and time format specifiers. String[] formats = { "d", "D", "f", "F", "g", "G", "m", "o", "r", "s", "t", "T", "u", "U", "Y" }; //Corresponding date literals for the standard Thai regional settings String[] expectedResults = {"14/2/2557" , "14 ?????????? 2557" , "14 ?????????? 2557 9:15" , "14 ?????????? 2557 9:15:32" , "14/2/2557 9:15" , "14/2/2557 9:15:32" , "14 ??????????" , "2014-02-14T09:15:32.3760000" , "Fri, 14 Feb 2014 09:15:32 GMT" , "2014-02-14T09:15:32" , "9:15" , "9:15:32" , "2014-02-14 09:15:32Z" , "??????????? 14 ?????????? 2014 9:15:32" , "?????????? 2557"}; //Act String[] actualResults = new String[15]; for (int i = 0; i < formats.Length; i++) { actualResults[i] = controller.FormatAsSpecified(theDate, theCulture, formats[i]); } //Assert CollectionAssert.AreEqual(expectedResults, actualResults); } I get an error in the test method at 'controller.FormatAsSpecified(theDate, theCulture, formats[i]);' that says "Argument 3, cannot convert from 'string' to 'string[]'" What am I doing wrong?

    Read the article

  • Convert 2 char into 1 int

    - by Leo
    I have 2 chars: HIGH and LOW and I'd like to convert them to an int corresponding to HIGH + the 2 left bits from LOW. I tried somethine like : char *HIGH; char *LOW; HIGH = 152; LOW = 12; int result; result += (LOW + 6); result += (LOW + 7)*2; result += HIGH*4; result += (HIGH + 1)*8; result += (HIGH + 2)*16; result += (HIGH + 3)*32; result += (HIGH + 4)*64; result += (HIGH + 5)*128; result += (HIGH + 6)*256; result += (HIGH + 7)*512; return result; But it doesn't work and I don't understand why.

    Read the article

  • Set intersection of two strings

    - by user1785712
    import java.util.*; class set { public static void main(String args[]) { TreeSet<Character> t1 = new TreeSet<Character>(); TreeSet<Character> t2 = new TreeSet<Character>(); String s1 = "Ambitab bachan"; String s2 = "Ranjikanth"; for(char c1:s1.toCharArray()) t1.add(c1); for(char c2:s2.toCharArray()) t2.add(c2); t2.retainAll(t1); System.out.println(t2); } } this program find the common character in two different string. in this program Treeset is used to store the value and retainAll() method is used to find the common characters. can anybody help me reduce the line of coding.thanks in advance

    Read the article

  • Printf ubuntu Segmentation fault (core dumped)

    - by Someone
    I have this code: int a; printf("&a = %u\n",(unsigned)&a); printf("a\n"); printf("b\n"); printf("c\n"); printf("d\n"); I tried to print the pointer of a variable. But it fail on the row printf("a\n"); and says Segmentation fault (core dumped) Output: &a = 134525024 Segmentation fault (core dumped) When I remove the row printf("&a = %u\n",(unsigned)&a); from the code, its success. Output: a b c d What worng in my code?

    Read the article

  • error : The element type "string" must be terminated by the matching end-tag "</string>"

    - by Priyanka
    ended the statement with and clean the the project still i am getting the same error ,here i am placing the code <resources> <string name="app_name">LiveWallpaper1</string> <string name="hello_world">Hello world!</string> <string name="menu_settings">Settings</string> <string name="title_activity_main">MainActivity</string> <string name="wallpaper_description">wallpaper descriptioning></string> </resources>

    Read the article

  • Load view when button is clicked in Xcodes Storyboard

    - by dooonot
    I just started to use Storyboard in Xcode. I have a starting view that has some buttons inside. Is there a way to load a special view when a button is clicked? I only found this workaround: -(IBAction)loadRegistration:(id)sender { // load registration controller UIStoryboard *storyboard = self.storyboard; RegisterController *svc = [storyboard instantiateViewControllerWithIdentifier:@"RegisterController"]; [self presentViewController:svc animated:YES completion:nil]; }

    Read the article

  • True / false evaluation doesn't work as expected in Scheme

    - by ron
    I'm trying to compare two booleans : (if (equal? #f (string->number "123b")) "not a number" "indeed a number") When I run this in the command line of DrRacket I get "not a number" , however , when I put that piece of code in my larger code , the function doesn't return that string ("not a number") , here's the code : (define (testing x y z) (define badInput "ERROR") (if (equal? #f (string->number "123b")) "not a number" "indeed a number") (display x)) And from command line : (testing "123" 1 2) displays : 123 Why ? Furthermore , how can I return a value , whenever I choose ? Here is my "real" problem : I want to do some input check to the input of the user , but the thing is , that I want to return the error message if I need , before the code is executed , because if won't - then I would run the algorithm of my code for some incorrect input : (define (convert originalNumber s_oldBase s_newBase) (define badInput "ERROR") ; Input check - if one of the inputs is not a number then return ERROR (if (equal? #f (string->number originalNumber)) badInput) (if (equal? #f (string->number s_oldBase)) badInput) (if (equal? #f (string->number s_newBase)) badInput) (define oldBase (string->number s_oldBase)) (define newBase (string->number s_newBase)) (define outDecimal (convertIntoDecimal originalNumber oldBase)) (define result "") ; holds the new number (define remainder 0) ; remainder for each iteration (define whole 0) ; the whole number after dividing (define temp 0) (do() ((= outDecimal 0)) ; stop when the decimal value reaches 0 (set! whole (quotient outDecimal newBase)) ; calc the whole number (set! temp (* whole newBase)) (set! remainder (- outDecimal temp)) ; calc the remainder (set! result (appending result remainder)) ; append the result (set! outDecimal (+ whole 0)) ; set outDecimal = whole ) ; end of do (if (> 1 0) (string->number (list->string(reverse (string->list result))))) ) ;end of method This code won't work since it uses another method that I didn't attach to the post (but it's irrelevant to the problem . Please take a look at those three IF-s ... I want to return "ERROR" if the user put some incorrect value , for example (convert "23asb4" "b5" "9") Thanks

    Read the article

  • Prolog for beginners about logic and syntax

    - by lnotik
    Hello everybody. I have this question : I need to create a paradict "rightGuesses" which will get 3 arguments , each one of them is a list of letters : 1) The list of guessed letters 2) The word i have to guess 3) The letters that where guessed so far . for example : rightGuesses([n,o,p,q], [p,r,o,l,o,g], Ans). will give us Ans = [p, -, o, -, o, -]. i made: rightGuesses([],T2,[ANS]) rightGuesses([A|T1],T2,[ANS]):- (member(A,T2))=\=true , rightGuesses(T1,T2,[ _ |'-']). rightGuesses([A|T1],T2,[ANS]):- member(A,T2), rightGuesses(T1,T2,[ _ |A]). but i get : ERROR: c:/users/leonid/desktop/file3.pl:5:0: Syntax error: Operator expected Warning: c:/users/leonid/desktop/file3.pl:6: when i trying to compile it what is my problem , and is there is a better way to do it ? thanks in advance.

    Read the article

  • Best Design Pattern to Implement while Mapping Actions in MVC

    - by FidEliO
    What could be the best practices of writing the following case: We have a controller which based on what paths users take, take different actions. For example: if user chooses the path /path1/hello it will say hello. If a user chooses /path1/bye?name="Philipp" it will invoke sayGoodBye() and etc. I have written a switch statement inside the controller which is simple, however IMO not efficient. What are the best way to implement this, considering that paths are generally String. private void takeAction() { switch (path[1]) { case "hello": //sayHello(); break; case "bye": //sayBye(); break; case "case3": //Blah(); break; ... } }

    Read the article

  • openCV center of image rotation in C

    - by user1477955
    I want to rotate 90 degrees counterclockwise, but it seems the rotation point is wrong. How do I find the rotation center of the source image? img=cvLoadImage(argv[1],-1); height = img->height; width = img->width; step = img->widthStep; channels = img->nChannels; data = (uchar *)img->imageData; IplImage *rotatedImg = cvCreateImage(cvSize(height,width), IPL_DEPTH_8U,img->nChannels); CvPoint2D32f center; center.x = width/2; center.y = height/2; CvMat *mapMatrix = cvCreateMat( 2, 3, CV_32FC1 ); cv2DRotationMatrix(center, 90, 1.0, mapMatrix); cvWarpAffine(img, rotatedImg, mapMatrix, CV_INTER_LINEAR + CV_WARP_FILL_OUTLIERS, cvScalarAll(0)); cvShowImage("My image", rotatedImg );

    Read the article

  • Drawing using Dynamic Array and Buffer Object

    - by user1905910
    I have a problem when creating the vertex array and the indices array. I don't know what really is the problem with the code, but I guess is something with the type of the arrays, can someone please give me a light on this? #define GL_GLEXT_PROTOTYPES #include<GL/glut.h> #include<iostream> using namespace std; #define BUFFER_OFFSET(offset) ((GLfloat*) NULL + offset) const GLuint numDiv = 2; const GLuint numVerts = 9; GLuint VAO; void display(void) { enum vertex {VERTICES, INDICES, NUM_BUFFERS}; GLuint * buffers = new GLuint[NUM_BUFFERS]; GLfloat (*squareVerts)[2] = new GLfloat[numVerts][2]; GLubyte * indices = new GLubyte[numDiv*numDiv*4]; GLuint delta = 80/numDiv; for(GLuint i = 0; i < numVerts; i++) { squareVerts[i][1] = (i/(numDiv+1))*delta; squareVerts[i][0] = (i%(numDiv+1))*delta; } for(GLuint i=0; i < numDiv; i++){ for(GLuint j=0; j < numDiv; j++){ //cada iteracao gera 4 pontos #define NUM_VERT(ii,jj) ((ii)*(numDiv+1)+(jj)) #define INDICE(ii,jj) (4*((ii)*numDiv+(jj))) indices[INDICE(i,j)] = NUM_VERT(i,j); indices[INDICE(i,j)+1] = NUM_VERT(i,j+1); indices[INDICE(i,j)+2] = NUM_VERT(i+1,j+1); indices[INDICE(i,j)+3] = NUM_VERT(i+1,j); } } glGenVertexArrays(1, &VAO); glBindVertexArray(VAO); glGenBuffers(NUM_BUFFERS, buffers); glBindBuffer(GL_ARRAY_BUFFER, buffers[VERTICES]); glBufferData(GL_ARRAY_BUFFER, sizeof(squareVerts), squareVerts, GL_STATIC_DRAW); glVertexPointer(2, GL_FLOAT, 0, BUFFER_OFFSET(0)); glEnableClientState(GL_VERTEX_ARRAY); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[INDICES]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0,1.0,1.0); glDrawElements(GL_POINTS, 16, GL_UNSIGNED_BYTE, BUFFER_OFFSET(0)); glutSwapBuffers(); } void init() { glClearColor(0.0, 0.0, 0.0, 0.0); gluOrtho2D((GLdouble) -1.0, (GLdouble) 90.0, (GLdouble) -1.0, (GLdouble) 90.0); } int main(int argv, char** argc) { glutInit(&argv, argc); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); glutInitWindowSize(500,500); glutInitWindowPosition(100,100); glutCreateWindow("myCode.cpp"); init(); glutDisplayFunc(display); glutMainLoop(); return 0; } Edit: The problem here is that drawing don't work at all. But I don't get any error, this just don't display what I want to display. Even if I put the code that make the vertices and put them in the buffers in a diferent function, this don't work. I just tried to do this: void display(void) { glBindVertexArray(VAO); glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0,1.0,1.0); glDrawElements(GL_POINTS, 16, GL_UNSIGNED_BYTE, BUFFER_OFFSET(0)); glutSwapBuffers(); } and I placed the rest of the code in display in another function that is called on the start of the program. But the problem still

    Read the article

  • OpenCV: Shift/Align face image relative to reference Image (Image Registration)

    - by Abhischek
    I am new to OpenCV2 and working on a project in emotion recognition and would like to align a facial image in relation to a reference facial image. I would like to get the image translation working before moving to rotation. Current idea is to run a search within a limited range on both x and y coordinates and use the sum of squared differences as error metric to select the optimal x/y parameters to align the image. I'm using the OpenCV face_cascade function to detect the face images, all images are resized to a fixed (128x128). Question: Which parameters of the Mat image do I need to modify to shift the image in a positive/negative direction on both x and y axis? I believe setImageROI is no longer supported by Mat datatypes? I have the ROIs for both faces available however I am unsure how to use them. void alignImage(vector<Rect> faceROIstore, vector<Mat> faceIMGstore) { Mat refimg = faceIMGstore[1]; //reference image Mat dispimg = faceIMGstore[52]; // "displaced" version of reference image //Rect refROI = faceROIstore[1]; //Bounding box for face in reference image //Rect dispROI = faceROIstore[52]; //Bounding box for face in displaced image Mat aligned; matchTemplate(dispimg, refimg, aligned, CV_TM_SQDIFF_NORMED); imshow("Aligned image", aligned); } The idea for this approach is based on Image Alignment Tutorial by Richard Szeliski Working on Windows with OpenCV 2.4. Any suggestions are much appreciated.

    Read the article

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